私はMicrosoftTeamsから最初のボットを開発しています。
ユーザーにボットにコマンドを入力してもらいたいのですが、ボットは外部の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]
コメントを追加