An easy linebot application work with SpringBoot, MongoDB and ngrok
這是一個具有基本回覆line訊息的linebot
Project is created with:
- Spring Boot version: 2.7.6
- ngrok
- MongoDB Altas
-
申請官方帳號:
- 進入LineDeveloper
- 登入或申請帳號後創建Provider
- 選擇選擇Create a line official account(choose Message API)
-
Clone該專案
git clone https://github.com/CoderLambTw/LineBot_Demo.git
-
設定linebot的channel-token及secret:
- Channel secret 在 LINE Developers 的 Basic settings 內
- Channel access token 在 LINE Developers 的 Messaging API 的最底下
- 取得後至專案中application.yml中進行修改
-
安裝ngrok至本機
- macOS User: 直接至終端機輸入
brew install --cask ngrok即可完成安裝 - windows User: 可至 ngrok 下載
- macOS User: 直接至終端機輸入
- Start spring boot application
- Start ngrok(windows使用者需先自行啓動ngrok.exe):
- 至終端機(command)輸入
ngrok http 9527 - 利用 ngrok 將本機Server (localhost) 發布到一個真實ip
- 使User傳送的訊息可以透過此ip, 再透過Line bot傳送到我們的Server
- 成功啓動後將 Forwarding 的 URL 複製 https://XXXXXXXX.ngrok.io 部分
- 登入 line developers tab,並選擇機器人
- 進入messaging API後將複製ngrok URL貼到webhook中並於後方加上
/callback
- 至終端機(command)輸入
- 按下webhookURL下方的Verify按鈕即可確認是否與本地server連通,如得到200的repsonse即可成功與機器人互動
- Demo Video
- 功能列表: [過往訊息、天氣、辨識貼圖事件、defaul message repsponse]