首页 > 解决方案 > 您如何在 bot v4 上设置计时器?

问题描述

我想使用 5 秒的计时器来显示消息,但出现错误。它在 Node.Js 中。

有没有办法解决这个问题?谢谢

     const HELP_INTENT = 'Help';
     async onTurn(context) {
     Switch(Intent){
       case HELP_INTENT:
       var reply =  MessageFactory.suggestedActions(['Testing','Running'],`How do we help you?`);
     setInterval(() => {
       await dc.context.sendActivity(reply);
       }, 5000);
       break;
       case NONE_INTENT:
       default:
           await dc.context.sendActivity(`Sorry I do not understand you.`);
       break;
     }

标签: javascriptnode.jsazurebots

解决方案


你能试试这个吗

const HELP_INTENT = 'Help';
         async onTurn(context) {
         Switch(Intent){
           case HELP_INTENT:
           var reply =  MessageFactory.suggestedActions(['Testing','Running'],`How do we help you?`);
           await new Promise(resolve => setTimeout(() => resolve(
            dc.context.sendActivity(reply)
           ), 5000);
           break;
           case NONE_INTENT:
           default:
               await dc.context.sendActivity(`Sorry I do not understand you.`);
           break;
         }

推荐阅读