javascript - 您如何在 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;
}
解决方案
你能试试这个吗
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;
}
推荐阅读
- .htaccess - 使用 htaccess 重定向所有子域
- python - 抓取页面,获取图像并生成文件夹,每页抓取图像
- c# - 如何在 SelectionChanged 事件 C# 上的文本框中显示网格行值?
- reactjs - 为什么我的 React 应用无法在 Github 页面上运行?
- c++ - C++应该如何执行PowerShell命令?
- c# - 访问会话信息会给出 System.NullReferenceException
- scala - 错误:未找到:Scala 中的值 inputJPG
- powershell - Get-ADGroup 检索不返回其他林中成员的成员(但返回不同域/同一林中的成员)
- java - 宾果号码类:接收错误
- node.js - 使用 Node JS 和 React 出错