20
AWS×LINE×LINE BOT AWARDS

Aws x line x line bot awards

Embed Size (px)

Citation preview

Page 1: Aws x line x line bot awards

AWS×LINE×LINE BOT AWARDS

Page 2: Aws x line x line bot awards

About Me

• 平岡雅俊• Sonicmoov Co,. Ltd.• Web エンジニア歴 10 年• 休日は自宅で映画鑑賞なインドア派• 猫好き• 病弱

Page 3: Aws x line x line bot awards

About Sonicmoov

• BtoB & BtoC• Guile

• 動画広告配信プラットフォーム• https://www.guile.jp/

• Tonariwa• LINE BUSINESS CONNECT

• ONE STOP SOLUTION• 企画・デザインから開発、運用まで社内で内製する体制

• Sonicmoov LAB• https://lab.sonicmoov.com/

Page 4: Aws x line x line bot awards

LINE BOT AWARDS

• http://botawards.line.me/ja/• 誰でも参加可能• 優勝賞金 1000 万円!

Page 5: Aws x line x line bot awards

AWS で構築する LINE BOT

• システム構成• API Gateway• Queue + Job Worker

• アカウント設定• Messaging API

• Reply Message• Push Message• Template Message

Page 6: Aws x line x line bot awards

Systems Architecture

Page 7: Aws x line x line bot awards

Queue Server

Internet gateway

API Gateway

Worker Server

Page 8: Aws x line x line bot awards

Api Gateway

• Messaging API の Callback URL は https のみ• Let‘s Encrypt などでも可能だが、独自ドメインが必要• 無料利用枠でなら、最大 12 ヶ月、 100 万回 / 月の呼び出しが無料• Lambda ももちろん可能• 今回は Http Proxy として利用• X-Line-Signature の転送設定を忘れずに• https://gist.github.com/hirarin/30114ac0eb1186a27fc599f41946261a

Page 9: Aws x line x line bot awards

Queue + Job Worker

• https://github.com/wa0x6e/php-resque-ex• Queue Server で受け取った event を Redis にスタック

• 処理としては Queue を登録するだけなので高速• Worker Server で順次処理

• 時間のかかる処理 ( 外部 API 呼び出しなど ) をゆっくり行う• 処理結果からメッセージを構築して LINE へ投げる• Worker のプロセス数を上げれば並列処理でさらに快適

Page 10: Aws x line x line bot awards

Phalcon 3.0.1 + line-bot-sdk-php

• https://phalconphp.com/ja/• 爆速 PHP フレームワーク• PHP Extension として、 Zephir 言語で書かれている• remi リポジトリ経由で rpm が配布されています

• https://github.com/line/line-bot-sdk-php• LINE 社が提供している SDK• example に SlimFramework で組まれた EchoBot などもあり、参考になります

Page 11: Aws x line x line bot awards

Developer Trial

Page 12: Aws x line x line bot awards

アカウントの取得• https://business.line.me/ja/services/bot

• 上記サイトから登録してアカウントを発行• LINE Developer サイトで Webhook URL を設定

• AWS API Gateway の Endpoint を指定• Channel Access Token の発行• LINE@ MANAGER サイトで Webhook を有効化

Page 13: Aws x line x line bot awards

Messaging API

Page 14: Aws x line x line bot awards

Reply Message

• リクエスト内の Reply Token を利用することで無料でメッセージを送信可能• Reply Token には有効期限がある• Reply Token は 1 度だけ使うことができる

/** @var \LINE\LINEBot $bot */

$bot = $this->getDI()->get('bot');

$response = $bot->replyText(

$event->getReplyToken(),

' 位置情報を送ってね! ');

Page 15: Aws x line x line bot awards

Push Message

• Channel Access Token を利用するメッセージ送信• ユーザーからのメッセージがなくてもいつでも送信可能• 処理に時間がかかるような返信は Push Message で

/** @var \LINE\LINEBot $bot */

$bot = $this->getDI()->get('bot');

$response = $bot->pushMessage(

$event->getUserId(),

new TextMessageBuilder(' 付近に居酒屋はないようです '));

Page 16: Aws x line x line bot awards

Template Message

• 予め用意されたテンプレート形式でメッセージを送信する• Button• Confirm• Carousel• 今回は Carousel で店舗情報を表示

/** @var \LINE\LINEBot $bot */

$bot = $this->getDI()->get('bot');

$carouselTemplateBuilder = new CarouselTemplateBuilder($columns);

$multiMessageBuilder = new MultiMessageBuilder();

$response = $bot->pushMessage(

$event->getUserId(),

$multiMessageBuilder

->add(new TextMessageBuilder(' 近くに居酒屋を発見しました! ')) ->add(new TemplateMessageBuilder('alt text', $carouselTemplateBuilder)) ->add(new TextMessageBuilder('Powered by ぐるなび ')));

Page 17: Aws x line x line bot awards

DEMO

Page 18: Aws x line x line bot awards

居酒屋検索 BOT

位置情報を送信すると近くの居酒屋を探してくれます

https://github.com/hirarin/izakaya-bot

Page 19: Aws x line x line bot awards

最後にソニックムーブではエンジニアを募集しています!• 新しい技術が好き• インフラもアプリケーションもやりたい• 自分好みの環境を作りたい• 島根で働きたいそんなアナタ!ソニックムーブで一緒に切磋琢磨しませんか?

https://www.sonicmoov.com/recruit/

Page 20: Aws x line x line bot awards

ご清聴ありがとうございました