消息未发布到Slack中的专用频道

时间:2019-07-08 03:04:00

标签: javascript api slack slack-api

我正在尝试为私人频道创建一个slackbot,我将其设置为应用程序并创建了一个bot。但是,当我尝试在私人频道中发布消息时,它不起作用。它适用于公共频道。我已在私人频道中添加了该应用程序/机器人。我在代码中使用Bot用户OAuth访问令牌。

const axios = require('axios');

const bot = new SlackBot({
  token: 'already-given',
  name: 'bot'
});

// Start Handler
bot.on('start', () => {
  const params = {
    icon_emoji: ':smiley:'
  };

  bot.postMessageToChannel(
    'pvtchannel',
    'I will assign a member soon!',
    params
  );
});

// Error Handle
bot.on('error', err => console.log(err));

// Message Handler
bot.on('message', data => {
  if (data.type !== 'message') {
    return;
  }

  handleMessage(data.text);
});

// Response to Data
function handleMessage(message) {
  if (message.includes('newspin')) {
    newSpin();

  } else (message.includes('help')) {
    runHelp();
  }
}

// Pick a team member randomly
function newSpin() {

    const params = {
      icon_emoji: ':laughing:'
    };
    var members=['1','2','3','4','5','6','7'];
    var assignee = members[Math.floor(Math.random()*members.length)];

      bot.postMessageToChannel('pvtchannel', `It's ${assignee}'s turn today!`, params);


}



// Show Help Text
function runHelp() {
  const params = {
    icon_emoji: ':question:'
  };

  bot.postMessageToChannel(
    'pvtchannel',
    `Type @bot with either 'newspin' for new spinning again,
    params
  );
}

这是我们需要向私人频道发布消息的方式吗?

bot.postMessageToChannel('pvtchannel', 'It's ${assignee}'s turn today!', params);

我很困惑是否需要在pvtchannel之前添加任何内容,因为它是私有的。

0 个答案:

没有答案