MicrosoftDocs / msteams-docs

Source for the Microsoft Teams developer platform documentation.
https://aka.ms/teamsdev
Creative Commons Attribution 4.0 International
281 stars 502 forks source link

MSTeams - Bot returning NotImplemented #403

Closed callenskoen closed 5 years ago

callenskoen commented 5 years ago

Hello,

I’m writing a bot in Azure that will be hosted in MS Teams. The bot has two AADv2 connections, one for the Microsoft Graph and one for Sharepoint Online.

When testing the signing to both oauth connection in the bot emulator they are working fine.

However, when deploying the bot in MS teams, authentication to the first oauth connection (Graph) works, the second oauth connection (Sharepoint online) doesn’t work.

I’ve used fiddler to see what is ongoing, and saw the following:

POST https://emea.ng.msg.teams.microsoft.com/v1/agents/28:8e7e6063-94a6-4989-ac8f-bf4892c57981/invoke HTT...

{"errorCode":1008,"message":"Bot returned unsuccessful status code NotImplemented"}

Anyone any idea what might be wrong? Or is this scenario not supported ?

Thx Koen

arkiaconsulting commented 5 years ago

Same here, with a Generic OAuth 2 Bot Service connection

Wajeed-msft commented 5 years ago

@callenskoen - Could you please share code snippet which show how signin/verifyState is handled? Are you using basic auth sample code?

callenskoen commented 5 years ago

Hi @Wajeed-msft ,

I'm using the bot framework v4 - enterprise template https://github.com/Microsoft/AI/tree/master/templates/Enterprise-Template/src/typescript/enterprise-bot

For the authentication, I use the provided dialog https://github.com/Microsoft/AI/blob/master/templates/Enterprise-Template/src/typescript/enterprise-bot/src/dialogs/authentication/authenticationDialog.ts.

Regards, Koen

arkiaconsulting commented 5 years ago

@Wajeed-msft I'm in the exact same version and flow as @callenskoen

Wajeed-msft commented 5 years ago

@arkiaconsulting , @callenskoen - Could you please share complete request/response body? Also, once sign in completed for SharePoint, Is it closing the pop-up? If so, are you getting any invoke action back in your code?

arkiaconsulting commented 5 years ago

Request url: https://emea.ng.msg.teams.microsoft.com/v1/agents/28:redacted-81e8-45cc-b691-7e4fecc8f0e0/invoke Request payload: {"value":{"state":"859791"},"conversation":{"id":"19:redacted-28ad-4b18-b096-d58b285e1aee_redacted-81e8-45cc-b691-7e4fecc8f0e0@unq.gbl.spaces"},"name":"signin/verifyState","imdisplayname":"redacted"} Response: {"errorCode":1008,"message":"<BotError>Bot returned unsuccessful status code NotImplemented"}

Wajeed-msft commented 5 years ago

Based on the request details, seems like signin/verifyState is not Implemented in the code. To confirm this, could you please try this basic auth sample code which handles signin/VerifySate invoke?

arkiaconsulting commented 5 years ago

@Wajeed-msft The sample you mentioned is in v3, but I'm using the botbuilder v4. Anyway, I tryed to have some more info about the requests incoming into my bot. Here is the last incoming request before the error:

{
  "name":"signin/verifyState",
  "type":"invoke",
  "timestamp":"2019-02-02T09:04:04.516Z",
  "localTimestamp":"2019-02-02T09:04:04.516Z",
  "id":"f:REDACTED",
  "channelId":"msteams",
  "serviceUrl":"https://smba.trafficmanager.net/emea/",
  "from":{
    "id":"29:REDACTED",
    "name":"REDACTED",
    "aadObjectId":"REDACTED-28ad-4b18-b096-REDACTED"
  },
  "conversation":{
    "conversationType":"personal",
    "id":"a:REDACTED"
  },
  "recipient":{
    "id":"28:REDACTED-81e8-45cc-b691-7e4fecc8f0e0",
    "name":"REDACTED"
  },
  "entities":[{
    "locale":"fr-FR",
    "country":"FR",
    "platform":"Web",
    "type":"clientInfo"}],
  "channelData":{
    "tenant":{
      "id":"REDACTED-3605-469a-bf42-REDACTED"
    },
    "source":{
      "name":"message"
    }
  },
"value":{"state":"035009"}}

and finally the error i'm getting:

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'toString' of undefined at BotFrameworkAdapter. (/app/node_modules/botbuilder/lib/botFrameworkAdapter.js:491:95) at Generator.next () at fulfilled (/app/node_modules/botbuilder/lib/botFrameworkAdapter.js:11:58) at processTicksAndRejections (internal/process/next_tick.js:81:5)

As a side note, all is working well when using the emulator. From what I understand, the request "signin/verifyState" should be handled by the Teams middleware, and should not even come inside my bot. So I think that you're right when you say that this request is not implemented in the code on your side.

arkiaconsulting commented 5 years ago

@callenskoen I found a workaround. I just had to intercept the activity whose name is signin/verifyState in my main bot handler, as following:

if (context.activity.name === 'signin/verifyState') {
   let oAuthDialog: Dialog<{}> = this.dialogs.find(AUTH_DIALOG);
   const dc = await this.dialogs.createContext(context);
   await oAuthDialog.continueDialog(dc);
}

Please note that this workaround should not be used in production as it no longer effectively ask the user to enter the verification code

Wajeed-msft commented 5 years ago

@callenskoen , @arkiaconsulting - signin/verifyState event needs to be handled in the bot code. Here is document on handle the login complete activity.

Also, you can raise this issue as an issue on Enterprise-Template repo so that it's fixed in template itself.