LoginSignup
1
4

More than 5 years have passed since last update.

BotkitでSlack Botを作って特定の発言に反応させる

Last updated at Posted at 2016-08-04
git clone git@github.com:howdyai/botkit.git
cd botkit
sudo npm install

// サンプルを実行。チャンネルにBotをinviteする必要がある
token=YOURTOKEN node slack_bot.js

slack_bot.jsの必要な場所だけ残して書き換える

if (!process.env.token) {
    console.log('Error: Specify token in environment');
    process.exit(1);
}

var Botkit = require('./lib/Botkit.js');
var os = require('os');

var controller = Botkit.slackbot({
    debug: true
});

var bot = controller.spawn({
    token: process.env.token
}).startRTM();

// 置換例:PerforceのパスをSwarmのパスに置き換える
controller.hears(['//depot'], 'ambient', function(bot, message) {
    var swarm_url = message.text.replace('//depot', 'http://xxxxxxxxx:1234/files/depot')
    bot.reply(message, swarm_url);
});

書き換えたらCtrl+Cで一度Botを落として再度実行すると、キーワード(今回は"//depot")に反応する

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