Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Botkit入門
Search
Takuya Arita
May 17, 2016
Programming
750
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Botkit入門
社内勉強会用の資料です
Takuya Arita
May 17, 2016
Transcript
17 slides
Botkitೖ @ariarijp
ఆϦεφʔ • “Bot”ͱ͍͏ΩʔϫʔυΛฉ͍ͨ͜ͱ͕͋Δ • SlackΛΑ͍ͬͯ͘Δ • BotkitΛฉ͍ͨ͜ͱ͕ͳ͍ɺͬͨ͜ͱ͕ͳ͍
Botͱ(WikipediaΑΓ) • ΠϯλʔωοτϘοτʢӳ: Internet botʣɺΠϯλʔωοτ্ͰࣗಈԽ͞ ΕͨλεΫΛ࣮ߦ͢ΔΞϓϦέʔγϣϯιϑτΣΞɻWebϘοτ͋Δ͍ ୯ʹϘοτͱݺͿɻҰൠʹ୯७ͳ܁Γฦ͠ͷλεΫΛ͜ͳ͠ɺͦͷΑ͏ͳ λεΫʹؔͯ͠ਓ͕ؒखͰΔΑΓߴͰ͋ΔɻϘοτओʹΫϩʔϥ ͱͯ͠ΘΕΔ͜ͱ͕ଟ͘ɺਓؒͷԿഒͷ͞ͰWebϖʔδΛࣗಈతʹ ूΊɺͦͷ༰ʢใʣΛੳͯ͠ྨ͢ΔɻWebαʔόʹ
robots.txt ͱ ͍͏ϑΝΠϧ͕͋ΓɺΫϩʔϥ͕ै͏͖نଇ͕ॻ͔Ε͍ͯΔɻ • ͦͷଞʹɺਓؒΑΓߴͳԠ͕ཁٻ͞ΕΔ໘ͰϘοτ͕ΘΕͨΓ ʢήʔϜΦʔΫγϣϯͳͲͰͷϘοτར༻ʣɺ·Εʹਓؒͷ׆ಈΛΤϛϡ Ϩʔγϣϯ͢ΔͷʹΘΕͨΓ͢ΔʢձϘοτͳͲʣɻ
ձBotʹ͍ͭͯ͏͢͜͠ • ͜͜࠷ۙͷ༷ʑͳBotؔ࿈χϡʔε • LINEFacebook, Microsoft͕BotΛͬͨαʔϏε։ൃڥΛެ։͠ʹͳͬͨ • ۙͷϏοάσʔλɺػցֶशɺਓೳͱ͍ͬͨΩʔϫʔυͱؔΘΓ͕͋Δͱ͍͑ Δ •
ऩूͨ͠σʔλɺֶशͨ͠σʔλʹج͍ͮͯదͳԠΛ͢Δ • LINEͱMicrosoft͕ఏڙ͍ͯ͠ΔʮΓΜͳʯ͕༗໊Ͳ͜Ζ • http://rinna.jp/rinna/ • SlackͷྲྀߦʹΑΓWebؔ࿈αʔϏεͷاۀͰɺBot͕ChatopsͳͲͷ໘Ͱ׆༻͞Εͯ ͍Δ
Botkitͱ • Slack༻ͷBotΛ࡞͢ΔͨΊͷϑϨʔϜϫʔ Ϋ • ϓϩάϥϛϯάݴޠNode.jsΛ༻͍ͯ͠Δ • ͔ᷮͳ࣮ͰಛఆͷΩʔϫʔυʹԠ͢ΔBot Λ؆୯ʹ࡞Δ͜ͱ͕Ͱ͖Δ
BotkitͰ ͍͋ͭ͞BotΛ࡞ͬͯΈΑ͏
͍͋ͭ͞Botͷࡶͳઃܭ • ʮ͓Α͏ʯͱ͔͚͠ΔͱʮࠓΑΖ͠ ͘ʯͱԠ͑Δ • ʮ͜Μʹͪʯͱ͔͚͠Δͱʮ͜Μʹͪʯ ͱԠ͑Δ • ʮ͓͔ͭΕ͞·ʯͱ͔͚͠Δͱʮ·ͨ໌ʯ ͱԠ͑Δ
ڥߏங $ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
$ sudo apt-get install -y nodejs $ cd /vagrant $ npm install --save botkit
αϯϓϧίʔυΛࢀߟʹ࣮ 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, '·ͨ໌'); });
ಈ࡞֬ೝ $ 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!
ಈ࡞֬ೝ • ࣮ߦ͢ΔͱBotϢʔβʔ͕ΦϯϥΠϯঢ়ଶʹͳ Δ • BotϢʔβʔΛదͳνϟϯωϧ·ͨάϧʔϓ ʹট͢Δ • BotϢʔβʔʹϝϯγϣϯΛ͚ͭͯʮ͓Α ͏ʯͱ͔͔͚ͯ͠ΈΔ
࣮ͷ·ͱΊ • controller.hearsͰԿʹԠ͢Δ͔Λఆٛ͢Δ • controller.hearsʹ͍ͯ͠Δແ໊ؔͰͲͷ Α͏ͳԠΛ͢Δ͔Λఆٛ͢Δ
ϦΞϧλΠϜʹձ͕Ͱ͖ΔΈ • WebSocketͱ͍͏௨৴ن(ϓϩτίϧ)Λ༻ • WebSocketʹ͍֤ͭͯࣗௐͯΈͯͩ͘͞ ͍ • HTTPͱͷҧ͍͕ཧղ͕Ͱ͖Δͱྑ͍Ͱ͠ΐ ͏
BotkitͳΒ࣮؆୯ͳͷͰ ͋ͱΞΠσΟΞ࣍ୈ
Botͷ࣮ྫ • ఱؾΛฉ͍ͨΒࠓͱ໌ͷఱؾΛڭ͑ͯ͘ΕΔ • Ӻ໊Λฉ͍ͨΒΓೖΕ࿏ઢΛڭ͑ͯ͘ΕΔ • ࠓͷ༧ఆΛฉ͍ͨΒGoogleΧϨϯμʔͳͲ͔ Βࣗͷ༧ఆΛڭ͑ͯ͘ΕΔ • ࢦఆͷ࣌ࠁʹͳͬͨΒ෦ఆྫͷϦϚΠϯυΛ͠
ͯ͘ΕΔ
طଘͷWebAPIͳͲͱ Έ߹ΘͤΔ͜ͱͰศརͳBot࡞ΕΔ
·ͱΊ • BotkitΛ͏͜ͱͰ؆୯ʹSlackͷBotΛ࡞Δ͜ ͱ͕Ͱ͖Δ • طଘͷWebAPIΛར༻͢Δ͜ͱͰɺBotʹศར ͳػೳΛ༩͢Δ͜ͱͰ͖Δ • Ͳ͏ͬͯ׆༻͢Δ͔ɺ։ൃऀͷΞΠσΟΞ ࣍ୈ
More Decks by Takuya Arita
See All by Takuya Arita
Hosted Redash の EOL と移行ツール redash-migrate / You should know about Hosted Redash EOL and redash-migrate
ariarijp
0
3.4k
Redash で踏み出す BI 導入はじめの一歩 / DataEngineeringStudy Redash
ariarijp
1
2.8k
Redash のいま / Redash in 2021
ariarijp
2
1.2k
Redash 導入・運用を4年ぐらいやって変わったこと・変わらなかったこと / Changed and unchanged things with Redash and me
ariarijp
0
1.5k
5年前の自分に伝えたい広告 API 周辺の歩き方 / SOT Tech Night vol.1
ariarijp
1
570
使われていない、を知る / How do we know unused things in the real world?
ariarijp
0
500
MULTI_ORG について / What is MULTI_ORG in Redash
ariarijp
1
4k
あらためて振り返る Redash の使いどころ / Why I strongly recommend Redash
ariarijp
2
1.3k
PHP Data Structures
ariarijp
1
590
Other Decks in Programming
See All in Programming
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
520
imagewebp()の向こう側: WebPはなぜ JPEG・PNGより軽いのか
yuzneri
0
160
Kawaiicon: Kubernetes, it's no longer cool, but let's secure it anyway!
barnbarn
0
150
Distance field of Julia set
kinakomoti321
0
340
ビジネスロジックを堅牢に~Scala 3のドメインプリミティブ~
j5ik2o
0
240
止まらない比較を止める — 余帰納法で無限ストリームを比べる
tarao
0
220
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
150
テスト駆動開発から学ぶ 達人プログラマーの型 / TechRAMEN 2026 Conference
a_okui
0
3.2k
Going Full Circle with Virtual Graphs and Relational Databases
michaelsimons
1
120
SODA - FACT BOOK(EN)
sodainc
1
310
AIコーディングをセッションで終わらせない: PHPライブラリ開発におけるコンテキスト承継設計
ickx
0
120
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
250
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.6k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
Writing Fast Ruby
sferik
630
63k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.8k
エンジニアに許された特別な時間の終わり
watany
109
250k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
830
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
650
AI: The stuff that nobody shows you
jnunemaker
PRO
12
1.3k
Ruling the World: When Life Gets Gamed
codingconduct
0
450