Microsoft Teams Integration : Error switching to new App ID

We are using the latest version of botpress (12.1.6) and we have integrated the bot with microsoft teams.
We had successfully working bot with one Microsoft tenant 1 and we were getting responses from Teams channels. When we moved to new microsoft teams tenant, we followed all the same previous steps “https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/bots/bots-create” as of old tenant to create a new application registration.

At the botpress we changed the app id and client secret key in channel-teams.json. After this restarted the bot. Emulator is working fine.

With the new teams tenant, bot is not working from Teams channel and we are getting below error:

Wed Oct 09 2019 19:08:08 GMT+0530 (India Standard Time) Launcher (error) Unhandled Rejection [Error, Error: Unauthorized. Invalid AppId passed on token: 92fbc141-499f-4936-a50b-6910d1a6dbf9]
STACK TRACE
Error: Error: Unauthorized. Invalid AppId passed on token: 92fbc141-499f-4936-a50b-6910d1a6dbf9
at BotFrameworkAdapter.processActivity (/opt/botpress/modules/.cache/module__3ea9b3ff0467ce749a3aeee9b5d8799458009be6f03789a913d8e58f9c8bb631/node_production_modules/botbuilder/lib/botFrameworkAdapter.js:511:19)
Wed Oct 09 2019 19:08:09 GMT+0530 (India Standard Time) Launcher (error) Unhandled Rejection [Error, Error: Unauthorized. Invalid AppId passed on token: 92fbc141-499f-4936-a50b-6910d1a6dbf9]

Kindly help to resolve the issue.

Can somebody help me solve this problem or someone have any Idea how this can be solved?

@allardy - would you have some insights since this is a teams integration issue? Looks like an incorrect api access token is getting linked with the microsoft azure app id.

I would like to add more now, I tried more with the channel-teams.json.

When I passed the tenant Id, then microsoft credentials are working properly. But after this, when you post to the teams channel you get Authorization error as below:

STACK TRACE
Error: Authorization has been denied for this request.
at new RestError (/opt/botpress/modules/.cache/module__3ea9b3ff0467ce749a3aeee9b5d8799458009be6f03789a913d8e58f9c8bb631/node_production_modules/@azure/ms-rest-js/dist/msRest.node.js:1397:28)
at /opt/botpress/modules/.cache/module__3ea9b3ff0467ce749a3aeee9b5d8799458009be6f03789a913d8e58f9c8bb631/node_production_modules/@azure/ms-rest-js/dist/msRest.node.js:1849:37
at tryCatcher (/opt/botpress/modules/.cache/module__f21b22cdb91304a860852bb6a0972f4eed394f43a241bc9a33d90818ff44b497/node_production_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/opt/botpress/modules/.cache/module__f21b22cdb91304a860852bb6a0972f4eed394f43a241bc9a33d90818ff44b497/node_production_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/opt/botpress/modules/.cache/module__f21b22cdb91304a860852bb6a0972f4eed394f43a241bc9a33d90818ff44b497/node_production_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/opt/botpress/modules/.cache/module__f21b22cdb91304a860852bb6a0972f4eed394f43a241bc9a33d90818ff44b497/node_production_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/opt/botpress/modules/.cache/module__f21b22cdb91304a860852bb6a0972f4eed394f43a241bc9a33d90818ff44b497/node_production_modules/bluebird/js/release/promise.js:729:18)
at _drainQueueStep (/opt/botpress/modules/.cache/module__f21b22cdb91304a860852bb6a0972f4eed394f43a241bc9a33d90818ff44b497/node_production_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/opt/botpress/modules/.cache/module__f21b22cdb91304a860852bb6a0972f4eed394f43a241bc9a33d90818ff44b497/node_production_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/opt/botpress/modules/.cache/module__f21b22cdb91304a860852bb6a0972f4eed394f43a241bc9a33d90818ff44b497/node_production_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (/opt/botpress/modules/.cache/module__f21b22cdb91304a860852bb6a0972f4eed394f43a241bc9a33d90818ff44b497/node_production_modules/bluebird/js/release/async.js:15:14)
at runCallback (timers.js:696:18)
at tryOnImmediate (timers.js:667:5)
at processImmediate (timers.js:649:5)
at process.topLevelDomainCallback (domain.js:121:23)

If you don’t pass the tenant id, microsoft credentials are not getting validated.

Any help or directions to look into will be helpful

So at last the issue is resolved. So here are the findings:

  1. While registering the app on Microsoft Azure portal there are 2 options:

    a. If you select only specific organization then
    While adding details in channel-teams.json you need to specify the tenantId. After this only credentials are validated when botpress is started. But after this, if you try to post from the teams channel, Authorization error comes as stated in above issue.
    So, looks like tenantId is not being used and it leads to Authorization error. There could be another reason to this. I wanted to know what is missing here.

    b. If you keep it open for any Azure directory then
    While adding details in channel-teams.json you dont need to specify the tenantId and you leave it as blank e.g. tenantId: “”.
    This resolved the issue for me.

Thanks,
Sarita