Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Botkit入門

 Botkit入門

社内勉強会用の資料です

Takuya Arita

May 17, 2016
Tweet

More Decks by Takuya Arita

Other Decks in Programming

Transcript

  1. ձ࿩Botʹ͍ͭͯ΋͏͢͜͠ • ͜͜࠷ۙͷ༷ʑͳBotؔ࿈χϡʔε • LINE΍Facebook, Microsoft͕BotΛ࢖ͬͨαʔϏε΍։ൃ؀ڥΛެ։͠࿩୊ʹͳͬͨ • ۙ೥ͷϏοάσʔλɺػցֶशɺਓ޻஌ೳͱ͍ͬͨΩʔϫʔυͱ΋ؔΘΓ͕͋Δͱ΋͍͑ Δ •

    ऩूͨ͠σʔλɺֶशͨ͠σʔλʹج͍ͮͯద੾ͳ൓ԠΛ͢Δ • LINEͱMicrosoft͕ఏڙ͍ͯ͠ΔʮΓΜͳʯ͕༗໊Ͳ͜Ζ • http://rinna.jp/rinna/ • SlackͷྲྀߦʹΑΓWebؔ࿈αʔϏεͷاۀͰ͸ɺBot͕ChatopsͳͲͷ৔໘Ͱ׆༻͞Εͯ ͍Δ
  2. ؀ڥߏங $ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -

    $ sudo apt-get install -y nodejs $ cd /vagrant $ npm install --save botkit
  3. αϯϓϧίʔυΛࢀߟʹ࣮૷ var Botkit = require('botkit'); var controller = Botkit.slackbot(); controller.spawn({

    token: process.env.SLACK_BOT_TOKEN, }).startRTM() controller.hears('͓͸Α͏', ['direct_message', 'direct_mention', 'mention'], function(bot, message) { bot.reply(message, 'ࠓ೔΋ΑΖ͘͠'); }); controller.hears('͜Μʹͪ͸', ['direct_message', 'direct_mention', 'mention'], function(bot, message) { bot.reply(message, '͜Μʹͪ͸'); }); controller.hears('͓͔ͭΕ͞·', ['direct_message', 'direct_mention', 'mention'], function(bot, message) { bot.reply(message, '·ͨ໌೔'); });
  4. ಈ࡞֬ೝ $ SLACK_BOT_TOKEN=BotϢʔβʔͷτʔΫϯ node bot.js info: ** No persistent storage

    method specified! Data may be lost when process shuts down. info: ** Setting up custom handlers for processing Slack messages info: ** API CALL: https://slack.com/api/rtm.start notice: ** BOT ID: greetbot ...attempting to connect to RTM!