Bot 框架 - 在 Cron 回调函数内调用 TurnContext.sendActivity 方法时出现意外错误

2024-04-03

我在发送预定的 Skype 通知时遇到一些问题。

Error:

(node:3720) UnhandledPromiseRejectionWarning: TypeError: Cannot perform 'get' on a proxy that has been revoked

at CronJob.<anonymous> (C:\bots\clean\bot.js:101:43)
at CronJob.fireOnTick (C:\bots\clean\node_modules\cron\lib\cron.js:554:23)
at Timeout.callbackWrapper [as _onTimeout] (C:\bots\clean\node_modules\cron\lib\cron.js:621:10)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5)

(node:3720) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 61)

My code:

await turnContext.sendActivity('Successful write to log.');        
var CronJob = require('cron').CronJob;
new CronJob('*/5 * * * * *', async function() {
    console.log('Executed');
    await turnContext.sendActivity('Executed'); //here is error
}, null, true, 'Europe/Riga');

第一次致电sendActivity工作正常,但 Cron 回调中的第二个不行。

即使我尝试在 axios 内部调用then()功能它也工作..:

axios.get('/user', {
    params: {
      ID: 12345
    }
  })
  .then(async function (response) {
     await turnContext.sendActivity('Executed');
  })

有没有办法打电话sendActivity在 Cron 匿名函数中?


尝试在 Axios 请求中使用 async/await 方法,而不是 then/catch 方法。我过去在从回调函数调用 sendActivity 时见过这个问题。

const res = await axios.get('/user', { params: { ID: 12345 }});
await turnContext.sendActivity('Executed');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Bot 框架 - 在 Cron 回调函数内调用 TurnContext.sendActivity 方法时出现意外错误 的相关文章

随机推荐