GoogleCloudPlatform / dialogflow-integrations

Dialogflow integrations with multiple platforms including KIK, Skype, Spark, Twlio, Twitter and Viber
https://cloud.google.com/dialogflow/
Apache License 2.0
256 stars 503 forks source link

How to integrate Dialogflow with Microsoft Teams. #43

Open revs1 opened 4 years ago

revs1 commented 4 years ago

As I have noticed in official document, Teams integration is not part of built in integrations supported by Google. It being an independent integration, can someone help me with trusted third party organization to do the same?

mekpavit commented 4 years ago

@revs1 I did integrate the Dialogflow with Microsoft Teams about 4 months ago using the same approach as Skype., I think it is still working now. Have you tried integrating using the Skype approach mentioned here. The key is that Dialogflow does not directly connect to Microsoft Teams, instead, it connects to Azure Bot Service and you integrate Azure Bot Service with Microsoft Teams channel just like this.

cah-prashanth-soma commented 4 years ago

@mekpavit What will be the messaging endpoint configuration for the server.js. I am unable to access the bot from the Microsoft bot framework channel TEST.

I have tried appending both "/webhook" and "/api/messages" to the cloud function URL https://xxxxxxxx.cloudfunctions.net/TeamsChannel

I am trying to integrate teams. I have followed the documentation for skype open source. But, instead of docker containers i am using cloud functions to deploy the server.js. (org level restrictions on docker).

mekpavit commented 4 years ago

@cah-prashanth-soma Have you tried using the Cloud Function url with adding any suffix? If you have, did you get any incoming request to your Cloud Function? I've never used Cloud Function for hosting the webhook before, but I think it should work.

cah-prashanth-soma commented 4 years ago

thanks. if you meant without suffix? yes I did. And nothing is logged. Nothing is getting hit.

mekpavit commented 4 years ago

@cah-prashanth-soma I've already tested dialogflow-integration with Azure Bot Service. It did work but it requires some changes on server.js since the Cloud Function works with only some project structure. Here is what I did:

  1. Move botlib folder to be in skype.
  2. Update importing statement in skype/server.js to refer to the new location of botlib. For example, you have to change const protoToJson = require('../botlib/proto_to_json.js'); to const protoToJson = require('./botlib/proto_to_json.js'); (remove one dot).
  3. Remove this code block because it will cause an error when the function is running
    const listener = app.listen(port, () => {
    console.log('Your Skype integration server is listening on port '
      + listener.address().port);
    });
  4. change this code block:
    module.exports = {
    convertToSkypeMessage
    };

    to this (Cloud Function can only access to the exported class/function from a .js file declared in main field of package.json):

    module.exports = {
    convertToSkypeMessage,
    app
    };
  5. Deploy to the Cloud Function with nodejs12 runtime, app entry point and service account that you created according to the instruction. For example,
    gcloud functions deploy you-function-name --runtime nodejs12 --service-account=some-service-acount-email@some-project-id.iam.gserviceaccount.com --entry-point app --trigger-http
cah-prashanth-soma commented 4 years ago

@mekpavit, it works. I thank you profusely for your quick and detailed response. Point 4 did the magic for me. (I have already implemented point 1 and 2 and redirected 3 to other port, but I was using convertToSkypeMessage as entry point ).

mekpavit commented 4 years ago

@cah-prashanth-soma You're welcome!!

preethamjv commented 3 years ago

@mekpavit what is the messaging endpoint for cloud run? I have set mine to https://skype-xxxxxxxxxx-uc.a.run.app, But my dialogflow intents still do not show up on Azure bot. can you pls help?

mekpavit commented 3 years ago

@mekpavit what is the messaging endpoint for cloud run? I have set mine to https://skype-xxxxxxxxxx-uc.a.run.app, But my dialogflow intents still do not show up on Azure bot. can you pls help?

@preethamjv Can you show your Cloud Run log? I want to ensure that the Microsoft Bot Service can't access your Cloud Run.

preethamjv commented 3 years ago

@mekpavit I get a series of error messages in my logs image image image

mekpavit commented 3 years ago

@mekpavit I get a series of error messages in my logs image image image

