Amazon Lex and BotFramework integration TypeError: Cannot perform 'get' on a proxy that has been revoked at Response
Amazon Lex and BotFramework integration TypeError: Cannot perform 'get' on a proxy that has been revoked at Response
我正在做一个概念验证,试图将 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 的响应,当我尝试 return 返回相同的响应时 context.sendActivity(MessageFactory.text(msg)) 在 BotFramework 的回调函数中抛出错误
Blockquote TypeError: Cannot perform 'get' on a proxy that has been revoked
at Response. (E:\playground\BotBuilder-Samples\samples\javascript_nodejs.echo-bot\lexbot.js:93:25)
at Request. (E:\playground\BotBuilder-Samples\samples\javascript_nodejs.echo-bot\node_modules\aws-sdk\lib\request.js:369:18)
at Request.callListeners (E:\playground\BotBuilder-Samples\samples\javascript_nodejs.echo-bot\node_modules\aws-sdk\lib\sequential_executor.js:106:20)
at Request.emit (E:\playground\BotBuilder-Samples\samples\javascript_nodejs.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
returns 是请求而不是承诺。你可能已经注意到你不能在回调中等待任何东西,因为它不是异步函数。 Lex 包似乎是 callback-based 而不是 promise-based,这意味着它很难与 Bot Framework 一起使用,因为 Bot Builder SDK 是 promise-based.
您可能想致电 PostText API directly using a promise-based HTTP library like Axios: use await inside callback (Microsoft Bot Framework v4 nodejs)
或者您可以尝试 creating your own promise and then awaiting that:
我正在做一个概念验证,试图将 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 的响应,当我尝试 return 返回相同的响应时 context.sendActivity(MessageFactory.text(msg)) 在 BotFramework 的回调函数中抛出错误
Blockquote TypeError: Cannot perform 'get' on a proxy that has been revoked at Response. (E:\playground\BotBuilder-Samples\samples\javascript_nodejs.echo-bot\lexbot.js:93:25) at Request. (E:\playground\BotBuilder-Samples\samples\javascript_nodejs.echo-bot\node_modules\aws-sdk\lib\request.js:369:18) at Request.callListeners (E:\playground\BotBuilder-Samples\samples\javascript_nodejs.echo-bot\node_modules\aws-sdk\lib\sequential_executor.js:106:20) at Request.emit (E:\playground\BotBuilder-Samples\samples\javascript_nodejs.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
returns 是请求而不是承诺。你可能已经注意到你不能在回调中等待任何东西,因为它不是异步函数。 Lex 包似乎是 callback-based 而不是 promise-based,这意味着它很难与 Bot Framework 一起使用,因为 Bot Builder SDK 是 promise-based.
您可能想致电 PostText API directly using a promise-based HTTP library like Axios: use await inside callback (Microsoft Bot Framework v4 nodejs)
或者您可以尝试 creating your own promise and then awaiting that: