【问题标题】:Slack API chat.scheduleMessage everydaySlack API chat.scheduleMessage 每天
【发布时间】:2022-01-25 15:04:27
【问题描述】:

我想知道是否有一种方法可以编写日程安排,以便每天在 Slack 中发布一条消息。现在我有这个,但它只运行一次

https://slack.dev/bolt-js/tutorial/getting-started#listening-and-responding-to-a-message

https://github.com/SlackAPI/bolt-js

https://api.slack.com/tutorials/tags/glitch

https://slack.dev/bolt-js/concepts#custom-routes

https://github.com/slackapi/bolt-js/blob/main/README.md

// 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 运行

标签: api bots slack


【解决方案1】:

使用 Slack API 无法做到这一点。你也不希望在发布 Slack 消息之前每天都需要获取比特币转换率。您应该找到一种使用玉米作业执行此操作的方法。

【讨论】:

    猜你喜欢
    • 2018-12-03
    • 2016-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-10
    • 2019-01-04
    • 2019-12-11
    • 1970-01-01
    相关资源
    最近更新 更多