LINE Setup
Last updated
This page covers constructing the core/line bot, exposing its webhook, and the Input your handler receives.
Constructor and options
bot, err := line.New(channelSecret, channelAccessToken, "8080",
line.WithPath("/hooks/line"),
)
| Argument | Rule |
|---|---|
secret |
Channel secret; used to verify webhook signatures. Empty → secret is required |
token |
Channel access token. Empty → token is required |
port |
Listen port; the server binds :<port> on every interface. Empty → port is required |
WithPath(path) |
Webhook path; default /linebot/webhook. An empty path keeps the default |
New builds the client with the legacy linebot package of line-bot-sdk-go/v8 and does not start the server.
Public HTTPS endpoint
Unlike Telegram and Discord, LINE pushes events to you. Set the webhook URL in the LINE Developers Console to a public HTTPS address that forwards to http://<host>:<port><path>. For local testing use a tunnel such as ngrok.
Start(ctx) calls GetBotInfo to validate the token, binds the port synchronously (a port already in use is returned as an error), and serves in a goroutine.
Webhook handling
| Situation | HTTP response |
|---|---|
Signature check fails (ErrInvalidSignature) |
400 |
| Body cannot be parsed | 500 |
| Bot not running | 503 |
| Events handled | 200, after every event in the request has been processed |
Events in one request are handled one after another under a shared 30-second context. LINE expects a quick 200, so keep slow work out of the handler or move it to a goroutine and use Send afterwards.
Input
| Field | Content |
|---|---|
SourceType |
user, group, or room |
UserID / GroupID / RoomID |
Source IDs; set according to SourceType |
Username |
Sender's display name, fetched with GetProfile, GetGroupMemberProfile, or GetRoomMemberProfile; "" if the call fails or UserID is empty |
ReplyToken |
One-time reply token, already used by the automatic reply |
MessageID |
ID of the message (all types); pass it to Save for media |
MessageType |
text, image, video, audio, or file |
Text |
Text messages only |
FileName |
File messages only |
Raw |
*linebot.Event |
LINE events do not carry a display name, so each message costs one profile API call before the handler runs.