Search code examples
c#botframeworkchatbotmicrosoft-teamsngrok

How to get access token and use it


I am working on creating bot for Microsoft teams in C#. I have a sample code (basic echo bot) that works fine in emulator. I created an app in teams app studio and entered my API end points in Bot section. I download the package and upload it as custom package in teams.

Now, when I add this app and try communicate with Bot, I get unauthorize error in API (using ngrok). I guess what’s going on here is that I don’t have the access token i.e. when someone install it, teams should give you access token, right?

What I don’t know is how teams will give me the access token and where in the process that access token will be used?

So basically, when someone clicks on “Add” button in teams app store, how the access token are passed.

@update

Note:-I have done the app registration as well.

So i did bot channel registration in Azure and added my ngrok end points. I copied the "MicrosoftAppId" and "MicrosoftAppPassword" in appsettings file. It is working fine in emulator as well as "test on web chat" in Azure bot management portal. I also connected it to Teams channel from portal itself. when i navigate to teams from the channel link, my bot is working as expected. enter image description here

After that i opened app studio and entered all the details. In Bot section, i selected existing bot id and entered my MicrosoftAppId from azure and it worked.

what I still don't understand is, when someone install the app, teams should be sending some information to my end point, right?


Solution

  • Without access to your code it is hard/impossible to determine the cause of your issue.

    I suggest instead you take a fresh start by using one of the Teams bot examples that are shared :

    if you do require authentication in your bot:

    pleanty other teams examples as well in that repo:

    • 50.teams-messaging-extensions-search
    • 51.teams-messaging-extensions-action
    • 53.teams-messaging-extensions-action-preview
    • 54.teams-task-module
    • 55.teams-link-unfurling
    • 56.teams-file-upload
    • 57.teams-conversation-bot
    • 58.teams-start-new-thread-in-channel