我需要使用 Javascript 制作一个机器人每十分钟发送一条消息。我正在使用 Microsoft Bot Framework,这是入口代码:
const restify = require('restify');
const botbuilder = require('botbuilder');
var adapter = new botbuilder.BotFrameworkAdapter({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword
});
let server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log(`\n${server.name} listening to ${server.url}`);
console.log(`\nGet Bot Framework Emulator: https://aka.ms/botframework-emulator`);
});
server.post('/api/messages', (req, res) => {
adapter.processActivity(req, res, async (turnContext) => {
if (turnContext.activity.type === 'message') {
const text = turnContext.activity.text;
await turnContext.sendActivity(`You just said: ${ text }`);
}
});
});
基本上,无论与机器人交谈的人说什么,它都会以“你刚刚说:x”来回应。
我需要的是机器人在 Skype 中分组并每十分钟发送一条消息。
但是,在我的示例中,服务器等待对 /api/messages 的 POST,然后它使用适配器处理该请求并从来自 processActivity 方法的 turnContext 中触发“sendActivity”方法。
我怎样才能以固定的时间间隔发送一条消息,而忽略所有消息/提及。
