13
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【LINE Bot挑戦】子連れランチ難民を救いたい

Last updated at Posted at 2023-10-29

やってみよう

どうも、子育て真っ最中のワーママエンジニアです。
今回も、覚えたての知識を使ってプロトタイピング挑戦!
使ってみるのはLINE Bot(初挑戦~!)

やってみよう~

子連れでもOKのお店を探したい

子連れランチ・・そこには、高いハードルがある・・
「ベビーカーが入る広さのお店かな・・」
「キッズメニューあるかな・・」

良い感じのお店が見つかっても、子連れOKのお店でなければ、
世の親達は諦め、またイチからか探すのである・・

なんて、日々自分の悩みをどうにかしたいと思ったので、
手軽に子連れOKなお店を探してくれるLINE Botを作ってみることにしました!

まず始めるにあたっては以下を参考にしました。

使用したもの

  • Node-RED(FlowForge)
  • LINEmessagingAPI
  • グルメサーチAPI(ホットペッパー Webサービス)

完成したものがこちら

わぁ、動いてる~~(感動)

中身について

フローはこんな感じです
スクリーンショット 2023-10-29 155507.png

JSON形式のコードは以下

[{"id":"790d607f541e14c2","type":"tab","label":"子連れランチ","disabled":false,"info":"","env":[]},{"id":"183e6087438e6d31","type":"ReplyMessage","z":"790d607f541e14c2","name":"","replyMessage":"","credentials":{"channelSecret":"","channelAccessToken":""},"x":740,"y":140,"wires":[]},{"id":"be76a4f277acadfd","type":"Webhook","z":"790d607f541e14c2","name":"","url":"/webhook","x":100,"y":60,"wires":[["20bf2584a00a38a2"]]},{"id":"20bf2584a00a38a2","type":"switch","z":"790d607f541e14c2","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"和食","vt":"str"},{"t":"cont","v":"洋食","vt":"str"},{"t":"cont","v":"カフェ","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":130,"y":160,"wires":[["268b11a96f7cc8ec"],["6450c75c87be5c10"],["c4cdc4730f9d9b83"],["c266bc5b63acafef"]]},{"id":"c266bc5b63acafef","type":"template","z":"790d607f541e14c2","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"カテゴリを選択してね!","output":"str","x":420,"y":280,"wires":[["183e6087438e6d31"]]},{"id":"6450c75c87be5c10","type":"http request","z":"790d607f541e14c2","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"http://webservice.recruit.co.jp/hotpepper/gourmet/v1/?key=取得したAPIキー&large_area=Z011&keyword=%E3%81%8A%E5%AD%90%E6%A7%98&genre=G005&count=20&order=4&format=json","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":330,"y":140,"wires":[["ef437d24eed1fda9"]]},{"id":"c4cdc4730f9d9b83","type":"http request","z":"790d607f541e14c2","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"http://webservice.recruit.co.jp/hotpepper/gourmet/v1/?key=取得したAPIキー&large_area=Z011&keyword=%E3%81%8A%E5%AD%90%E6%A7%98&genre=G014&count=20&order=4&format=json","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":330,"y":180,"wires":[["1acc97f2c6207530"]]},{"id":"a3607268bc8fe7cd","type":"function","z":"790d607f541e14c2","name":"和食","func":"msg.num = Math.floor(Math.random() * msg.payload.results.shop.length);\nmsg.payload = 'おすすめはこちら! \\n' + msg.payload.results.shop[msg.num].name + ' \\n アクセス' + msg.payload.results.shop[msg.num].access + ' \\n ★' + msg.payload.results.shop[msg.num].child + ' \\n ' + msg.payload.results.shop[msg.num].urls.pc;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":80,"wires":[["183e6087438e6d31"]]},{"id":"268b11a96f7cc8ec","type":"http request","z":"790d607f541e14c2","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"http://webservice.recruit.co.jp/hotpepper/gourmet/v1/?key=取得したAPIキー&large_area=Z011&keyword=%E3%81%8A%E5%AD%90%E6%A7%98&genre=G004&count=10&order=4&format=json","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":330,"y":80,"wires":[["a3607268bc8fe7cd"]]},{"id":"ef437d24eed1fda9","type":"function","z":"790d607f541e14c2","name":"洋食","func":"msg.num = Math.floor(Math.random() * msg.payload.results.shop.length);\nmsg.payload = 'おすすめはこちら! \\n' + msg.payload.results.shop[msg.num].name + ' \\n アクセス' + msg.payload.results.shop[msg.num].access + ' \\n ★' + msg.payload.results.shop[msg.num].child + ' \\n ' + msg.payload.results.shop[msg.num].urls.pc;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":140,"wires":[["183e6087438e6d31"]]},{"id":"1acc97f2c6207530","type":"function","z":"790d607f541e14c2","name":"カフェ","func":"msg.num = Math.floor(Math.random() * msg.payload.results.shop.length);\nmsg.payload = 'おすすめはこちら! \\n' + msg.payload.results.shop[msg.num].name + ' \\n アクセス' + msg.payload.results.shop[msg.num].access + ' \\n ★' + msg.payload.results.shop[msg.num].child + ' \\n ' + msg.payload.results.shop[msg.num].urls.pc;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":180,"wires":[["183e6087438e6d31"]]}]

①ジャンルを分ける

image.png

まずジャンルは、「和食」「洋食」「カフェ」 に分けました。(要素を含めばOK)

送るメッセージはリッチメニューで作成
image.png

※ちなみに、どのジャンルも含まないものを送ると、以下のように出る仕様
中華.jpg

②API リクエスト

スクリーンショット 2023-10-29 180028.png

http://webservice.recruit.co.jp/hotpepper/gourmet/v1/?key=取得したAPIキー&large_area=Z011&keyword=%E3%81%8A%E5%AD%90%E6%A7%98&genre=G004&count=10&order=4&format=json

使ったのはリクルートが提供している「グルメサーチAPI」
検索クエリについては「こちら」を参照しました。(使うには、利用登録して、APIキー取得することが必要です!)
ここで上記の3つのジャンルを指定しています。
また、キーワードには 「お子様」 を指定。これで、お子様OKの店を抽出しています。

③結果を返信する

スクリーンショット 2023-10-29 180049.png

msg.num = Math.floor(Math.random() * msg.payload.results.shop.length);
msg.payload = 'おすすめはこちら! \n' + msg.payload.results.shop[msg.num].name + ' \n アクセス' + msg.payload.results.shop[msg.num].access + ' \n' + msg.payload.results.shop[msg.num].child + ' \n ' + msg.payload.results.shop[msg.num].urls.pc;
return msg;

取得したデータから、ランダムで1件返してくれるようにしてみました。
自分のこだわりですが、お店側が書いている、「お子様連れOK」の情報を出してくれるようにしてみました。
お店によってはここに、「お子様メニュー」とか「お子様椅子あり」とか書いてあったので、分かると助かる~!と思って。

作ってみて

まず、ちゃんと動いたことに感動・・!
初心者でもある程度のものが作れるので、LINE Bot楽しい~
(もちろん、簡単には出来ず、たくさん苦労はしました。)

今回はエリアを広く「東京」で指定してまったのですが、
本当は、こちらからエリアを指定して検索したり、
詳細な条件で絞ったりしてみたかったのですが、今回は断念・・
でも楽しかったのでもっと色々作ってみたくなりました!

最後まで読んでいただきありがとうございました!

参考記事

13
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?