- Create a simple Line Bot that can receive and push messages.
- Messages received are stored in MongoDB.
-
Install ngrok (for macOS users)
brew install --cask ngrok
用途: 使用ngrok,把外界的請求轉發到你的local
- Start MongoDB container:
make up
Make sure you already registered on LINE developer console.
- Create new
Messaging Channel
- Get
Channel Secret
on "Basic Setting" tab. - Issue
Channel Access Token
on "Messaging API" tab. - Open LINE Official Account Manager from "Basic Setting" tab.
- Go to Reply setting on LINE Official Account Manager, enable "webhook"
-
Clone this project
# Move to your workspace cd your-workspace # Clone this project into your workspace git clone git@github.com:karenchuu/go-linebot.git # Move to the project root directory cd go-linebot
-
Modify the configuration
config/config.yaml
linebot.channelSecret
andlinebot.channelAccessToken
must be changed to the data obtained from the LINE Developer Console.
-
Run server:
go run main.go ngrok http 8080
-
Go to Messaging API on LINE Official Account Manager, input webhookurl. for example:
https://{{YOUR NGROK URL}}/linecallback
.
├── config
│ ├── config.yaml
├── db
│ └── mongo.go
├── docker-entrypoint-initdb.d
│ └── mongo-init.js
├── internal
│ ├── api
│ └── models
├── docker-compose.yaml
├── go.mod
├── go.sum
├── main.go
├── Makefile
├── main.go
Test receiving Line Bot messages and pushing messages.