【问题标题】:How can I post a welcome message to a newly joined user via a Slack bot?如何通过 Slack 机器人向新加入的用户发布欢迎消息?
【发布时间】:2017-08-04 06:45:56
【问题描述】:

我正在尝试利用 Slack 的实时消息传递 (RTM) API 从“Greeter Bot”向我团队中新加入的用户发布欢迎消息。

我正在监听的事件是team_join

我已确认该事件正在触发,并且可以在收到该事件后将消息发送给之前加入的用户。然而,当试图通知新加入的用户时,没有任何反应。 在通知用户之前,我在收到事件后添加了延迟(最多 45 秒),但仍然没有骰子。

这是我的index.js 文件:

var SlackBot = require('slackbots');

var bot = new SlackBot({
  token: process.env.SLACK_TOKEN || '',
  name: process.env.BOT_NAME || 'greeterbot'
});

bot.on('message', function(data) {
  var self = this;
  if ('team_join' === data.type) {
    setTimeout(function() {
      var message = 'hello.';
      // this works. 'some crusty old user' gets a DM message from my greeterbot.
      self.postMessageToUser('some crusty old user', message, { as_user: true });
      // FAIL. what am i doing wrong?!
      self.postMessageToUser(data.user.name, message, { as_user: true });
    }, 45000);
    console.log("'" + data.user.name + "' has joined the team."); // works. the user name is present in the log.
  }
});

【问题讨论】:

    标签: node.js slack-api


    【解决方案1】:

    我想通了。我正在使用的底层机器人库存在缓存问题。

    作为参考,这里是一个旨在解决此问题的 PR 的链接。 https://github.com/mishk0/slack-bot-api/pull/25

    现在切换库。

    【讨论】:

      【解决方案2】:

      我们的 Slack 团队 SKGTech.io 使用我们编写的 Janitr。 Janit 是一款 Slack 机器人,可根据您的偏好欢迎新用户。

      【讨论】:

        猜你喜欢
        • 2021-01-22
        • 2020-05-18
        • 2021-11-13
        • 1970-01-01
        • 2015-10-02
        • 2021-06-24
        • 2020-01-22
        • 2023-03-20
        • 1970-01-01
        相关资源
        最近更新 更多