2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SlackからRaspberry Piにメッセージを送信する(2019年3月時点)

Last updated at Posted at 2019-03-20

以前こちらの記事にSlackからRaspberry Piにメッセージを送信する話を記載したのですが、2日ほど前にnode-red-contrib-slackのバージョンが上がりましたので、最新版について記載したいと思います。
(私も感じていたのですが、以前のSlack Botノードはコネクションがいつの間にか切れていて応答がなくなる、ということがあったのですが、最新版では改善されているとのことです。)

以前のSlackノードを再現

本家のサイトに記載してある通りですが、以前のノードの動きを再現するには、Slackノードの前にfunctionノードが必要です。username, emojiIcon, channel の "" の部分に表示される送信ユーザ名、ユーザの絵文字、チャネル(「#」で始まるもの)を入れておきます。

// https://api.slack.com/methods/chat.postMessage
msg.topic = "chat.postMessage"
var payload = {
    text: msg.payload
};

// set default username (replicate the node configuration value)
var username = "";
if (username) {
    payload.username = username;
    payload.as_user = false;
} else if (msg.username) {
    payload.username = msg.username;
    payload.as_user = false;
}

// set default emojiIcon (replicate the node configuration value)
var emojiIcon = "";
if (emojiIcon) {
    payload.icon_emoji = emojiIcon;
} else if (msg.emojiIcon) {
    payload.icon_emoji = msg.emojiIcon;
}

// set default channel (replicate the node configuration value)
var channel = "";
if (channel) {
    payload.channel = channel;
} else if (msg.channel) {
    payload.channel = msg.channel
}

if (msg.attachments) {
    payload.attachments = msg.attachments;
}

msg.payload = payload;

return msg;

※ 上記には msg.attachments があり、以前はできなかった画像送信ができるのかと思ったのですが、試してみたところ送信はできませんでした。。私の設定の問題かもしれません。

参考にしたサイト

GitHub node-red-contrib-slack

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?