简体   繁体   English

Bot Framework V4 - 类型错误:无法在已撤销的代理上执行“获取”

[英]Bot Framework V4 - TypeError: Cannot perform 'get' on a proxy that has been revoked

I am trying to make a rest query against a database that stores knowledge articles for users and returns an array of results based on what the user has searched for.我正在尝试对一个数据库进行 rest 查询,该数据库为用户存储知识文章并根据用户搜索的内容返回一组结果。 Whenever I try to search I get:每当我尝试搜索时,我都会得到:

"TypeError: Cannot perform 'get' on a proxy that has been revoked" “类型错误:无法在已撤销的代理上执行‘获取’”

I have tried adding it to async as shown but I still keep getting the same error.如图所示,我已尝试将其添加到异步中,但我仍然不断收到相同的错误。 Any idea what I am doing wrong?知道我做错了什么吗?

const Response = async (turnContext) => {
    if (turnContext.activity.value.choice === 'feedbackProvider') {
        try {
            const feedbackBody = turnContext.activity.value.feedbackBody;
            const feedbackEmail = turnContext.activity.value.feedbackEmail;
            storage.write(feedbackBody, feedbackEmail);
            await turnContext.sendActivity(`Feedback Sent`);
        } catch (err) {
            console.log('fetch failed', err);
        }
    } else if (turnContext.activity.value.choice === 'issueRaiser') {
        try {
            const bugTitle = turnContext.activity.value.issueTitle;
            const bugDesc = turnContext.activity.value.issueDescription;
            const bugEmail = turnContext.activity.value.issueEmail;
            const request = require('request');
            request({
                method: 'Post',
                uri: `<uri>issues?title=${ bugTitle }&description=${ bugDesc } ${ bugEmail }&labels=bug`,
                json: true,
                headers: {
                    'Private-Token': '<token>'
                }
            });
            turnContext.sendActivity(`Issue Raised`);
        } catch (err) {
            console.log('fetch failed', err);
        }
    } else if (turnContext.activity.value.choice === 'knowledgeBaseSearch') {
        try {
            const knowledgeBaseTopic = turnContext.activity.value.knowledgeBaseTopic;
            request({
                url: process.env.SN_KB_URL + knowledgeBaseTopic,
                json: true,
                auth: {
                    'username': process.env.Ticket_User,
                    'password': process.env.Ticket_Key
                }
            }, async (error, response, body) => {
                try {
                    var stuff = [];
                    for (var i = 0, len = body.result.length; i < len; i++) {
                        stuff.push(
                            CardFactory.heroCard(body.result[i].short_description, ['imageUrl1'], [`${ process.env.SN_KB_Resp_URl }${ body.result[i].number }`])

                        );
                    }
                    let messageWithCarouselOfCards = MessageFactory.carousel(stuff);
                    await turnContext.sendActivity(messageWithCarouselOfCards);
                } catch (err) {
                    console.log(error);
                }
            });
        } catch (err) {
            console.log('fetch failed', err);
        }
    }
};

Full Error Message:完整错误信息:

