LoginSignup
8
5

More than 1 year has passed since last update.

enebularで作成したLINEのチャットボットをずっと使えるようにする方法

Last updated at Posted at 2022-03-07

はじめに

今までは、enebularで作成したものを継続的に使用するには、AWS、Herokuなどにデプロイする必要がありました。

それが、2022年2月28日から、その心配はなくなりました。
enebular上で作成したものを、少し手間を加えるだけで、継続的に使用することができるようになりました。

詳細はこちら
https://blog.enebular.com/function/apps-environment/

ということで、
本記事では、以前こちらの記事で作成したLINEのチャットボットで試してみます。

作るもの

フロー

[{"id":"2356a69b.eadcda","type":"http in","z":"5191bfdc.d823d","name":"","url":"/line","method":"post","upload":false,"swaggerDoc":"","x":80,"y":80,"wires":[["f9598acd.b16de8"]]},{"id":"709bcec.962fc3","type":"http response","z":"5191bfdc.d823d","name":"","statusCode":"","headers":{},"x":430,"y":160,"wires":[]},{"id":"9f4e6d76.837be","type":"http request","z":"5191bfdc.d823d","name":"(6)BOTの返信文をLINE へ送信","method":"POST","ret":"obj","paytoqs":false,"url":"https://api.line.me/v2/bot/message/reply","tls":"","persist":false,"proxy":"","authType":"basic","x":1010,"y":300,"wires":[["16da9f5d.0d18d1"]]},{"id":"40240fb1.87004","type":"http request","z":"5191bfdc.d823d","name":"(3-1)天気API","method":"GET","ret":"obj","paytoqs":false,"url":"https://www.jma.go.jp/bosai/forecast/data/overview_forecast/340000.json","tls":"","persist":false,"proxy":"","authType":"basic","x":410,"y":220,"wires":[["ba9f0f25.9b50e"]]},{"id":"6811e36f.8fca2c","type":"switch","z":"5191bfdc.d823d","name":"(2)分岐","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"天気","vt":"str"},{"t":"eq","v":"猫","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":160,"y":280,"wires":[["40240fb1.87004"],["cff255b7.29f7b8"],["25435a2.b30cca6"]]},{"id":"ba9f0f25.9b50e","type":"function","z":"5191bfdc.d823d","name":"(3-2)BOT文作成(天気)","func":"// 送信したい文字列をresultに退避させておく\nconst result = msg.payload;\n\n// LINEサーバーからの内容をpayloadに復元する\nmsg.payload = msg.line;\n\n// 返信メッセージをhttp requestの結果にする\nreplyMessage = result.text;\n\n\nvar post_request = {\n    \"headers\": {\n        \"content-type\": \"application/json; charset=UTF-8\",\n        \"Authorization\": \" Bearer \" +  msg.linetoken\n    },\n    \"payload\": {\n        \"replyToken\": msg.payload.events[0].replyToken,\n        \"messages\": [\n            {\n                \"type\": \"text\",\n                \"text\": replyMessage\n            }\n        ]\n    }\n};\n\nreturn post_request;","outputs":1,"noerr":0,"x":630,"y":220,"wires":[["9f4e6d76.837be"]]},{"id":"25435a2.b30cca6","type":"function","z":"5191bfdc.d823d","name":"(5)その他(オウム返し文作成)","func":"lineMessage = msg.line.events[0].message.text;\nreplyMessage = msg.line.events[0].message.text;\n\nvar post_request = {\n    \"headers\": {\n        \"content-type\": \"application/json; charset=UTF-8\",\n        \"Authorization\": \" Bearer \" + msg.linetoken\n    },\n    \"payload\": {\n        \"replyToken\": msg.line.events[0].replyToken,\n        \"messages\": [\n            {\n                \"type\": \"text\",\n                \"text\": replyMessage\n            }\n        ]\n    }\n};\n\nreturn post_request;","outputs":1,"noerr":0,"x":660,"y":400,"wires":[["9f4e6d76.837be"]]},{"id":"16da9f5d.0d18d1","type":"debug","z":"5191bfdc.d823d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":950,"y":500,"wires":[]},{"id":"cff255b7.29f7b8","type":"http request","z":"5191bfdc.d823d","name":"(4-1)猫API","method":"GET","ret":"obj","paytoqs":false,"url":"https://api.thecatapi.com/v1/images/search","tls":"","persist":false,"proxy":"","authType":"basic","x":410,"y":300,"wires":[["507ef313.5c2bbc"]]},{"id":"507ef313.5c2bbc","type":"function","z":"5191bfdc.d823d","name":"(4-2)BOT返信画像作成(猫)","func":"const result = msg.payload;\n\nmsg.payload = msg.line;\n\nreplyMessage = result[0].url;\n\nvar post_request = {\n    \"headers\": {\n        \"content-type\": \"application/json; charset=UTF-8\",\n        \"Authorization\": \" Bearer \" +  msg.linetoken\n    },\n    \"payload\": {\n        \"replyToken\": msg.payload.events[0].replyToken,\n        \"messages\": [\n            {\n                \"type\": \"image\",\n                \"originalContentUrl\": replyMessage,\n                \"previewImageUrl\": replyMessage\n            }\n        ]\n    }\n};\n\nreturn post_request;","outputs":1,"noerr":0,"x":650,"y":300,"wires":[["9f4e6d76.837be"]]},{"id":"f9598acd.b16de8","type":"function","z":"5191bfdc.d823d","name":"(1)LINE情報ゲット","func":"// LINEサーバーからの情報をmsg.lineに退避させる\nmsg.line = msg.payload;\n\n// msg.payloadに送信されたメッセージ本体を入れる\nmsg.payload = msg.payload.events[0].message.text;\n\n// msg.payloadにトークンを入れる\nmsg.linetoken = \"チャンネルアクセストークン\"\nreturn msg;","outputs":1,"noerr":0,"x":170,"y":160,"wires":[["6811e36f.8fca2c","709bcec.962fc3"]]}]

または、こちらからダウンロード
(ファイル名:flows1.json)
https://www.dropbox.com/s/wnajktd3w73qpmd/flows1.json?dl=0


実行環境構築

LCDP in / outノードのインポート

Discover Asset (以下のリンク先)へ 
https://enebular.com/discover/

こんな画面

Image from Gyazo

検索欄に lcdp-toolkit と入力し、プルダウンから名称を選択

Image from Gyazo

lcdp-toolkit(下画像右側)をクリック

Image from Gyazo

インポートをクリック
Image from Gyazo

インポートしたいプロジェクトを選んで「インポート」
Image from Gyazo

実行環境

アセット画面の「実行環境」をクリック

Image from Gyazo

「+」をクリック
Image from Gyazo

この画面になる。
Image from Gyazo

設定タグ > 設定を編集する

Image from Gyazo

HTTP トリガーを「ON」
パスを入力 (本件の場合 line )
「保存」をクリック
Image from Gyazo

少し経つと、こんな画面になる。
下画像の赤で囲ったURLが、LINE
LINE APIの webhook アドレスになる

Image from Gyazo

LINE Developer の webhook URL にペーストする。
Image from Gyazo

フロー画面の編集

LCDP ノードで囲う
Image from Gyazo

デプロイ!


実行環境デプロイ

次は実行環境でデプロイ!

Image from Gyazo

これで、enebular で作成した LINEのチャットボットがずっと使えます。



利用制限について

プランに応じた利用制限があります。

プロジェクト内に作成できる実行環境

・エンタープライズプランのプロジェクトの場合: 5
・トライアルプランのプロジェクトの場合: 2
フリープランのプロジェクトの場合: 2

月間当たりの利用上限

  • エンタープライズ
    HTTPリクエスト回数 3,000,000回
    実行時間 1000時間
    ログサイズ 5GB

-トライアルおよびフリー
HTTPリクエスト回数 50,000回
実行時間 24時間
ログサイズ 0.1GB

制限されても、次の月の1日1時頃(UTC時間)に制限は解除されます。


8
5
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
8
5