v0.5.0

LINE Setup

Last updated


This page covers constructing the core/line bot, exposing its webhook, and the Input your handler receives.

Constructor and options


  1. bot, err := line.New(channelSecret, channelAccessToken, "8080",
  2. line.WithPath("/hooks/line"),
  3. )

ArgumentRule
secretChannel secret; used to verify webhook signatures. Empty → secret is required
tokenChannel access token. Empty → token is required
portListen 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


SituationHTTP response
Signature check fails (ErrInvalidSignature)400
Body cannot be parsed500
Bot not running503
Events handled200, 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


FieldContent
SourceTypeuser, group, or room
UserID / GroupID / RoomIDSource IDs; set according to SourceType
UsernameSender's display name, fetched with GetProfile, GetGroupMemberProfile, or GetRoomMemberProfile; "" if the call fails or UserID is empty
ReplyTokenOne-time reply token; consumed by the automatic reply when the handler returns non-empty text
MessageIDID of the message (all types); pass it to Save for media
MessageTypetext, image, video, audio, or file
TextText messages only
FileNameFile 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.

中文