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
DiscordとLINEをPython+FastAPI+Dockerで連携させる
Search
マグロ隊長kinTV
July 22, 2023
Technology
490
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
DiscordとLINEをPython+FastAPI+Dockerで連携させる
linedbでの発表資料です。
Qiitaの記事はこちら。
https://qiita.com/maguro-alternative/items/6f57d4cc6c9923ba6a1d
マグロ隊長kinTV
July 22, 2023
More Decks by マグロ隊長kinTV
See All by マグロ隊長kinTV
C#未経験の僕がAIに読めるコードを書かせるまで
maguroalternative
0
410
感動を貰う側から与える側へ -アイドルマスターミリオンライブから学ぶCfPに挑むと言うこと-
maguroalternative
1
590
useEffectってなんで非推奨みたいなこと言われてるの?
maguroalternative
11
8.1k
React19.2のuseEffectEventを追う
maguroalternative
2
1.2k
UDDのススメ - 拡張版 -
maguroalternative
2
1.9k
遊戯王GX 丸藤兄弟から学ぶ成長
maguroalternative
1
230
UDDのすすめ
maguroalternative
0
1.5k
LINE Works Bot入門
maguroalternative
0
160
めぐろLT#21 今年一番の仕事の成果
maguroalternative
0
160
Other Decks in Technology
See All in Technology
素人でもできた!AIを使った短編小説創作入門
delhi09
PRO
0
310
Lint の層を組み直した話
bengo4com
3
310
Strands Decider 2BでAWSアップデートの目利きをしてみた
sato4mi
1
110
Flutter Webを「SDK」として配る — 50以上のゲームを支える埋め込みアーキテクチャ
masayukisuda
0
180
2026 Apache Flink Community Checkpoint
rmetzger
0
160
増え続けるプロダクトの品質をどう担保するか。ProductSpecとTypeScriptによる取り組み
joere
3
380
Consistency for mere mortals - A gentle guide to consistency
ufried
0
120
デザインレビューは自動化できるのか?─ Flutter × Figma で UI 品質保証を考える
techiro
2
790
Technical Project Manager の役割とやりがい、少しだけ AI
yoshiiryo1
0
590
リアクションエンジニア ― 小さなリアクションから、話しかけやすい組織をつくる ―
ryuguyana
1
130
WireGuard for Apache NuttX - Bringing Secure Remote Access to embedded Devices -
aki310ooooo
0
140
AWSを利用する上で知っておきたい名前解決の話 2026
nagisa53
2
320
Featured
See All Featured
Become a Pro
speakerdeck
PRO
31
6.3k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Building Applications with DynamoDB
mza
96
7.3k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.3k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
560
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
320
Code Review Best Practice
trishagee
74
20k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Utilizing Notion as your number one productivity tool
mfonobong
4
640
Transcript
DiscordとLINEを Python+FastAPI+Docker で連携させる マグロ
自己紹介 • 名前:マグロ • 所属:日本大学 学部四年 • スキル: • 勉強中:
Twitter:@sigumataityouda GitHub:maguro-alternative
背景 • 友達とゲームしながら通話するためDiscordでサーバを作った。 →初めての人が多く、混乱が生じる。 →LINEと連携させて、慣れてもらおう!
バージョン • これまで計4回のフルリメイクを行う。 今回はQiitaの記事にあるバージョン4を解説。 バージョン1:Glitch(Discord.js) とGAS(LINE) バージョン2:Railway(pycord)と GAS(LINE) バージョン3:Railwayに完全移行 バージョン4:FastAPIに移行
バージョン5:Postgresでのカスタマイズ 機能追加 今回は これ GitHubの はこれ
イメージ 複数でのサーバー運用を想 定
イメージ Discordからメッセージを送る と、送信元を解釈してLINEグ ループに送信
イメージ 同じようにLINEグループから のメッセージも解釈して Discordに送信
選定 • Python 3.10.7 • Railway • FastAPI • Discord.py+Pycord
• Docker • LINE Messaging API • LINE Notify
設計 • Railway上でDockerを展開、Pythonの実行環境を作成 • DiscordBotとFastAPIのアプリを並列実行 Bot アプリ サーバ
設計(LINEBot) FastAPIで立ち上げたサーバー をLINEAPIのWebhookに設定 https://....railway.app/line-bot
設計(LINEBot) テキスト、音声ファイル https://....railway.app/line-bot 画像 画像URL 動画 動画URL(限定公開) スタンプ情報 スタンプURL ライブラリなしでDiscordAPIを使用
して送信 画像はGyazoAPI、動画はYouTube Data APIでアップロードして共有
設計(DiscordBot) メッセージを読み取りLINEに送 信
設計(DiscordBot) 動画、音声はMessaging APIで 送信 テキスト、画像、スタンプは LINE Notifyで送信 1時間に1000件 の送信上限 1か月に200件の
送信上限
識別方法 • 環境変数を利用 • 以下のような2つのサーバーで運用を想定(LINEグループもそれぞれ存在) SERVER_A SERVER_B
識別方法 サーバー名を頭文字にし、対応す る環境変数を代入 .split(",")で名前を区切り、サーバーを分別 DiscordサーバーidからLINEBotに関するイン スタンスを作成 SERVER_A SERVER_AのLINEグループ SERVER_Aと判断 サーバid
メッセージ
識別方法 • LINEBotの署名を各サーバごとに行う。 • 一致したものからDiscordのインスタン スを作成。 SERVER_A SERVER_AのLINEグループ SERVER_Aと判断 body
識別方法 • 現在はトークンをWeb上で設定。
メンション、チャンネル指定 • LINE→Discordでは送信先チャンネルは環境変数で定める。 • だがLINE側からも指定したい。 • メンション機能も付けていたが、Discordの仕様変更により見直し。
メンション、チャンネル指定 • メッセージの先頭に「/チャンネル名 #channel」と表記することで変更可能。 • チャンネル一覧から同名のチャンネル を探し、idを取得、そこに投稿。 • 現在は送信先をデータベース で管理しており、Web上で変
更可能
ファイルの扱い • DiscordはCDN方式のため、httpsで参照可能。 • 一方、LINEはバイナリで扱われるため扱いが大変。 • どこかしらに保存して共有させる必要あり。
ファイルの扱い • それぞれのファイルに特化したストレージサービスを利用。 • 画像:Gyazo API • 動画:YouTube Data API
• 音声:Discord API • いずれも「multipart/form-data」でアップロード可能。
実行例 • Discord→LINE(テキスト、画像)
実行例 • Discord→LINE(動画、音声)
実行例 • LINE→Discord(テキスト、画像、動画)
実行例 • LINE→Discord(音声、スタンプ)
今後 • 現在WebUIでの制御を可能にしているが、サーバもフロントも同一のフルスタッ クアプリとして動かしている。 • フロントと分けるか検討中。
最後に • 連携してDiscordに勧誘しよう!!!!