【发布时间】:2022-01-25 15:04:27
【问题描述】:
我想知道是否有一种方法可以编写日程安排,以便每天在 Slack 中发布一条消息。现在我有这个,但它只运行一次
https://slack.dev/bolt-js/tutorial/getting-started#listening-and-responding-to-a-message
// Require the Bolt package (github.com/slackapi/bolt)
const { App, subtype } = require('@slack/bolt');
const { WebClient } = require('@slack/web-api');
const axios = require('axios').default;
// Actions
(async () => {
let currentDate = new Date();
let futureDate = new Date(currentDate.getTime() + 3 * 60000);
let unixTimeStamp = Math.floor(futureDate.getTime() / 1000);
try {
const USD = await axios.get(
'https://api.coindesk.com/v1/bpi/currentprice.json'
);
const bitcoins = USD.data.bpi.USD.rate;
console.log(unixTimeStamp);
// Call chat.scheduleMessage with the built-in client
const result = await web.chat.scheduleMessage({
channel: general_channel,
post_at: unixTimeStamp,
text: `Summer has come and the Bitcoin is at ${bitcoins}`,
});
} catch (error) {
console.log(error);
}
})();
【问题讨论】:
-
您想查看 setInterval() 并将时间间隔设置为 24 小时,并让此进程 24/7 运行