Javascript Amazon Lex和BotFramework集成类型错误:无法执行';获取';在响应时已撤销的代理上
我正在做一个概念验证,试图将BotFramework与Amazon lex集成,并最终将bot与Microsoft Team channel集成。AWS-SDK用于调用Amazon Lex botJavascript Amazon Lex和BotFramework集成类型错误:无法执行';获取';在响应时已撤销的代理上,javascript,node.js,botframework,microsoft-teams,amazon-lex,Javascript,Node.js,Botframework,Microsoft Teams,Amazon Lex,我正在做一个概念验证,试图将BotFramework与Amazon lex集成,并最终将bot与Microsoft Team channel集成。AWS-SDK用于调用Amazon Lex bot async callLex(context) { let msg var lexruntime = new AWS.LexRuntime(); const params = { botAlias: 'tutorialbot', botNam
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的响应,当我尝试将相同的响应返回到context时,回调函数中的sendActivity(MessageFactory.text(msg))将抛出一个错误
Blockquote TypeError:无法对已撤销的代理执行“获取”
在回答时。(E:\playway\BotBuilder Samples\Samples\javascript\u nodejs\02.echo bot\lexbot.js:93:25)
应要求。(E:\playway\BotBuilder Samples\Samples\javascript\u nodejs\02.echo bot\node\u modules\aws sdk\lib\request.js:369:18)
at Request.callListeners(E:\playway\BotBuilder Samples\Samples\javascript\u nodejs\02.echo bot\node\u modules\aws sdk\lib\sequential\u executor.js:106:20)
at Request.emit(E:\playway\BotBuilder Samples\Samples\javascript\u nodejs\02.echo bot\node\u modules\aws sdk\lib\sequential\u executor.js:78:10)
似乎一旦消息发送到Lex,bot使用的代理就不再可用。你能给我一些关于如何解决这个问题的建议吗
这是调用异步函数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();
});
}
此错误消息始终表示您尚未等待应等待的内容。您可以在构造函数中看到以下行: 这意味着您需要等待
sendActivity
,但您没有在postText
回调中等待它:
您正在等待对postText
本身的调用,但这没有任何作用,因为返回的是请求而不是承诺。您可能已经注意到,您不能等待回调中的任何内容,因为它不是异步函数。Lex包似乎是基于回调的,而不是基于承诺的,这意味着它很难与Bot框架一起使用,因为Bot Builder SDK是基于承诺的
您可能希望使用基于承诺的HTTP库(如Axios)直接调用:
或者,您可以尝试然后等待:嘿,凯尔,非常感谢您的帮助,问题的解决方案是什么。这听起来和我面临的问题很相似。我的回答可以接受吗?谢谢,凯尔,这太完美了
await context.sendActivity(`Hi, I'm a TutorialBot. Welcome to the team ${ teamMember.givenName } ${ teamMember.surname }`);
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")
})