简体   繁体   English

如何获取访问令牌并使用它

[英]How to get access token and use it

I am working on creating bot for Microsoft teams in C#.我正在为 C# 中的 Microsoft 团队创建机器人。 I have a sample code ( basic echo bot ) that works fine in emulator.我有一个在模拟器中运行良好的示例代码( 基本 echo bot )。 I created an app in teams app studio and entered my API end points in Bot section.我在团队应用工作室中创建了一个应用,并在 Bot 部分输入了我的 API 端点。 I download the package and upload it as custom package in teams.我下载 package 并将其作为自定义 package 上传到团队中。

Now, when I add this app and try communicate with Bot, I get unauthorize error in API (using ngrok).现在,当我添加此应用程序并尝试与 Bot 通信时,我在 API(使用 ngrok)中收到未经授权的错误。 I guess what's going on here is that I don't have the access token ie 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.所以我在 Azure 中进行了机器人频道注册,并添加了我的 ngrok 端点。 I copied the "MicrosoftAppId" and "MicrosoftAppPassword" in appsettings file.我在 appsettings 文件中复制了“MicrosoftAppId”和“MicrosoftAppPassword”。 It is working fine in emulator as well as "test on web chat" in Azure bot management portal.它在模拟器中以及在 Azure 机器人管理门户中的“web 聊天测试”中运行良好。 I also connected it to Teams channel from portal itself.我还将它从门户本身连接到 Teams 频道。 when i navigate to teams from the channel link, my bot is working as expected.当我从频道链接导航到团队时,我的机器人按预期工作。 在此处输入图像描述

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.在 Bot 部分,我选择了现有的 bot id 并从 azure 输入了我的 MicrosoftAppId 并且它有效。

what I still don't understand is, when someone install the app, teams should be sending some information to my end point, right?我仍然不明白的是,当有人安装该应用程序时,团队应该向我的端点发送一些信息,对吗?

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:相反,我建议您使用共享的 Teams 机器人示例之一重新开始:

if you do require authentication in your bot:如果您确实需要在您的机器人中进行身份验证:

pleanty other teams examples as well in that repo:在那个 repo 中也有很多其他团队的例子:

  • 50.teams-messaging-extensions-search 50.teams-messaging-extensions-search
  • 51.teams-messaging-extensions-action 51.teams-messaging-extensions-action
  • 53.teams-messaging-extensions-action-preview 53.teams-messaging-extensions-action-preview
  • 54.teams-task-module 54.teams-任务-模块
  • 55.teams-link-unfurling 55.teams-链接-展开
  • 56.teams-file-upload 56.teams-文件上传
  • 57.teams-conversation-bot 57.teams-对话机器人
  • 58.teams-start-new-thread-in-channel 58.teams-start-new-thread-in-channel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM