【发布时间】:2020-12-17 01:33:19
【问题描述】:
我正在做一个概念验证,试图将 BotFramework 与 Amazon lex 集成,并最终将机器人集成到 Microsoft 团队频道。 AWS-SDK 用于调用 Amazon Lex 机器人。
async callLex(context) {
let msg
var lexruntime = new AWS.LexRuntime();
const params = {
botAlias: 'tutorialbot',
botName: 'TutorialBot',
inputText: context.activity.text.trim(), /* required */
userId: context.activity.from.id,
//inputStream: context.activity.text.trim()
}
await lexruntime.postText(params, function(err,data) {
console.log("Inside the postText Method")
if (err) console.log(err, err.stack); // an error occurred
else {
console.log(data)
msg = data.message
console.log("This is the message from Amazon Lex" + msg)
context.sendActivity(MessageFactory.text(msg));
//turnContext.sendActivity(msg);
}
console.log("Completed the postText Method")
})
return msg;
}
收到来自 Lex 的响应,当我尝试在 BotFramework 的回调函数中返回相同的响应时,context.sendActivity(MessageFactory.text(msg)) 会抛出错误
Blockquote TypeError:无法在已撤销的代理上执行“获取” 在响应。 (E:\playground\BotBuilder-Samples\samples\javascript_nodejs\02.echo-bot\lexbot.js:93:25) 在请求。 (E:\playground\BotBuilder-Samples\samples\javascript_nodejs\02.echo-bot\node_modules\aws-sdk\lib\request.js:369:18) 在 Request.callListeners (E:\playground\BotBuilder-Samples\samples\javascript_nodejs\02.echo-bot\node_modules\aws-sdk\lib\sequential_executor.js:106:20) 在 Request.emit (E:\playground\BotBuilder-Samples\samples\javascript_nodejs\02.echo-bot\node_modules\aws-sdk\lib\sequential_executor.js:78:10)
似乎一旦将消息发送到 Lex,机器人使用的代理就不再可用。你能指点一下如何解决这个问题吗?
这是调用异步函数 callLex 的调用代码
class TeamsConversationBot extends TeamsActivityHandler {
constructor() {
super();
this.onMessage(async (context, next) => {
TurnContext.removeRecipientMention(context.activity);
var replyText = `Echo: ${ context.activity.text }`;
await this.callLex(context)
console.log("After calling the callLex Method")
await next();
});
this.onMembersAddedActivity(async (context, next) => {
context.activity.membersAdded.forEach(async (teamMember) => {
if (teamMember.id !== context.activity.recipient.id) {
await context.sendActivity(`Hi, I'm a TutorialBot. Welcome to the team ${ teamMember.givenName } ${ teamMember.surname }`);
}
});
await next();
});
}
【问题讨论】:
-
嘿凯尔非常感谢您的帮助,问题stackoverflow.com/questions/53054736/bot-framework-async-issues 中的解决方案是什么。这听起来与我面临的问题相似。
-
我的回答可以接受吗?
-
感谢凯尔这是完美的
标签: javascript node.js botframework microsoft-teams amazon-lex