TypeError: Cannot perform 'get' on a proxy that has been revoked
cardMiddleware.js:35
    at Request.request [as _callback] (c:\Bots\sdk4-2\skills\cardMiddleware.js:35:45)
    at Request.self.callback (c:\Bots\sdk4-2\node_modules\request\request.js:186:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (c:\Bots\sdk4-2\node_modules\request\request.js:1163:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (c:\Bots\sdk4-2\node_modules\request\request.js:1085:12)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)

From my post on the forum I was informed that I was using a request module that did not support Promises, which I believe was causing my error.从我在论坛上的帖子中得知,我正在使用不支持 Promises 的请求模块,我认为这是导致我出错的原因。 I've now began to use Axios for my request which is shown below;我现在开始使用 Axios 来满足我的请求,如下所示;

try {
    return await axios.get(process.env.SN_KB_URL + knowledgeBaseTopic, {
        headers: {
          auth: {
          username: process.env.Ticket_User,
          password: process.env.Ticket_Key
        }
      }
    })
  }

However now when I run the request I get a 401 'Unauthorised' error and I'm not sure what is wrong with my request.但是,现在当我运行请求时,出现 401“未经授权”错误,我不确定我的请求有什么问题。

This issue happened because I was using a request module that did not support promises.发生此问题是因为我使用的请求模块不支持承诺。 Changing my request module for one that did support promises (which I found out about by using this article ) resolved the issue.将我的请求模块更改为支持承诺的模块(我通过使用这篇文章发现了这一点)解决了该问题。

The answer for me was to double check I didn't miss any await usage that might be necessary.我的答案是仔细检查我没有错过任何可能需要的await用法。 Turns out I called this.dialog.run(context, this.dialogState);原来我叫this.dialog.run(context, this.dialogState); without the await and that threw the same error.没有await并且抛出了同样的错误。 I found the answer on this Github issue我在这个 Github 问题上找到了答案

I'm going to put this here only because it's the first result that pops up when searching, although it doesn't directly relate to this issue.我将它放在这里只是因为它是搜索时弹出的第一个结果,尽管它与此问题没有直接关系。

There's a very easy way to use setTimeout() and avoid this error:有一种非常简单的方法可以使用setTimeout()并避免此错误:

await new Promise(resolve => setTimeout(() => resolve(
    turnContext.sendActivity('I was sent 5 seconds later')
), 5000));

I spent a lot of time struggling with this issue.我花了很多时间来解决这个问题。 As other commenters have noted, the issue lies in the fact that the Lex Runtime is not promise-based, so you cannot await requests, which causes the proxy to be revoked.正如其他评论者所指出的,问题在于 Lex 运行时不是基于承诺的,因此您不能等待请求,这会导致代理被撤销。

Here is my solution:这是我的解决方案:

async callLex(context) {
    const params = {
        botAlias: 'prod',
        botName: 'botName',
        userId: context.activity.from.id,
        contentType: 'text/plain; charset=utf-8',
        accept: 'text/plain; charset=utf-8',
        inputStream: context.activity.text.trim()
    }
    let request = lexruntime.postContent(params)
    await request.promise().then(
        async response => {
            console.log(response)
            console.log('Success!')
            await context.sendActivity(response.message)          
        },
        err => {
            console.log(err)
            console.log('Error!')
        })
}

Rather than directly invoke the request like "lexruntime.postContent(params, callback func)", I exclude the callback function and utilize the "promise" property of AWS.Request to send the request as a promise which enables me to use "await" and keeps the proxy open.我没有直接调用像“lexruntime.postContent(params, callback func)”这样的请求,而是排除回调函数并利用AWS.Request的“promise”属性将请求作为promise发送,这使我能够使用“await”并保持代理打开。 See documentation here . 请参阅此处的文档

In my scenario, we were trying to upload files from a Task Module (modal popup of teams) to the bot and in response the bot would give a first confirmation that the attachments are uploading.在我的场景中,我们试图将文件从任务模块(团队的模态弹出窗口)上传到机器人,作为响应,机器人将首先确认附件正在上传。 This activity would close the task module (as the bot must reply within 10 seconds or teams would resend the request).此活动将关闭任务模块(因为机器人必须在 10 秒内回复,否则团队将重新发送请求)。 Now when the attachments were uploaded, we wanted to update the previously sent adaptive card with the list of the uploaded attachments.现在,当上传附件时,我们想用上传的附件列表更新之前发送的自适应卡片。 We achieved this using the proactive messaging feature of bot framework.我们使用机器人框架的主动消息传递功能实现了这一点。

const conversationReference = TurnContext.getConversationReference(activity);
Promise.all(listOfPromises).then(() => {
    await botAdapter.continueConversation(conversationReference, async turnContext => {
        await turnContext.sendActivity('All attachments uploaded!');
    });
}

Docs: https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-proactive-message?view=azure-bot-service-4.0&tabs=javascript文档: https : //docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-proactive-message? view = azure-bot-service-4.0 & tabs =javascript

Check for lines that needs await inside any aync function. I hope that azure will point usto which file or line specifically but I have not figured it out until I looked at all my functions.检查任何 aync function 中需要await的行。我希望 azure 将具体指向哪个文件或行,但直到我查看了所有函数后我才弄明白。

Okay, so this is indeed a very cryptic error message as the github thread here suggested.好的,所以这确实是一个非常神秘的错误消息,正如此处建议的 github 线程。

But I found that I was not await ing in this block:但是我发现我并没有在这个块中await

 this.onMessage(async (context, next) => {. const didBotWelcomedUser = await this.welcomedUserProperty.get( context, "false" ); if (didBotWelcomedUser === false) { // first time user is in chat await this.sendWelcomeMessage(context); `<-------- await here was missing` } else { await this.sendSuggestedAction(context); `<-------- await here was missing` } await next(); }); this.onMembersAdded(async (context, next) => { await this.sendWelcomeMessage(context); await next(); }); }

I thought await.next() is enough.我认为await.next()就足够了。 We all gotta learn this somehow... Hope you resolve yours.我们都必须以某种方式学习这个......希望你能解决你的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获(承诺)类型错误:无法在已撤销的代理上执行“设置” - Uncaught (in promise) TypeError: Cannot perform 'set' on a proxy that has been revoked 获取 TypeError:无法在已撤销 Redux 工具包的代理上执行“get” - Getting TypeError: Cannot perform 'get' on a proxy that has been revoked Redux toolkit 类型错误:无法读取未定义的属性“v4” - TypeError: Cannot read property 'v4' of undefined Bot Framework(v4)-如何从自定义提示验证中获取状态 - Bot framework (v4) - How to get state from custom prompt validation bot框架网络聊天v4中的字体自定义 - Font Customization in bot framework web chat v4 在回调中使用await(Microsoft Bot Framework v4 nodejs) - use await inside callback (Microsoft Bot Framework v4 nodejs) 如何在Bot Framework v4中实施触发动作? - How to implement trigger action in bot framework v4? 机器人框架 V4 订阅以接收 Javascript 上的对话 ID - Bot framework V4 Subscribe to receive conversation Id on Javascript Microsoft bot 框架 v4 作为最小化 window 嵌入到带有 javascript 的网站中 - Microsoft bot framework v4 embed as minimizable window in website with javascript 更新已在 javascript 的 Bot Framework v4 中发布 Adaptive Card - Update already posted Adaptive Card in Bot Framework v4 in javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM