【问题标题】:Amazon Lex and BotFramework integration TypeError: Cannot perform 'get' on a proxy that has been revoked at Response [duplicate]Amazon Lex 和 BotFramework 集成 TypeError:无法对已在响应中撤销的代理执行“获取”[重复]
【发布时间】: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();
        });
    }

【问题讨论】:

标签: javascript node.js botframework microsoft-teams amazon-lex


【解决方案1】:

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

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 包似乎是基于回调的,而不是基于 Promise 的,这意味着它很难与 Bot Framework 一起使用,因为 Bot Builder SDK 是基于 Promise 的。

您可能希望使用基于 Promise 的 HTTP 库(如 Axios)直接调用 PostText APIuse await inside callback (Microsoft Bot Framework v4 nodejs)

您也可以尝试creating your own promise,然后等待:Bot Framework V4 - TypeError: Cannot perform 'get' on a proxy that has been revoked

【讨论】:

    猜你喜欢
    • 2020-09-27
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 2021-02-14
    • 2021-02-01
    • 2021-10-23
    • 2021-10-25
    • 2022-08-11
    相关资源
    最近更新 更多