According to the logs, it looks like you misconfigure the microsoft secret. Can you show me your server.js file? Maybe take a screenshot around here: Screen Shot 2564-03-08 at 19 20 23

preethamjv commented 3 years ago

@mekpavit Thanks for your quick follow-up, here is the screenshot image image

mekpavit commented 3 years ago

@preethamjv Okay, you already set the appId and appPassword. Could you check whether the appId and appPassword in server.js are correct? (1. Is it really the appId of your chatbot? 2. Is the appId match the appPassword)

preethamjv commented 3 years ago

@mekpavit I have checked the app id and password, it was correct. I redeployed the code into a new cloud run service, it worked! Adding the missing steps in documentation: On dialogflow webhook fulfillment section, we need to give the MS Azure endpoint URL: image

In the Azure bot configuration section, replace the existing MS Azure endpoint URL with the URL of the Cloud Run service that we have created. image

Hope this helps someone!

@mekpavit thanks for your quick response!

preethamjv commented 3 years ago

@mekpavit just wanted to check, can we add google calendar schedule(book a slot) feature into this integration? Pls give your inputs, thanks in advance!

mekpavit commented 3 years ago

@mekpavit just wanted to check, can we add google calendar schedule(book a slot) feature into this integration? Pls give your inputs, thanks in advance!

I'm not sure if I really understand your feature. if I guess, it might be one of this:

  1. When someone ask your chatbot to setup a meeting, you chatbot schedule a meeting on Google Calendar:

    • IMO, this integration app should only concern about how to integrate between various messaging platform and Google's Dialogflow. If you want to add a feature like this, it might be better to add it in your bot handler app.
  2. When someone schedule a meeting on the bot's Google Calendar, it triggers the Google's Dialogflow intent based on some properties on the meeting.

    • This is possible since the Google Calendar API has a feature that let's an application watch for a change in a calendar. If this is what you want, you can take a look about the Google Calendar API here and develop the feature on this repository.
ExceptionXD commented 3 years ago

@revs1 I did integrate the Dialogflow with Microsoft Teams about 4 months ago using the same approach as Skype., I think it is still working now. Have you tried integrating using the Skype approach mentioned here. The key is that Dialogflow does not directly connect to Microsoft Teams, instead, it connects to Azure Bot Service and you integrate Azure Bot Service with Microsoft Teams channel just like this.

Hi, is there any video tutorial for the same, I am facing issues.

mekpavit commented 3 years ago

@ExceptionXD What's the issues you're facing?

ExceptionXD commented 3 years ago

@mekpavit So I followed all the steps and also got the URL but when i am keeping that as my messaging endpoint and testing web chat I am getting the following error : There was an error sending this message to your bot: HTTP status code Unauthorized

mekpavit commented 3 years ago

@mekpavit So I followed all the steps and also got the URL but when i am keeping that as my messaging endpoint and testing web chat I am getting the following error : There was an error sending this message to your bot: HTTP status code Unauthorized

Where did you get this error message? From Microsoft Teams web chat or from the logging page on GCP?

ExceptionXD commented 3 years ago

@mekpavit on Microsoft Team web chat

mekpavit commented 3 years ago

@mekpavit on Microsoft Team web chat

So, the situation is that, when Microsoft Teams sends a HTTP request to your Cloud Run application, it responses back with 401 status code. One possibility that can be the root clause is that "allow unauthenticated invocations" setting on your Cloud Run application is set to "no".

Could you confirm that, when you deploying using gcloud beta run deploy command, you answer "y" when it is prompted to allow unauthenticated invocations?

ExceptionXD commented 3 years ago

Yes I had given 'y' as my response

ExceptionXD commented 3 years ago

@mekpavit the msg endpoint which i got, I am placing that in my web chat bot -> configurations -> messaging endpoint and then testing. This is what is mentioned right ?

ExceptionXD commented 3 years ago

Hey @mekpavit , @preethamjv has mentioned that " I have checked the app id and password, it was correct. I redeployed the code into a new cloud run service, it worked! Adding the missing steps in documentation: On dialogflow webhook fulfillment section, we need to give the MS Azure endpoint URL:"

so do i need to do this ?

cah-prashanth-soma commented 3 years ago

Well.. 1) Cloud run service end point URL has to be plugged in Bot framework messaging end point (configuration section) 2) if you have a cloud function that has the webhook handling functionality .. you can mention its trigger URL On you dialogflow webhook fulfillment section.

ExceptionXD commented 3 years ago

From where to get MS Azure end point URL ?

mekpavit commented 3 years ago

@ExceptionXD Okay, so, 401 response does not come from Cloud Run authentication. Cloud you show your application logs on Cloud Run? I want to confirm that whether the 401 response was from BotFrameworkAdapter or not.

ExceptionXD commented 3 years ago

Screenshot (50) Screenshot (51)

mekpavit commented 3 years ago

@ExceptionXD Ok. According to the logs, it seems like the service account of your application does not have a permission to use Dialogflow. Could you confirm that you've done "Service Account Setup (GCP)" section here. If you've already done this, please show the screenshot of IAM page on your GCP console, so I can ensure that you give the right permission to the service account.

ExceptionXD commented 3 years ago

Screenshot (52) Screenshot (53) @mekpavit the second image has the permissions which are granted to me

ExceptionXD commented 3 years ago

@mekpavit I am using DialogFlowCX, so is the integration process different ?

mekpavit commented 3 years ago

@ExceptionXD After reading the API document of both Dialogflow ES and CSV, the API specification seems different (at least, the end point is different). Since this integration application only supports Dialogflow ES, I think you cannot use Dialogflow CX here.

BTW, there is one thing you can try. You can try changing the library used in botlib/dialogflow_session_client.js from dialogflow to dialogflow-cx instead. Since the API exposed by these two library is almost identical, I think just changing the package name would be fine.

kyooi2 commented 2 years ago

image

Hi @mekpavit, I follow the msteams integrations using cloud run, but facing the issue above. Can you assist to help?

mekpavit commented 2 years ago

@kyooi2 Hi. According to your logs, the response object doesn't have response.payload.fields.skype field. So, when convertToSkypeMessage tried to get that field's value to convert to a valid MSTeam response, it encountered Cannot read property 'structValue' of undefined error.

https://github.com/GoogleCloudPlatform/dialogflow-integrations/blob/master/skype/server.js#L148-L152

I would suggest you to find out why Dialogflow responded you back with that response object. Do you use a webhook or just Dialogflow to process a message?

https://github.com/GoogleCloudPlatform/dialogflow-integrations/blob/master/skype/server.js#L150

kyooi2 commented 2 years ago

@mekpavit Hi. I think i found out the things that i have missed out. I forgot to add in the response for skype, so when it route back to default response, it will take the default payload. This is what I encounter for the error. Thanks alot for helping.

image

olivomarco commented 2 years ago

Hi. Using knowledge from this issue I have recently created this repo where I have put all code and instructions needed to integrate bots in DialogFlow with Microsoft Teams. HTH

AdityaSinghania93 commented 1 year ago

Hello @mekpavit Hope you doing great. I am trying to integrate Google Dialog Flow with MS Teams but could not complete it. I have created Google dialog Flow intents ( request & response ). Created Azure Service Bot also & also followed the below link in order to compete the integration but it does not work. I don't receive any response on MS teams platform the response that i have written in my Google Dialog flow.

https://github.com/olivomarco/dialogflow-teams-integration If you can help me set up the integration of Google Dialog Flow with MS teams. Almost 90 % work is completed not sure what is causing the error. If you have any step by step to follow, if you can share it it will be big help also

ghchinoy commented 1 year ago

Please see a more recent integration in this repo https://github.com/GoogleCloudPlatform/dialogflow-integrations/tree/master/cx/azure-bot-service

shahilnissam commented 11 months ago

Has anyone got this gateway timeout issue for dialogflow cx integration with Azure bot service? https://github.com/GoogleCloudPlatform/dialogflow-integrations/tree/master/cx/azure-bot-service All env keys are correct as per the instructions.. but I still get this error.

September 23, 2023 at 9:53 PM GMT+5:30 There was an error sending this message to your bot: HTTP status code GatewayTimeout ca12f4b87b1ba4ae040098b5904c62e6