コンテンツにスキップ

Slack用botサンプル

Slakからのチャットの指示で動作をおこない、結果をslackに返すサンプルフローです。

サンプルフロー


[{"id":"651f0132.b80cb","type":"slack-rtmapi","z":"bac93068.01bd1","name":"","token":"","channels":"","events":["message"],"x":280,"y":820,"wires":[["c9e369d8.bc1be8"]]},{"id":"c9e369d8.bc1be8","type":"switch","z":"bac93068.01bd1","name":"","property":"payload.text","propertyType":"msg","rules":[{"t":"regex","v":"サイト確認","vt":"str","case":true},{"t":"regex","v":"PING確認","vt":"str","case":true}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":820,"wires":[["8788d057.62551"],["20a8e77d.081858"]]},{"id":"8788d057.62551","type":"site-login","z":"bac93068.01bd1","name":"サイト確認","viewwidth":800,"viewheight":600,"url":"https://www.calltracker.jp/","urlType":"str","timeout":30000,"waitfor":3000,"formactions":[],"conditions":[{"f":"page.screenshotb64","o":"screenshot","ot":"msg"}],"x":630,"y":780,"wires":[["e06ff35c.286b9"]]},{"id":"e06ff35c.286b9","type":"function","z":"bac93068.01bd1","name":"本文生成","func":"msg.filename = \"スクリーンショット.png\";\nmsg.description = \"サイト確認のエビデンスとなります。\";\nreturn msg;\n","outputs":1,"noerr":0,"x":820,"y":780,"wires":[["87e21dc0.8237e","28aa95ce.7583ea"]]},{"id":"87e21dc0.8237e","type":"slack-webapi","z":"bac93068.01bd1","name":"","token":"","channel":"","channelType":"str","class":"fileUpload","posttext":"","posttextType":"str","posticon":"","posticonType":"str","attachments":"","attachmentsType":"str","file":"screenshot","fileType":"msg","filename":"filename","filenameType":"msg","filetype":"auto","filetypeType":"str","filecomment":"現在のサイトはこのようになっています。","filecommentType":"str","x":1000,"y":780,"wires":[]},{"id":"20a8e77d.081858","type":"conf ping","z":"bac93068.01bd1","name":"PING確認","host":"www.calltracker.jp","timeout":"5","requests":"2","x":620,"y":860,"wires":[["bb0413c1.8e3aa"]]},{"id":"bb0413c1.8e3aa","type":"template","z":"bac93068.01bd1","name":"本文生成","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"PINGの結果は {{payload}} ms でした。","output":"str","x":820,"y":860,"wires":[["44bfd5be.e21a1c","d0b06a17.850ac8"]]},{"id":"44bfd5be.e21a1c","type":"slack-webapi","z":"bac93068.01bd1","name":"","token":"","channel":"","channelType":"str","class":"postMessage","posttext":"payload","posttextType":"msg","posticon":":robostein:","posticonType":"str","attachments":"","attachmentsType":"str","file":"screenshot","fileType":"str","filename":"SS","filenameType":"str","filetype":"auto","filetypeType":"str","filecomment":"先ほど取得したスクリーンショットです。","filecommentType":"str","x":1000,"y":860,"wires":[]},{"id":"bb9e5790.d75648","type":"corobo-trigger","z":"bac93068.01bd1","name":"正常終了","status":"1","statusType":"num","x":1000,"y":720,"wires":[]},{"id":"d70412f8.fa67b","type":"link in","z":"bac93068.01bd1","name":"正常終了","links":["d0b06a17.850ac8","28aa95ce.7583ea"],"x":855,"y":720,"wires":[["bb9e5790.d75648"]]},{"id":"d0b06a17.850ac8","type":"link out","z":"bac93068.01bd1","name":"","links":["d70412f8.fa67b"],"x":955,"y":900,"wires":[]},{"id":"28aa95ce.7583ea","type":"link out","z":"bac93068.01bd1","name":"","links":["d70412f8.fa67b"],"x":955,"y":820,"wires":[]},{"id":"a9fb184b.2aadf8","type":"catch","z":"bac93068.01bd1","name":"","scope":null,"uncaught":false,"x":540,"y":720,"wires":[["c05eb1e7.3c29"]]},{"id":"c05eb1e7.3c29","type":"corobo-trigger","z":"bac93068.01bd1","name":"異常終了","status":"2","statusType":"num","x":720,"y":720,"wires":[]},{"id":"cd80a08.6f7076","type":"comment","z":"bac93068.01bd1","name":"Slack BOT サンプル","info":"Slackからの受信については\nhttps://manual.robostein.io/sub-custom-node/received-Slack.html\nを見て設定を済ませてください。\n\nSlackへの送信については\nhttps://manual.robostein.io/sub-custom-node/send-Slack.html\nを見て設定を済ませてください。\n","x":310,"y":660,"wires":[]}]

上記を設置すると以下のようなフローが表示されます。 slack-botノード

設置後の設定

ただし、このままでは動作しませんのでコメントに記載の通り

Slackからの受信については
こちらを見て設定を済ませてください。

Slackへの送信については
こちらを見て設定を済ませてください。

上記の設定が済めばSlackで設定したチャンネル上にて「PING確認して」や「サイト確認して」をチャットする事により、robosteinがそのチャット内容を受け、実施した内容をslackに返答します。

これを使って

このサンプルフローを参考にし、

  • 分岐(switch)の条件を増やし、様々な事が出来るbotを作る
  • Slackからの受信をトリガーに動作をするフローを作る
  • Slackへの送信部分を利用し何かの結果をお知らせするフローを作る

など、パーツとしての利用やbot作成の参考にしてください。