我正在从Microsoft Teams开发我的第一个机器人。
我希望用户在机器人中输入命令,该机器人应将请求发送到我的外部Web服务器,并将结果显示为自适应卡。我可以使用外部服务器对机器人进行身份验证。机器人在身份验证后显示用户访问令牌。完善!
如何在我的机器人代码或网络服务器中获取用户的访问令牌,以处理来自机器人的传入请求。这是我的机器人代码的样子。
this.onMessage(async (context, next) => {
//I need a way to get the user's access token here
//or a way to fetch the access token from my web server
//based on some id in the context.
const response = await myWebService.getData(context);
// Run the Dialog with the new message Activity.
await this.dialog.run(context, this.dialogState);
await next();
});
我在这里想念什么?
您可以在登录过程中捕获令牌。假设您已按照以下方式构建了登录过程,则用户登录的结果将从传递promptStep()
到loginStep()
。我可以在stepContext.result
其中分配tokenResponse
并以活动文本形式返回给用户。
您可以在这里执行所需的其他逻辑。
async promptStep(stepContext) {
return await stepContext.beginDialog(OAUTH_AAD_PROMPT);
}
async loginStep(stepContext) {
// Get the token from the previous step. Note that we could also have gotten the
// token directly from the prompt itself. There is an example of this in the next method.
const tokenResponse = stepContext.result;
if (tokenResponse) {
return await stepContext.context.sendActivity(`Your token is: ${ tokenResponse.token }`);
}
await stepContext.context.sendActivity('Login was not successful, please try again.');
return await stepContext.next();
}
希望有帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句