SlideShare a Scribd company logo
1 of 63
Download to read offline
Collaboration hack with slackbot
PyCon HK 2018 - 2018.11.24
Kei IWASAKI at SQUEEZE Inc.
1 / 63
你好!
2 / 63
Who am I ?
3 / 63
Kei IWASAKI
Web Application/Infrastructure Engineer
working at SQUEEZE Inc in Japan.
From Tokyo, Japan.
Twitter: @laugh_k, Github: @laughk
Co-authors of "スラスラわかるPython"
4 / 63
スラスラわかる Python
surasura wakaru Python
Python Introductory Book in Japanese
5 / 63
My other activities related to Python
in Japan
Python mini hack-a-thon
manthly event in Tokyo
Lecturer of Python ⼊⾨者の集い(hands-on events for Python begginer)
PyCon JP
PyCon JP 2015: LT
PyCon JP 2016: talk speaker
PyCon JP 2017: panel discussion
6 / 63
https://suitebook.io/
7 / 63
Collaboration hack with slackbot
PyCon HK 2018 - 2018.11.24
Kei IWASAKI at SQUEEZE Inc.
8 / 63
Today's sample source code is here
https://github.com/laughk/pyconhk2018-sample-code
9 / 63
Talking about today.
1. About slackbot
2. How to use slackbot?
3. Let's Try slackbot
4. Examples of slackbot
10 / 63
About slackbot
11 / 63
Slack
https://slack.com
Collaboration Platform
Slack allows us to
collaborate with chat on
channels and direct
messages.
12 / 63
About slack"bot"
13 / 63
Bot ?
14 / 63
Chatbot
15 / 63
Slack with bot
Slack is providing bot intergrations.
https://my.slack.com/apps/A0F7YS25R-bots
16 / 63
Slack with bot
You can make a slack bot using RTM API etc.
https://my.slack.com/apps/A0F7YS25R-bots 17 / 63
But, this API is hard to use directly...
18 / 63
All right. There is a nice framework!
19 / 63
slackbot
https://github.com/lins05/slackbot
a slack bot framwork by Python.
20 / 63
Let's Try slackbot
21 / 63
Quick start
install slackbot
$ pip install slackbot
make slackbot_settings.py like below.
API_TOKEN = '<set a bot user token from your slack team>'
DEFAULT_REPLY = 'Hi :raising_hand: I'm Slackbot'
22 / 63
Quick start
make run.py
from slackbot.bot import Bot
def main():
bot = Bot()
bot.run()
if __name__ == '__main__':
main()
run!
$ python run.py
23 / 63
Quick start
invite bot user to your channel
call bot user
24 / 63
Good 👍
25 / 63
Let's Try More !
26 / 63
make custom plugin
add below to slackbot_settings.py
API_TOKEN = '<set a bot user token from your slack team>'
DEFAULT_REPLY = 'Hi :raising_hand: I'm Slackbot'
PLUGINS = [
'plugin'
]
27 / 63
make custom plugin
add below to slackbot_settings.py
API_TOKEN = '<set a bot user token from your slack team>'
DEFAULT_REPLY = 'Hi :raising_hand: I'm Slackbot'
PLUGINS = [
'plugin'
]
28 / 63
make custom plugin
make plugin.py like below
from slackbot.bot import respond_to, listen_to
@respond_to(r'parrots+(.+)')
def parrot(message, word):
message.reply(word)
@listen_to(r'HAHAHA')
def what_is_funny(message):
message.send('What is funny?')
29 / 63
30 / 63
Use the slackbot function below
listen_to
called when a message matching the pattern is sent on a channel/private
channel chat.
response_to
called when a message matching the pattern is sent to the bot.
31 / 63
listen_to
called when a message matching the pattern is sent on a channel/private channel
chat.
@listen_to(r'HAHAHA')
def what_is_funny(message):
message.send('What is funny?')
32 / 63
response_to
called when a message matching the pattern is sent to the bot.
@respond_to(r'parrots+(.+)')
def parrot(message, word):
message.reply(word)
33 / 63
Let's Try More! More!
34 / 63
slackbot x PeeWee(database)
PeeWee
http://docs.peewee-orm.com/en/latest/
simple and small ORM.
35 / 63
Let's make simple memo plugin with
PeeWee 💪
36 / 63
simple memo plugin with PeeWee
make data modeles, as models.py like below.
import os
from peewee import SqliteDatabase, Model, CharField, TextField
db = SqliteDatabase(os.path.join(os.path.dirname(__file__), 'bot_database.db'))
class Memo(Model):
name = CharField(primary_key=True)
text = TextField()
class Meta:
database = db
db.connect()
db.create_tables([Memo], safe=True)
37 / 63
simple memo plugin with PeeWee
add functions to plugin.py like below.
from models import Memo
...
@respond_to(r'memos+saves+(S+)s+(S.*)')
def memo_save(message, name, text):
memo, created = Memo.get_or_create(name=name, text=text)
memo.save()
message.reply(f'I remembered a memo "{name}"')
@respond_to(r'memos+shows+(S+)')
def memo_show(message, name):
memo = Memo.get_or_none(name=name)
if memo:
message.reply(f'memo "{name}" is belown```n{memo.text}n```n')
else:
message.reply(f'memo "{name}" ... hmm ..., I don't know ¯_(ツ)_/¯')
38 / 63
save and show memo
39 / 63
not exits memo
40 / 63
Good 🙌
41 / 63
Try! More! More! More!
42 / 63
slackbot x requests x Web API
43 / 63
slackbot x requests x Web API
requests
http://python-requests.org/
Python HTTP Requests for Humans
44 / 63
Weather API by OpenWeatherMap
https://openweathermap.org/current 45 / 63
Weather API by OpenWeatherMap
https://openweathermap.org/appid
You can get APPID for Free! 46 / 63
$ curl -Ls 
> 'https://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=<Your AP
> python -m json.tool
{
"coord": {
"lon": -0.13,
"lat": 51.51
},
"weather": [
{
"id": 300,
"main": "Drizzle",
"description": "light intensity drizzle",
"icon": "09d"
}
],
-- -- snip -- --
}
47 / 63
Let's make simple weather information
plugin 🌄
48 / 63
make simple weather information plugin
add parameter information to slackbot_setting.py like below
API_TOKEN = '<set a bot user token from your slack team>'
DEFAULT_REPLY = 'Hi :raising_hand: I'm Slackbot'
PLUGINS = [
'plugin'
]
OPENWEATHERMAP_APPID = 'b6******************************' # put Your APPID
you can use a parameter
>>> from slackbot import settings
>>> settings.OPENWEATHERMAP_APPID
b6******************************
49 / 63
make simple weather information plugin
add functions to plugin.py like below.
import json, requests
from slackbot import settings
...
@respond_to(r'weathers+(S+)')
def show_weather(message, city):
url = 'http://api.openweathermap.org/data/2.5/weather'
result = requests.get(
f'{url}?q={city}&appid={settings.OPENWEATHERMAP_APPID}'
)
data_dict = json.loads(result.content.decode())
if result.status_code == 200:
message.reply('nCurrent Weathern'
f'{data_dict["name"]}: {data_dict["weather"][0]["description"]}')
else:
message.reply('Sorry, I could not get weather Information :sob:')
50 / 63
51 / 63
Great!!
52 / 63
Further applications examples
53 / 63
slackbot x AWS
boto3
https://github.com/boto/boto3
AWS SDK for Python.
54 / 63
show ec2 instance information from id
sample code: https://bit.ly/2PLI0Mu
55 / 63
slackbot x Gitbub
PyGithub
https://pygithub.readthedocs.io
Typed interactions with the GitHub API v3
56 / 63
reviewer assign plugin
sample code: https://bit.ly/2Bsii6S
57 / 63
slackbot x Slacker x PeeWee
Slacker
https://github.com/os/slacker
Full-featured Python interface for the Slack API
you can use slack function more than using slackbot (ex. getting slack userid)
58 / 63
Plusplus Plugin
count of Karma
you can Praise the team members!
this source code from pyconjpbot
https://github.com/pyconjp/pyconjpbot/blob/master/pyconjpbot/plugins/pluspl
59 / 63
You can let a slackbot do anything
else you can do with Python
60 / 63
Let's hack your collaboration
with Python !
61 / 63
References
lins05/slackbot: A chat bot for Slack (https://slack.com).
pyconjp/pyconjpbot: Slack bot for PyCon JP Slack
62 / 63
多謝
63 / 63

More Related Content

What's hot

I/O Extended (GDG Bogor) - Sidiq Permana
I/O Extended (GDG Bogor) - Sidiq PermanaI/O Extended (GDG Bogor) - Sidiq Permana
I/O Extended (GDG Bogor) - Sidiq PermanaDicoding
 
Introduction to Spring WebFlux #jsug #sf_a1
Introduction to Spring WebFlux #jsug #sf_a1Introduction to Spring WebFlux #jsug #sf_a1
Introduction to Spring WebFlux #jsug #sf_a1Toshiaki Maki
 
OpenWhisk by Example - Auto Retweeting Example in Python
OpenWhisk by Example - Auto Retweeting Example in PythonOpenWhisk by Example - Auto Retweeting Example in Python
OpenWhisk by Example - Auto Retweeting Example in PythonCodeOps Technologies LLP
 
Silicon Valley Code Camp 2019 - Reaching the Cloud Native World
Silicon Valley Code Camp 2019 - Reaching the Cloud Native WorldSilicon Valley Code Camp 2019 - Reaching the Cloud Native World
Silicon Valley Code Camp 2019 - Reaching the Cloud Native WorldChris Bailey
 
Python in the land of serverless
Python in the land of serverlessPython in the land of serverless
Python in the land of serverlessDavid Przybilla
 
Proxy Deep Dive Voxxed Belgrad 2015
Proxy Deep Dive Voxxed Belgrad 2015Proxy Deep Dive Voxxed Belgrad 2015
Proxy Deep Dive Voxxed Belgrad 2015Sven Ruppert
 
Effective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good PracticesEffective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good PracticesNaresha K
 
Spring Cloud Function & Project riff #jsug
Spring Cloud Function & Project riff #jsugSpring Cloud Function & Project riff #jsug
Spring Cloud Function & Project riff #jsugToshiaki Maki
 
Getting Started with Maven and Cucumber in Eclipse
Getting Started with Maven and Cucumber in EclipseGetting Started with Maven and Cucumber in Eclipse
Getting Started with Maven and Cucumber in EclipseTom Arend
 
What is Puppet? | How Puppet Works? | Puppet Tutorial For Beginners | DevOps ...
What is Puppet? | How Puppet Works? | Puppet Tutorial For Beginners | DevOps ...What is Puppet? | How Puppet Works? | Puppet Tutorial For Beginners | DevOps ...
What is Puppet? | How Puppet Works? | Puppet Tutorial For Beginners | DevOps ...Simplilearn
 
Software Project Management
Software Project ManagementSoftware Project Management
Software Project ManagementWidoyo PH
 
Velocity London - Chaos Engineering Bootcamp
Velocity London - Chaos Engineering Bootcamp Velocity London - Chaos Engineering Bootcamp
Velocity London - Chaos Engineering Bootcamp Ana Medina
 
Mobile Development integration tests
Mobile Development integration testsMobile Development integration tests
Mobile Development integration testsKenneth Poon
 
Docker and Django Meet For A Tango - London Meetup
Docker and Django Meet For A Tango - London MeetupDocker and Django Meet For A Tango - London Meetup
Docker and Django Meet For A Tango - London Meetupfrentrup
 
Puppet Camp Dallas 2014: How Puppet Ops Rolls
Puppet Camp Dallas 2014: How Puppet Ops RollsPuppet Camp Dallas 2014: How Puppet Ops Rolls
Puppet Camp Dallas 2014: How Puppet Ops RollsPuppet
 

What's hot (16)

I/O Extended (GDG Bogor) - Sidiq Permana
I/O Extended (GDG Bogor) - Sidiq PermanaI/O Extended (GDG Bogor) - Sidiq Permana
I/O Extended (GDG Bogor) - Sidiq Permana
 
Introduction to Spring WebFlux #jsug #sf_a1
Introduction to Spring WebFlux #jsug #sf_a1Introduction to Spring WebFlux #jsug #sf_a1
Introduction to Spring WebFlux #jsug #sf_a1
 
OpenWhisk by Example - Auto Retweeting Example in Python
OpenWhisk by Example - Auto Retweeting Example in PythonOpenWhisk by Example - Auto Retweeting Example in Python
OpenWhisk by Example - Auto Retweeting Example in Python
 
Silicon Valley Code Camp 2019 - Reaching the Cloud Native World
Silicon Valley Code Camp 2019 - Reaching the Cloud Native WorldSilicon Valley Code Camp 2019 - Reaching the Cloud Native World
Silicon Valley Code Camp 2019 - Reaching the Cloud Native World
 
Python in the land of serverless
Python in the land of serverlessPython in the land of serverless
Python in the land of serverless
 
Proxy Deep Dive Voxxed Belgrad 2015
Proxy Deep Dive Voxxed Belgrad 2015Proxy Deep Dive Voxxed Belgrad 2015
Proxy Deep Dive Voxxed Belgrad 2015
 
Java Applets
Java AppletsJava Applets
Java Applets
 
Effective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good PracticesEffective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good Practices
 
Spring Cloud Function & Project riff #jsug
Spring Cloud Function & Project riff #jsugSpring Cloud Function & Project riff #jsug
Spring Cloud Function & Project riff #jsug
 
Getting Started with Maven and Cucumber in Eclipse
Getting Started with Maven and Cucumber in EclipseGetting Started with Maven and Cucumber in Eclipse
Getting Started with Maven and Cucumber in Eclipse
 
What is Puppet? | How Puppet Works? | Puppet Tutorial For Beginners | DevOps ...
What is Puppet? | How Puppet Works? | Puppet Tutorial For Beginners | DevOps ...What is Puppet? | How Puppet Works? | Puppet Tutorial For Beginners | DevOps ...
What is Puppet? | How Puppet Works? | Puppet Tutorial For Beginners | DevOps ...
 
Software Project Management
Software Project ManagementSoftware Project Management
Software Project Management
 
Velocity London - Chaos Engineering Bootcamp
Velocity London - Chaos Engineering Bootcamp Velocity London - Chaos Engineering Bootcamp
Velocity London - Chaos Engineering Bootcamp
 
Mobile Development integration tests
Mobile Development integration testsMobile Development integration tests
Mobile Development integration tests
 
Docker and Django Meet For A Tango - London Meetup
Docker and Django Meet For A Tango - London MeetupDocker and Django Meet For A Tango - London Meetup
Docker and Django Meet For A Tango - London Meetup
 
Puppet Camp Dallas 2014: How Puppet Ops Rolls
Puppet Camp Dallas 2014: How Puppet Ops RollsPuppet Camp Dallas 2014: How Puppet Ops Rolls
Puppet Camp Dallas 2014: How Puppet Ops Rolls
 

Similar to Collaboration hack with slackbot - PyCon HK 2018 - 2018.11.24

나도 할 수 있다 오픈소스
나도 할 수 있다 오픈소스나도 할 수 있다 오픈소스
나도 할 수 있다 오픈소스효준 강
 
Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)Yuriy Senko
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...Jian-Hong Pan
 
apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...
apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...
apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...apidays
 
Build restful ap is with python and flask
Build restful ap is with python and flaskBuild restful ap is with python and flask
Build restful ap is with python and flaskJeetendra singh
 
Where's the source, Luke? : How to find and debug the code behind Plone
Where's the source, Luke? : How to find and debug the code behind PloneWhere's the source, Luke? : How to find and debug the code behind Plone
Where's the source, Luke? : How to find and debug the code behind PloneVincenzo Barone
 
HotPush with Ionic 2 and CodePush
HotPush with Ionic 2 and CodePushHotPush with Ionic 2 and CodePush
HotPush with Ionic 2 and CodePushEvan Schultz
 
How to send gzipped requests with boto3
How to send gzipped requests with boto3How to send gzipped requests with boto3
How to send gzipped requests with boto3Luciano Mammino
 
First python project
First python projectFirst python project
First python projectNeetu Jain
 
Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk PemulaOon Arfiandwi
 
Python Flask app deployed to OPenShift using Wercker CI
Python Flask app deployed to OPenShift using Wercker CIPython Flask app deployed to OPenShift using Wercker CI
Python Flask app deployed to OPenShift using Wercker CIBruno Rocha
 
Compose Camp Slide Session 1
Compose Camp Slide Session 1Compose Camp Slide Session 1
Compose Camp Slide Session 1AkshatBajpai12
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingAlessandro Molina
 
Build resource server &amp; client for OCF Cloud (2018.8.30)
Build resource server &amp; client for OCF Cloud (2018.8.30)Build resource server &amp; client for OCF Cloud (2018.8.30)
Build resource server &amp; client for OCF Cloud (2018.8.30)남균 김
 
[CON3189] JavaOne 2016 - Introduction to Java ME development for the Raspberr...
[CON3189] JavaOne 2016 - Introduction to Java ME development for the Raspberr...[CON3189] JavaOne 2016 - Introduction to Java ME development for the Raspberr...
[CON3189] JavaOne 2016 - Introduction to Java ME development for the Raspberr...Kevin Hooke
 
Building Cloud Castles
Building Cloud CastlesBuilding Cloud Castles
Building Cloud CastlesBen Scofield
 

Similar to Collaboration hack with slackbot - PyCon HK 2018 - 2018.11.24 (20)

나도 할 수 있다 오픈소스
나도 할 수 있다 오픈소스나도 할 수 있다 오픈소스
나도 할 수 있다 오픈소스
 
Origins of Serverless
Origins of ServerlessOrigins of Serverless
Origins of Serverless
 
Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
 
apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...
apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...
apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...
 
Build restful ap is with python and flask
Build restful ap is with python and flaskBuild restful ap is with python and flask
Build restful ap is with python and flask
 
Where's the source, Luke? : How to find and debug the code behind Plone
Where's the source, Luke? : How to find and debug the code behind PloneWhere's the source, Luke? : How to find and debug the code behind Plone
Where's the source, Luke? : How to find and debug the code behind Plone
 
HotPush with Ionic 2 and CodePush
HotPush with Ionic 2 and CodePushHotPush with Ionic 2 and CodePush
HotPush with Ionic 2 and CodePush
 
How to send gzipped requests with boto3
How to send gzipped requests with boto3How to send gzipped requests with boto3
How to send gzipped requests with boto3
 
First python project
First python projectFirst python project
First python project
 
Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk Pemula
 
Python Flask app deployed to OPenShift using Wercker CI
Python Flask app deployed to OPenShift using Wercker CIPython Flask app deployed to OPenShift using Wercker CI
Python Flask app deployed to OPenShift using Wercker CI
 
PSGI REST API
PSGI REST APIPSGI REST API
PSGI REST API
 
Compose Camp Slide Session 1
Compose Camp Slide Session 1Compose Camp Slide Session 1
Compose Camp Slide Session 1
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears Training
 
Build resource server &amp; client for OCF Cloud (2018.8.30)
Build resource server &amp; client for OCF Cloud (2018.8.30)Build resource server &amp; client for OCF Cloud (2018.8.30)
Build resource server &amp; client for OCF Cloud (2018.8.30)
 
[CON3189] JavaOne 2016 - Introduction to Java ME development for the Raspberr...
[CON3189] JavaOne 2016 - Introduction to Java ME development for the Raspberr...[CON3189] JavaOne 2016 - Introduction to Java ME development for the Raspberr...
[CON3189] JavaOne 2016 - Introduction to Java ME development for the Raspberr...
 
Building Cloud Castles
Building Cloud CastlesBuilding Cloud Castles
Building Cloud Castles
 
Mojolicious lite
Mojolicious liteMojolicious lite
Mojolicious lite
 

More from Kei IWASAKI

コロナ渦とキャリアの話 / my carrier and covid-19
コロナ渦とキャリアの話 / my carrier and covid-19コロナ渦とキャリアの話 / my carrier and covid-19
コロナ渦とキャリアの話 / my carrier and covid-19Kei IWASAKI
 
Elasticbeanstalk で Ansible を使っている話
Elasticbeanstalk で Ansible を使っている話Elasticbeanstalk で Ansible を使っている話
Elasticbeanstalk で Ansible を使っている話Kei IWASAKI
 
入門書を読み終わったらなにしよう? 〜Python と WebAPI の使い方から学ぶ次の一歩〜 / next-step-python-programing
入門書を読み終わったらなにしよう? 〜Python と WebAPI の使い方から学ぶ次の一歩〜 / next-step-python-programing入門書を読み終わったらなにしよう? 〜Python と WebAPI の使い方から学ぶ次の一歩〜 / next-step-python-programing
入門書を読み終わったらなにしよう? 〜Python と WebAPI の使い方から学ぶ次の一歩〜 / next-step-python-programingKei IWASAKI
 
Pelican の紹介 / World Plone Day 2017 Tokyo
Pelican の紹介 / World Plone Day 2017 TokyoPelican の紹介 / World Plone Day 2017 Tokyo
Pelican の紹介 / World Plone Day 2017 TokyoKei IWASAKI
 
たった一ファイルの python スクリプトから始めるOSS開発入門 / PyCon JP 2016
たった一ファイルの python スクリプトから始めるOSS開発入門 / PyCon JP 2016たった一ファイルの python スクリプトから始めるOSS開発入門 / PyCon JP 2016
たった一ファイルの python スクリプトから始めるOSS開発入門 / PyCon JP 2016Kei IWASAKI
 
3分でサーバオペレーションコマンドを作る技術
3分でサーバオペレーションコマンドを作る技術3分でサーバオペレーションコマンドを作る技術
3分でサーバオペレーションコマンドを作る技術Kei IWASAKI
 
Cli mini Hack!#1 ~Terminalとの親睦を深めよう~
Cli mini Hack!#1 ~Terminalとの親睦を深めよう~Cli mini Hack!#1 ~Terminalとの親睦を深めよう~
Cli mini Hack!#1 ~Terminalとの親睦を深めよう~Kei IWASAKI
 
Vagrant+virtualboxを使ってみよう
Vagrant+virtualboxを使ってみようVagrant+virtualboxを使ってみよう
Vagrant+virtualboxを使ってみようKei IWASAKI
 
障害発生時に抑えておきたい基礎知識
障害発生時に抑えておきたい基礎知識障害発生時に抑えておきたい基礎知識
障害発生時に抑えておきたい基礎知識Kei IWASAKI
 
監視のススメ
監視のススメ監視のススメ
監視のススメKei IWASAKI
 

More from Kei IWASAKI (10)

コロナ渦とキャリアの話 / my carrier and covid-19
コロナ渦とキャリアの話 / my carrier and covid-19コロナ渦とキャリアの話 / my carrier and covid-19
コロナ渦とキャリアの話 / my carrier and covid-19
 
Elasticbeanstalk で Ansible を使っている話
Elasticbeanstalk で Ansible を使っている話Elasticbeanstalk で Ansible を使っている話
Elasticbeanstalk で Ansible を使っている話
 
入門書を読み終わったらなにしよう? 〜Python と WebAPI の使い方から学ぶ次の一歩〜 / next-step-python-programing
入門書を読み終わったらなにしよう? 〜Python と WebAPI の使い方から学ぶ次の一歩〜 / next-step-python-programing入門書を読み終わったらなにしよう? 〜Python と WebAPI の使い方から学ぶ次の一歩〜 / next-step-python-programing
入門書を読み終わったらなにしよう? 〜Python と WebAPI の使い方から学ぶ次の一歩〜 / next-step-python-programing
 
Pelican の紹介 / World Plone Day 2017 Tokyo
Pelican の紹介 / World Plone Day 2017 TokyoPelican の紹介 / World Plone Day 2017 Tokyo
Pelican の紹介 / World Plone Day 2017 Tokyo
 
たった一ファイルの python スクリプトから始めるOSS開発入門 / PyCon JP 2016
たった一ファイルの python スクリプトから始めるOSS開発入門 / PyCon JP 2016たった一ファイルの python スクリプトから始めるOSS開発入門 / PyCon JP 2016
たった一ファイルの python スクリプトから始めるOSS開発入門 / PyCon JP 2016
 
3分でサーバオペレーションコマンドを作る技術
3分でサーバオペレーションコマンドを作る技術3分でサーバオペレーションコマンドを作る技術
3分でサーバオペレーションコマンドを作る技術
 
Cli mini Hack!#1 ~Terminalとの親睦を深めよう~
Cli mini Hack!#1 ~Terminalとの親睦を深めよう~Cli mini Hack!#1 ~Terminalとの親睦を深めよう~
Cli mini Hack!#1 ~Terminalとの親睦を深めよう~
 
Vagrant+virtualboxを使ってみよう
Vagrant+virtualboxを使ってみようVagrant+virtualboxを使ってみよう
Vagrant+virtualboxを使ってみよう
 
障害発生時に抑えておきたい基礎知識
障害発生時に抑えておきたい基礎知識障害発生時に抑えておきたい基礎知識
障害発生時に抑えておきたい基礎知識
 
監視のススメ
監視のススメ監視のススメ
監視のススメ
 

Recently uploaded

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 

Recently uploaded (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

Collaboration hack with slackbot - PyCon HK 2018 - 2018.11.24

  • 1. Collaboration hack with slackbot PyCon HK 2018 - 2018.11.24 Kei IWASAKI at SQUEEZE Inc. 1 / 63
  • 3. Who am I ? 3 / 63
  • 4. Kei IWASAKI Web Application/Infrastructure Engineer working at SQUEEZE Inc in Japan. From Tokyo, Japan. Twitter: @laugh_k, Github: @laughk Co-authors of "スラスラわかるPython" 4 / 63
  • 5. スラスラわかる Python surasura wakaru Python Python Introductory Book in Japanese 5 / 63
  • 6. My other activities related to Python in Japan Python mini hack-a-thon manthly event in Tokyo Lecturer of Python ⼊⾨者の集い(hands-on events for Python begginer) PyCon JP PyCon JP 2015: LT PyCon JP 2016: talk speaker PyCon JP 2017: panel discussion 6 / 63
  • 8. Collaboration hack with slackbot PyCon HK 2018 - 2018.11.24 Kei IWASAKI at SQUEEZE Inc. 8 / 63
  • 9. Today's sample source code is here https://github.com/laughk/pyconhk2018-sample-code 9 / 63
  • 10. Talking about today. 1. About slackbot 2. How to use slackbot? 3. Let's Try slackbot 4. Examples of slackbot 10 / 63
  • 12. Slack https://slack.com Collaboration Platform Slack allows us to collaborate with chat on channels and direct messages. 12 / 63
  • 16. Slack with bot Slack is providing bot intergrations. https://my.slack.com/apps/A0F7YS25R-bots 16 / 63
  • 17. Slack with bot You can make a slack bot using RTM API etc. https://my.slack.com/apps/A0F7YS25R-bots 17 / 63
  • 18. But, this API is hard to use directly... 18 / 63
  • 19. All right. There is a nice framework! 19 / 63
  • 22. Quick start install slackbot $ pip install slackbot make slackbot_settings.py like below. API_TOKEN = '<set a bot user token from your slack team>' DEFAULT_REPLY = 'Hi :raising_hand: I'm Slackbot' 22 / 63
  • 23. Quick start make run.py from slackbot.bot import Bot def main(): bot = Bot() bot.run() if __name__ == '__main__': main() run! $ python run.py 23 / 63
  • 24. Quick start invite bot user to your channel call bot user 24 / 63
  • 26. Let's Try More ! 26 / 63
  • 27. make custom plugin add below to slackbot_settings.py API_TOKEN = '<set a bot user token from your slack team>' DEFAULT_REPLY = 'Hi :raising_hand: I'm Slackbot' PLUGINS = [ 'plugin' ] 27 / 63
  • 28. make custom plugin add below to slackbot_settings.py API_TOKEN = '<set a bot user token from your slack team>' DEFAULT_REPLY = 'Hi :raising_hand: I'm Slackbot' PLUGINS = [ 'plugin' ] 28 / 63
  • 29. make custom plugin make plugin.py like below from slackbot.bot import respond_to, listen_to @respond_to(r'parrots+(.+)') def parrot(message, word): message.reply(word) @listen_to(r'HAHAHA') def what_is_funny(message): message.send('What is funny?') 29 / 63
  • 31. Use the slackbot function below listen_to called when a message matching the pattern is sent on a channel/private channel chat. response_to called when a message matching the pattern is sent to the bot. 31 / 63
  • 32. listen_to called when a message matching the pattern is sent on a channel/private channel chat. @listen_to(r'HAHAHA') def what_is_funny(message): message.send('What is funny?') 32 / 63
  • 33. response_to called when a message matching the pattern is sent to the bot. @respond_to(r'parrots+(.+)') def parrot(message, word): message.reply(word) 33 / 63
  • 34. Let's Try More! More! 34 / 63
  • 36. Let's make simple memo plugin with PeeWee 💪 36 / 63
  • 37. simple memo plugin with PeeWee make data modeles, as models.py like below. import os from peewee import SqliteDatabase, Model, CharField, TextField db = SqliteDatabase(os.path.join(os.path.dirname(__file__), 'bot_database.db')) class Memo(Model): name = CharField(primary_key=True) text = TextField() class Meta: database = db db.connect() db.create_tables([Memo], safe=True) 37 / 63
  • 38. simple memo plugin with PeeWee add functions to plugin.py like below. from models import Memo ... @respond_to(r'memos+saves+(S+)s+(S.*)') def memo_save(message, name, text): memo, created = Memo.get_or_create(name=name, text=text) memo.save() message.reply(f'I remembered a memo "{name}"') @respond_to(r'memos+shows+(S+)') def memo_show(message, name): memo = Memo.get_or_none(name=name) if memo: message.reply(f'memo "{name}" is belown```n{memo.text}n```n') else: message.reply(f'memo "{name}" ... hmm ..., I don't know ¯_(ツ)_/¯') 38 / 63
  • 39. save and show memo 39 / 63
  • 42. Try! More! More! More! 42 / 63
  • 43. slackbot x requests x Web API 43 / 63
  • 44. slackbot x requests x Web API requests http://python-requests.org/ Python HTTP Requests for Humans 44 / 63
  • 45. Weather API by OpenWeatherMap https://openweathermap.org/current 45 / 63
  • 46. Weather API by OpenWeatherMap https://openweathermap.org/appid You can get APPID for Free! 46 / 63
  • 47. $ curl -Ls > 'https://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=<Your AP > python -m json.tool { "coord": { "lon": -0.13, "lat": 51.51 }, "weather": [ { "id": 300, "main": "Drizzle", "description": "light intensity drizzle", "icon": "09d" } ], -- -- snip -- -- } 47 / 63
  • 48. Let's make simple weather information plugin 🌄 48 / 63
  • 49. make simple weather information plugin add parameter information to slackbot_setting.py like below API_TOKEN = '<set a bot user token from your slack team>' DEFAULT_REPLY = 'Hi :raising_hand: I'm Slackbot' PLUGINS = [ 'plugin' ] OPENWEATHERMAP_APPID = 'b6******************************' # put Your APPID you can use a parameter >>> from slackbot import settings >>> settings.OPENWEATHERMAP_APPID b6****************************** 49 / 63
  • 50. make simple weather information plugin add functions to plugin.py like below. import json, requests from slackbot import settings ... @respond_to(r'weathers+(S+)') def show_weather(message, city): url = 'http://api.openweathermap.org/data/2.5/weather' result = requests.get( f'{url}?q={city}&appid={settings.OPENWEATHERMAP_APPID}' ) data_dict = json.loads(result.content.decode()) if result.status_code == 200: message.reply('nCurrent Weathern' f'{data_dict["name"]}: {data_dict["weather"][0]["description"]}') else: message.reply('Sorry, I could not get weather Information :sob:') 50 / 63
  • 55. show ec2 instance information from id sample code: https://bit.ly/2PLI0Mu 55 / 63
  • 56. slackbot x Gitbub PyGithub https://pygithub.readthedocs.io Typed interactions with the GitHub API v3 56 / 63
  • 57. reviewer assign plugin sample code: https://bit.ly/2Bsii6S 57 / 63
  • 58. slackbot x Slacker x PeeWee Slacker https://github.com/os/slacker Full-featured Python interface for the Slack API you can use slack function more than using slackbot (ex. getting slack userid) 58 / 63
  • 59. Plusplus Plugin count of Karma you can Praise the team members! this source code from pyconjpbot https://github.com/pyconjp/pyconjpbot/blob/master/pyconjpbot/plugins/pluspl 59 / 63
  • 60. You can let a slackbot do anything else you can do with Python 60 / 63
  • 61. Let's hack your collaboration with Python ! 61 / 63
  • 62. References lins05/slackbot: A chat bot for Slack (https://slack.com). pyconjp/pyconjpbot: Slack bot for PyCon JP Slack 62 / 63