LoginSignup
1
1

More than 5 years have passed since last update.

BotkitでSlackのアプリメッセージをキャッチしたい

Posted at

概要

SlackでBotkitを使用してbotを作るとき、ユーザーのメッセージに反応するにはambientだったりmention,direct_messageなど使うが、これらはアプリ経由やwebhook経由からのメッセージには反応しない。
つまり人間が発言したメッセージ以外はbotがキャッチしてくれない。

図で説明するとこんな感じ

スクリーンショット 2018-08-07 0.21.40.png

このAPPが付いたメッセージをBotkitでキャッチしたい、とする。

方法

controller.hearsで2番めのイベント引数にbot_messageを渡すだけで反応してくれる

const Botkit = require('botkit');
const controller = Botkit.slackbot();
controller.hears([''], 'ambient, bot_message', (bot, message) => {
    //botがあれこれする箇所
});

ちなみに、Botkit自身が投稿したSlackメッセージには反応しない。

備考

ちなみに、このbot_messageはBotkitドキュメントに見当たらず、下記Issueを見た時に偶然知った。

Any reason why bots don't hear other bots in slack? · Issue #284 · howdyai/botkit https://github.com/howdyai/botkit/issues/284

参考リンク

Botkit公式ドキュメント
https://botkit.ai/docs/readme-slack.html

1
1
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
1
1