Amazon Lex和BotFramework集成TypeError:无法对已在响应中被吊销的代理执行“获取" [英] Amazon Lex and BotFramework integration TypeError: Cannot perform 'get' on a proxy that has been revoked at Response
问题描述
我正在做一个概念验证,试图将BotFramework与Amazon lex集成在一起,最后将bot集成到Microsoft团队渠道中. AWS-SDK用于调用Amazon Lex机器人.
I was doing a proof of concept trying to integrate BotFramework with Amazon lex and finally integrate the bot to Microsoft teams channel. The AWS-SDK is used to call the Amazon Lex bot.
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))到BotFramework的回调函数时,抛出错误
The response from Lex is received and When i try to return the same response back context.sendActivity(MessageFactory.text(msg)) in the callback function to BotFramework throws an error
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)
Blockquote TypeError: Cannot perform 'get' on a proxy that has been revoked at Response. (E:\playground\BotBuilder-Samples\samples\javascript_nodejs\02.echo-bot\lexbot.js:93:25) at Request. (E:\playground\BotBuilder-Samples\samples\javascript_nodejs\02.echo-bot\node_modules\aws-sdk\lib\request.js:369:18) at Request.callListeners (E:\playground\BotBuilder-Samples\samples\javascript_nodejs\02.echo-bot\node_modules\aws-sdk\lib\sequential_executor.js:106:20) at Request.emit (E:\playground\BotBuilder-Samples\samples\javascript_nodejs\02.echo-bot\node_modules\aws-sdk\lib\sequential_executor.js:78:10)
似乎消息一旦发送给Lex,该机器人使用的代理就不再可用.您能否提供一些有关如何解决此问题的指导.
It seems once the message is sent to Lex, the proxy that the bot uses is no longer available. Can you give some pointers on how to fix this.
这是调用异步函数callLex的调用代码
This is the calling code invoking the async function 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();
});
}
推荐答案
此错误消息始终表示您尚未等待应等待的操作.您可以在构造函数中看到以下行:
This error message always means you have not awaited something that should be awaited. You can see the following line in your constructor:
await context.sendActivity(`Hi, I'm a TutorialBot. Welcome to the team ${ teamMember.givenName } ${ teamMember.surname }`);
这应该向您暗示sendActivity
需要等待,但是您没有在postText
回调中等待它:
This should imply to you that sendActivity
needs to be awaited, and yet you are not awaiting it in your postText
callback:
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
本身的调用,但这没有任何作用,因为
You are awaiting the call to postText
itself, but that doesn't do anything because postText
returns a request and not a promise. And you may have noticed that you can't await anything in the callback because it's not an async function. It seems the Lex package is callback-based and not promise-based, which means it's hard to use it with the Bot Framework since the Bot Builder SDK is promise-based.
您可能要直接调用 PostText API 使用基于承诺的HTTP库(例如Axios):在回调(Microsoft Bot Framework v4 nodejs)中使用await
You may want to call the PostText API directly using a promise-based HTTP library like Axios: use await inside callback (Microsoft Bot Framework v4 nodejs)
或者,您可以尝试创建自己的承诺,然后等待:
Alternatively you can try creating your own promise and then awaiting that: Bot Framework V4 - TypeError: Cannot perform 'get' on a proxy that has been revoked
这篇关于Amazon Lex和BotFramework集成TypeError:无法对已在响应中被吊销的代理执行“获取"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!