-
從零開始, 建立 Gradle 的 IntelljJ 專案, e.g., Building Java Projects with Gradle
-
從零開始, 建立 Spring Boot 的 IntelljJ 專案, e.g., Building a RESTful Web Service
-
從零開始, 建立簡易的 Line Bot, 只做訊息的回應 Ref., 並佈署到 Heroku Ref.
Heroku 的 Settings > Config Variables 中需要有 LINE_BOT_CHANNEL_SECRET 與 LINE_BOT_CHANNEL_TOKEN 這兩個變數的設定
-
使用 ngrok 將 Line Bot 的執行佈署到本機
可使用
./gradlew bootRun -Dline.bot.channelToken=YOUR_CHANNEL_TOKEN -Dline.bot.channelSecret=YOUR_CHANNEL_SECRET
執行程式 -
測試 IntelljJ 的 Debug 模式是否可直接使用在 Line Bot 專案上? 可以
-
測試 ngrok 提供的封包檢視功能
目前只看到由外部接收到的 Request 與對應的 Response 封包, 並沒看到自己對 Line API Server 發出的封包
-
查看執行 Line Bot 時, IntelliJ 的 Console 介面顯示的訊息有些什麼意義?
有紀錄對 Line API 操作的 Request 與 Response 封包訊息
Request 封包的訊息範例 :
--> POST https://api.line.me/v2/bot/message/reply http/1.1 ...... --> END POST (285-byte body)
Response 封包的訊息範例 :
<-- 200 OK https://api.line.me/v2/bot/message/reply (80ms) ...... <-- END HTTP (2-byte body)
-
測試 Group 裡是否也會 ECHO 其他使用者留的訊息? 會, 但並無法知道使用者的 ID
-
測試 Line Bot 如何藉由 RESTful API (GET) 主動送訊息給使用者
-
測試如何將 log4j 或其他 logging framework 導入 Spring Boot 的程式中
-
測試 Line Bot 如何藉由 RESTful API (POST) 主動送訊息給使用者? 使用 Spring Boot 建立 RESTful Web Service 接收 訊息 後, 再用 Push message API 丟訊息即可
-
Bot 加入 Group 後, 拿到的 Source 會是 Group 類型嗎? YES
-
重構 HelloWorld 的 Line Bot, 當被加入群組時, 會顯示群組 ID
-
測試 Messaging API 的各項功能
RequestMapping 的 Annotation 可同時支援 GET 與 POST, 若使用 postman 做測試時, 除了 Body 使用 form-data 外, Header 也要加上 X-Application-Context=application
-
測試其他 Messaging API 並重構目前的 HelloWorld 程式
-
測試 AWS 的自動佈署 (Boxfuse)
在 Heroku 裡的 LINE_BOT_CHANNEL_TOKEN 與 LINE_BOT_CHANNEL_SECRET 兩個系統變數改設置在 src/main/resources/line-bot.properties 的設定檔中, 但 Boxfuse 的 EC2 佈署需要自行到 AWS 上設定 HTTPS 協定
- Let a bot join a group
- Let the bot send any message to the group
-
- When an event is triggered, an HTTPS POST request is sent to the webhook URL.
- An Event : a user adds your account or sends a message
- The Webhook URL : e.g.,
https://<YOUR_HEROKU_APP_NAME>.herokuapp.com/callback- A Sample Event:
{ "events": [ { "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", "type": "message", "timestamp": 1462629479859, "source": { "type": "user", "userId": "U206d25c2ea6bd87c17655609a1c37cb8" }, "message": { "id": "325708", "type": "text", "text": "Hello, world" } } ] }
- A Join Event : your account joins a group or talk room.
- It conains the group's ID source.groupId.
- A Sample Event:
{ "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", "type": "join", "timestamp": 1462629479859, "source": { "type": "group", "groupId": "cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" } }
-
- Send messages to users, groups, and rooms at any time.
- Sample Codes :
- <to> : the ID returned via the webhook event of the source user, group, or room as the ID of the receiver
- <textMessage> : can be any of send message objects
TextMessage textMessage = new TextMessage("hello"); PushMessage pushMessage = new PushMessage( "<to>", textMessage ); Response<BotApiResponse> response = LineMessagingServiceBuilder .create("<channel access token>") .build() .pushMessage(pushMessage) .execute(); System.out.println(response.code() + " " + response.message());
- Messaging API
- Rate limits of API
- Line Business Center
- API References
- Line Developers
- Line Admins
- Channels
- Java SDK
- FAQ
- line-bot-api-v1
- Getting started with the Messaging API
- 在 Heroku 建立你自己的 Line 機器人
- Line BOT API
- 關於Linebot(2) - 新版Line@ Messaging API使用心得 (Line Bot v2)
- LINE BOT + Bluemix 打造你專屬的LINE機器人
- LineBot 與電影資訊
- Homepage
- Heroku Dashboard
- Free Quota
- Getting Started with Gradle on Heroku
- Set up:
heroku login
- Prepare the app:
git clone ...
- Deploy the app:
- Create an app on Heroku:
heroku create
- Deploy your code:
git push heroku master
- Ensure that at least one instance of the app is running:
heroku ps:scale web=1
- Open the website:
heroku open
- View logs:
heroku logs --tail
- Create an app on Heroku:
- Set up:
- Change Timezone of papertrail
-
其他備註:
- IntelliJ 需在 Setting 中指定 Gradle JVM 為 Java 1.8, 也可使用下列程式碼確認 Gradle 所使用的 Java Version
// Add in build.gradle println System.getProperty("java.home") System.exit(1)
-
build.gradle
相關設定說明:
- Spring 教學(1) - 從 Spring Boot 開始
- Working a Getting Started guide with IntelliJ IDEA
- Building a RESTful Web Service
- Spring Boot @ConfigurationProperties example
- Official Site
- Official Document
- 使用方式:
- 若 Spring Boot 執行的 Web 程式可用
localhost:8080
開始時, 則在 cmder 執行ngrok http 8080
後, 便會有 https://<A_RANDOM_NAME>.ngrok.io/ 外部網址可以使用 - 可使用此網址 http://localhost:4040/inspect/http 查看對上述網址 Request 的封包
- 若 Spring Boot 執行的 Web 程式可用
-
build.gradle 需要新增的程式碼:
buildscript { repositories { maven { url 'http://files.boxfuse.com' } } dependencies { classpath "com.boxfuse.client:boxfuse-gradle-plugin:1.24.1.1219" } } apply plugin: 'boxfuse'
-
Gradle 執行的指令:
build boxfuseRun -info build boxfuseRun -Dboxfuse.env=prod -i
- the Tomcat servlet container
- bean
- REST
- Line Beacon
- Autowired