Botbuilder-js: Bot Framework V4 - TypeError: Cannot perform 'get' on a proxy that has been revoked

Created on 6 Nov 2018  路  9Comments  路  Source: microsoft/botbuilder-js

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. 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. Does anyone know what could be causing this issue?

const search = (turnContext) => {
    const knowledgeBaseTopic = turnContext.activity.value.knowledgeBaseTopic;
    request({
        method: 'Get',
        url: process.env.SN_KB_URL
    }, (error, response, body) => {
        console.log(error);
        var stuff = [];
        let messageWithCarouselOfCards = MessageFactory.carousel(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 }`])

            );
        }
        turnContext.sendActivity(messageWithCarouselOfCards);
    });
};

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)

Support

Most helpful comment

Make sure to await your call to turnContext.sendActivity:

await turnContext.sendActivity(messageWithCarouselOfCards);

All 9 comments

Make sure to await your call to turnContext.sendActivity:

await turnContext.sendActivity(messageWithCarouselOfCards);

I'm a little unsure of what you're trying to do since knowledgeBaseTopic seems to be unused. But I think what's going on here is that the proxy is being revoked by the time the callback for your request is run. Try using a library that uses async/await instead of callbacks.

the above function can be modified to use async/await like @v-kydela suggests:

const search = async (turnContext) => {
  const knowledgeBaseTopic = turnContext.activity.value.knowledgeBaseTopic;
  const message = await new Promise(resolve => {
    request({
      method: 'Get',
      url: process.env.SN_KB_URL
    }, (error, response, body) => {
      console.log(error);
      var stuff = [];
      let messageWithCarouselOfCards = MessageFactory.carousel(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 }`])
        );
      }
      resolve(messageWithCarouselOfCards);
    });
  });
  return turnContext.sendActivity(message);
};

// Inside a middleware or onTurn
async onTurn(turnContext) {
  await search(turnContext);
}

Yes that's my question. I'm going to try the request using a different module to see if that resolves my issue. I won't get a chance to do this until Monday but hopefully it will resolve it. Thanks for the help so far

@Weirwolf - Did you get a chance to try anything?

I've updated my request to use the Axios module now so I'm no longer getting the proxy revoked error. However I'm now getting a 401 'Unauthorised' error on my request and I'm not sure what I'm doing wrong with my authentication as I'm new to Axios. My request is below.

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

It looks like you're now sending auth information that you weren't before, and I'm not sure I understand the reason for the change. It may be worthwhile to try @justinwilaby's solution (make your own promise) and see if that works.

"Unauthorized" errors are common in bots because of missing or incorrect app ID's and passwords or keys to access services like LUIS. Are you sure it's your axios request that's producing the error?

You may need to end up sharing private information in order for me to reproduce this, so you can email me if you like.

I'm sure its the request that's causing the error, I've tried to create a function separate from the bot and I still get issues with the request. That being said I've now resolved the auth issue and I am instead getting an issue where it is not pulling in any articles which I've raised a stackoverflow question about -
https://stackoverflow.com/questions/53448900/typeerror-cannot-read-property-data-of-undefined. As this issue has been resolved I'll close off this issue.

Was this page helpful?
0 / 5 - 0 ratings