Slack从bot帖子改变主题

时间:2017-11-03 07:19:44

标签: slack slack-api

我有一个机器人,代码如下:

bot.on('message', function (data) {
    // all ingoing events https://api.slack.com/rtm
    console.log(data);
    if (data.content.includes('new')) {
        bot.postMessageToUser(data.subtitle, '#282828 ,#565656 ,#2AFC86 ,#282828 ,#434745 ,#FFFFFF ,#2AFC8e ,#DB6668 ');
    } else {
        bot.postMessageToUser(data.subtitle, 'I don\'t understand :scream_cat:\nPlease type "new" for a new color scheme.');
    }
});

当我发布配色方案时,它看起来像这样:

然而,当机器人发布完全相同的东西时,它看起来像这样:

发布时的方式是理想的结果。有什么方法可以让它发挥作用吗?

1 个答案:

答案 0 :(得分:0)

只需添加{as_user: true}作为搜索参数参数:

bot.on('message', function (data) {
    // all ingoing events https://api.slack.com/rtm
    console.log(data);
    if (data.content.includes('new')) {
        bot.postMessageToUser(data.subtitle, '#282828 ,#565656 ,#2AFC86 ,#282828 ,#434745 ,#FFFFFF ,#2AFC8e ,#DB6668 ', {as_user: true});
    } else {
        bot.postMessageToUser(data.subtitle, 'I don\'t understand :scream_cat:\nPlease type "new" for a new color scheme.', {as_user: true});
    }
});