百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
L

LineBotTemplate

> 编程语言
开源

一个简单的 Golang LINE 机器人模板以及如何在 Heroku 上设置 LINE 机器人 API 的教程

200 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个简单的 Golang LINE 机器人模板以及如何在 Heroku 上设置 LINE 机器人 API 的教程

LINE BotTemplate

A minimal Golang LINE Bot template built on the official line-bot-sdk-go v8. Clone it, deploy it, and you have a working LINE Bot in a few minutes.

What it does

  • Serves a /callback webhook endpoint and verifies the LINE signature
  • Echoes back any text message it receives
  • Replies with the sticker ID / resource type when it receives a sticker
  • Logs every incoming event so you can see the payload shape while developing

That is the whole app — one file, main.go, roughly 100 lines. It is meant to be read and then rewritten into your own bot.

Requirements

Go 1.25 or later
SDK github.com/line/line-bot-sdk-go/v8 v8.22.0

Environment variables

Both are required. You get them from the LINE Developers Console.

Name Where to find it
ChannelSecret Messaging API channel → Basic settings tab
ChannelAccessToken Messaging API channel → Messaging API tab → issue a long-lived token

PORT is optional and defaults to 5000. Most PaaS providers set it for you.

Getting started

1. Create a LINE Messaging API channel

  1. Sign in to the LINE Developers Console.
  2. Create a new Messaging API channel.
  3. Copy the Channel Secret from the Basic settings tab.
  4. Issue a Channel Access Token on the Messaging API tab.
  5. Open LINE Official Account Manager from the Basic settings tab, go to Response settings, and turn Webhook on (turn Auto-reply messages off, otherwise the OA replies before your bot does).

2. Deploy

Pick whichever platform you prefer.

Render

Render reads render.yaml. Fill in ChannelSecret and ChannelAccessToken when prompted.

Heroku

Heroku reads app.json and Procfile. Fill in the same two variables, and note the app name — you need it for the webhook URL.

3. Point LINE at your webhook

Back in the LINE Developers Console, set the Webhook URL to your deployment plus /callback:

https://.onrender.com/callback
https://.herokuapp.com/callback

Hit Verify. If it returns success, add the bot as a friend and send it a message.

Running locally

git clone https://github.com/kkdai/LineBotTemplate.git
cd LineBotTemplate

export ChannelSecret=
export ChannelAccessToken=

go run main.go
# http://localhost:5000/

LINE only calls HTTPS webhooks, so expose the local port with a tunnel:

ngrok http 5000

Then set the webhook URL to https://.ngrok-free.app/callback.

Making it your own

All the interesting code lives in the event loop in main.go:

for _, event := range cb.Events {
    switch e := event.(type) {
    case webhook.MessageEvent:
        switch message := e.Message.(type) {
        case webhook.TextMessageContent:
            // your logic here
        }
    }
}
  • Reply to different message types — add cases for webhook.ImageMessageContent, webhook.LocationMessageContent, webhook.AudioMessageContent, and so on.
  • Reply with something richer than text — swap messaging_api.TextMessage for StickerMessage, ImageMessage, FlexMessage, or TemplateMessage in the Messages slice.
  • Handle non-message events — webhook.FollowEvent, webhook.JoinEvent, webhook.PostbackEvent, and webhook.BeaconEvent are cases on the outer switch, alongside webhook.MessageEvent.
  • Push instead of reply — a reply token is single-use and short-lived; use bot.PushMessage when you need to message a user outside of a reply window.

See the Messaging API reference for the full surface.

Tutorials

  • Video: How to deploy LINE BotTemplate
  • Video: How to modify your LINE BotTemplate code
  • 中文教學:用 Golang 打造你的 LINE Bot

Inspired by

  • Golang (heroku) で LINE Bot 作ってみる
  • LINE BOT をとりあえずタダで Heroku で動かす
  • 阿美語萌典 BOT

Project52

It is one of my project 52.

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Issues· 1 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Gobot-apigolanggolang-linebot-templateheroku

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言