LoginSignup
4
3

More than 3 years have passed since last update.

今更だけどSlackBotを作ってみた

Posted at

作ったツールは、PythonのツールでSlackで単純な受け答えするツール。
使用するPythonのライブラリは、「slackbot」を使用する。

ライブラリの場所

Slack側の設定

Slackの管理画面

検索から「Bots」入力

SlackBots.png

Botsの設定確認

SlackBots2.png

BotsのAPIトークンをメモする

image.png

Python側の設定

ライブラリをダウンロード

pip install slackbot

以下の構造道理作成する

slackbot
 └── run.py               :初期起動の設定
 └── slackbot_settings.py :ここに先程の上でメモしたAPI_TOKENをセットする。
 └── plugins
     └── __init__.py
     └── custom.py     :カスタマイズするファイル

Slackでメッセージをやりとりしてみるカスタマイズファイルを作成する。
Githubのサンプルをつかって、「Hi」とメッセージしたら「I can understand hi or HI!」をレスポンスする

custom.py
@respond_to('hi', re.IGNORECASE)
def hi(message):
    message.reply('I can understand hi or HI!')
    message.react('+1')

Slackボットを起動するコマンド

python run.py

コマンドで起動したらSlackでボットに「hi」とメッセージを行う

SlackMessage.png

以下にGithubに使用したファイルアップ

4
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
4
3