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
beproudbot slack移行
Search
altnight
April 20, 2015
Technology
960
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
beproudbot slack移行
connpass.com/event/12689/
altnight
April 20, 2015
Other Decks in Technology
See All in Technology
AIに賢く動いてもらうためのコンテキスト〜Snowflake女子会 vol.8
snowwmn0824
0
160
AIを活用するために決めた "やらないこと" - 価値に注目する / Not betting on AI
soudai
PRO
3
590
バイブコーディング時代のWebアプリ開発入門~Cloud Runで学ぶセキュアなビルドとデプロイ
waiwai2111
1
140
aws-iot-platform-architecture-use-cases.pdf
ma2shita
0
540
GoのInterface内部構造から学ぶ!最高パフォーマンスを出すコード設計
yappli_developers
1
270
研究開発部の紹介 / Sansan R&D Profile
sansan33
PRO
5
25k
Cloudflare Workers 向けアプリを C# で構築する ~WASM Native AOT への道~
nenonaninu
1
1.2k
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
12k
Slack上でインフラをトラブルシュートする! Agentic Platform Engineeringの第一歩
teru0x1
5
1.9k
地方移住と都心キャリアの両立は「金・時間・人」のリソースをフル活用すれば実現できる!〜Snowflake女子会 vol.8
snowwmn0824
0
100
現場で役立つ技術負債の効果的な返済方法
masuda220
PRO
11
5.1k
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
16
120k
Featured
See All Featured
The browser strikes back
jonoalderson
0
1.7k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
250
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
The Cult of Friendly URLs
andyhume
79
7k
New Earth Scene 8
popppiees
4
2.6k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
520
Utilizing Notion as your number one productivity tool
mfonobong
4
590
How to train your dragon (web standard)
notwaldorf
97
6.8k
A Soul's Torment
seathinner
8
3.6k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
330
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
550
My Coaching Mixtape
mlcsv
0
320
Transcript
beproudbot Slack移行 天下一bot武闘会 2015/04/17
目次 - はじめに - お前誰よ - 技術的なこと - 実装コード例 -
まとめ
お前誰よ - altnight - Python/Django - bot担当
Skypeつらい - 重い - 重い - 重い - 同期できないときがある -
落ちる - 固まる - 通知できない… - なんとなくイケてない…
Slackにしよう - Slackにすれば - 軽くて - 通知もできて - スニペットもはれて -
Integrationも便利で - なんかいろいろいい感じで最高では?
Slackに移行するには? - アカウントを調べて - 料金や制限を調べて - 必要な人を招待して - 部屋の命名規則などを決めて -
beproudbotを動くようにする <- ここの作業
概要 - Skypeで動作するbeproudbotをSlackでも動かす - 開発期間は1ヶ月弱(2014/07)
beproudbotの歴史 - 1枚のスクリプトだった - djangoアプリ化された - いろいろ機能が増えた - GJ機能を実装していた流れでSlack対応の実装をした
What is GJ機能 - 「GJ」なことがあったらインクリメント - デクリメントはなし - “altnight++ bot実装”
みたいにチャット上でカジュアルに行 う
What is GJ機能
What is GJ機能 - 雑談でも?
フレームワーク/ライブラリ - Python 2.7(将来Py3移行できるように) - Django 1.5(当時の最新版) - irc -
slacker
設計 - Djangoアプリで作成する - botの発言イベントの受け取りはircライブラリで行う - 受け取ったイベントメッセージのハンドラーを作る - Skype4Pyで動く既存実装を流用するため、Skype4Pyイベン トと互換性のあるオブジェクトを実装する
- 投稿はSlack APIを使用する
構成
構成
イベントの取得をどうする? - outgoingを経由しているプラグインは、プライベートグループ が多いので事実上使えない - -> hubotも使えない(かった) - 自前でポーリング実装する? -
Slack API access limit にひっかかるのでは?
イベントの取得をどうする? - SlackのIRC gateway接続でIRC接続部分を流用するのが一 番楽だった - 現在は RTM API あります
- https://api.slack.com/rtm
起動する beproudbot/beproudbot/ircbot/management/commands/runircbot.py logger.info('ircbot start command accepted') # connect to irc
client ssl_factory = irc.connection.Factory(wrapper=ssl.wrap_socket) connection_data = dict(connect_factory=ssl_factory) bot = IRCBot(settings.IRC_CHANNEL, settings.IRC_NICK, settings.IRC_SERVER, settings.IRC_PORT, settings.IRC_PASSWORD, **connection_data) # slack インスタンスをbotに紐付ける slack = slack_utils.get_slack(settings.SLACK_API_TOKEN) setattr(bot, '_slack_instance', slack) # 部屋名一覧をbotに紐付ける room_list = slack_utils.get_rooms(slack) setattr(bot, '_room_list', room_list) # ユーザー一覧をbotに紐付ける user_list = slack_utils.get_users(slack) setattr(bot, '_user_list', user_list) # bot.start の後に埋め込むとログが出ないため手前でロギングする logger.info('ircbot start successfully') # start try: bot.start() except Exception, e: logger.exception('ircbot exception') raise
Botインスタンスの作成 beproudbot/beproudbot/ircbot/bot.py class IRCBot(irc.bot.SingleServerIRCBot): def __init__(self, channel, nickname, server, port=6667,
password='', **connection_data): irc.bot.SingleServerIRCBot.__init__(self, [(server, port, password)], nickname, nickname, reconnection_interval=60, **connection_data) def make_message_event(self, event): """ IRCで送られてくるイベントからアプリで使う Messageイベントに変換する """ return Message(self, event.sender_unicode, event.body_unicode, event.target_unicode) def process_on_pubmsg(self, event): """ グループの発言を受け取って処理する """ msg = self.make_message_event(event) on_irc_message.dispatch(msg) def on_pubmsg(self, connection, event): """ チャンネル、グループメッセージが送られてきたときのフックポイント """ self.process_on_pubmsg(event)
ありがちなこと - アッ
Skype4Py互換オブジェクト作成 beproudbot/beproudbot/ircbot/handlers.py class Chat(object): def __init__(self, irc_instance, target): self._irc_instance =
irc_instance # 部屋ID self.Name = slack_utils.get_channel_id(target, self._room_list) # 部屋名 self.Topic = target def SendMessage(self, msg): post_message(self._slack_instance, self._target_name, msg, self._irc_instance)
Skype4Py互換オブジェクト作成 class Message(object): def __init__(self, irc_instance, who, body, target): self.Sender
= Sender(who) self.Body = body self.Chat = Chat(irc_instance, target) self.Timestamp = time.time()
Skype4Py互換オブジェクト作成 class Sender(object): def __init__(self, who): self.Handle = who self.FullName
= who self.Birthday = ''
イベントの伝播 beproudbot/beproudbot/ircbot/handlers.py class IRCHandler(object): def __init__(self): self.receivers = set() def
connect(self, receiver): self.receivers.add(receiver) def dispatch(self, message): for receiver in self.receivers: receiver(self, message, "RECEIVED") on_irc_message = IRCHandler()
既存コードのレシーバ接続 beproudbot/beproudbot/thx/skypebot.py on_message.connect(thx_receiver) on_irc_message.connect(thx_receiver)
いくつか改修して - GJデータ移行 - 部屋モデル作成 - DB migration - コマンドのPrefix変更(#
-> $)
動いた - ほっ
まとめ - 全体的にうまく動いていて一安心 - Slackよい