Amazon Lex 和 BotFramework 集成 类型错误:无法对在响应时撤销的代理执行'get'



我正在做一个概念验证,试图将BotFramework与Amazon lex集成,并最终将机器人程序集成到Microsoft团队渠道。AWS-SDK用于调用AmazonLex机器人。

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的回调函数中的sendActivity(MessageFactory.text(msg((抛出错误

blockquote类型错误:无法对已吊销的代理执行"get"在响应中。(E:\playground\BotBuilder Samples\Samples\javascript_nodejs\02.echo-bot\lexbot.js:93:25(应要求。(E:\操场\BotBuilder Samples\Samples\javascript_nodejs\02.echo-bot\node_modules\aws sdk\lib\request.js:369:18(在Request.callListeners上(E:\操场\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();
});
}

此错误消息始终表示您没有等待应该等待的东西。您可以在构造函数中看到以下行:

await context.sendActivity(`Hi, I'm a TutorialBot. Welcome to the team ${ teamMember.givenName } ${ teamMember.surname }`);

这应该意味着sendActivity需要等待,但您没有在postText回调中等待:

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")
})

您正在等待对postText本身的调用,但这没有任何作用,因为postText返回的是请求而不是承诺。您可能已经注意到,您不能在回调中等待任何东西,因为它不是一个异步函数。Lex包似乎是基于回调的,而不是基于承诺的,这意味着很难将其与Bot Framework一起使用,因为Bot Builder SDK是基于承诺的。

您可能想使用基于promise-based的HTTP库(如Axios(直接调用PostText API:使用等待内部回调(Microsoft Bot Framework v4-nodejs(

或者,你可以尝试创建自己的承诺,然后等待:Bot Framework V4-TypeError:无法执行';获取';在已撤销的代理上

最新更新