LINE Messaging API Connector Layer
Overview
This module is the wrapper around the LINE Messaging API that other modules call whenever they need to talk to LINE for real. It covers creating and uploading rich menu images, linking rich menus to users, setting the default rich menu, validating Flex Messages, managing rich menu aliases, and requesting or verifying access tokens.
The module exposes no HTTP routes of its own. The controller in the original NestJS codebase was
entirely commented out, so RegisterRoutes is deliberately a no-op, annotated in cmd/api/modules.go
as having 0 routes.
A small companion module, lineapictl, exposes GET /api/line-api, which returns a mock profile.
That endpoint exists purely for testing and is not part of any business flow.
Business Flow
- The rich menu, campaign, and rich message modules call this service when a user hits publish.
- The service talks to LINE through two channels with different base URLs, preserved one-for-one
from the original TypeScript code.
- Direct axios calls to
LINE_ENDPOINT(defaulthttps://api.line.me/v2) for/oauth/accessTokenand/oauth/verify - LINE bot SDK v9, which uses fixed base URLs:
https://api.line.mefor the API andhttps://api-data.line.mefor blobs
- Direct axios calls to
- Each OA's access token is cached in Redis so it does not have to be re-requested every time.
- The main functions other modules rely on:
callCreateRichMenuOnLineOA,setRichMenuImage,deleteRichMenulinkRichMenuIdToUsers,setDefaultRichMenucallCreateRichMenuAliasOnLineOA,callGetRichMenuAliasOnLineOA,callUpdateRichMenuAliasOnLineOAgetRichMenuImageandvalidateJsonFlexMessage- Layout and merge-tag helpers in
layout.go,mergetag.go, andrichmenu.go
Error-handling behaviour preserved from the original code
These details matter when debugging, because some errors are swallowed on purpose.
linkRichMenuIdToUsers— catches and callsJSON.parse(error.body). A JSON body makes the error disappear silently, while a non-JSON body raises a brand-new error in its place.setDefaultRichMenu— swallows all errors and only logs them.getRichMenuImage— logs and returns undefined.callCreateRichMenuOnLineOA,setRichMenuImage,deleteRichMenu, and the alias get/update calls let errors propagate normally.callCreateRichMenuAliasOnLineOA— logs, then rethrows.
Key Files & Functions
The implementation lives in internal/modules/linemessageapi/, comprising service.go,
controller.go, richmenu.go, layout.go, mergetag.go, types.go, enums.go, util.go,
and jsutil.go.
| File | Role |
|---|---|
service.go | LineMessageApiService — talks to the LINE API and blob API |
richmenu.go | LineMessageApiRichMenuService — rich-menu-specific flows |
layout.go | Computes rich menu layout and tap areas |
mergetag.go | Substitutes merge tags such as {{name}} in message bodies |
controller.go | RegisterRoutes is a no-op (0 routes) |
Companion module internal/modules/lineapictl/controller.go:
| Method | Route | Handler |
|---|---|---|
| GET | /api/line-api | getProfile(c, d) — returns a mock profile; public |
The external client lives in internal/externals/lineapi/lineapi.go, with lineapi.Service
injected via Deps.LineAPI.
Connections to Other Services
- Permission — no routes, so no guards, apart from the public mock at
/api/line-api. - Tables — reads
line_oato obtainchannel_access_token. - Redis — caches the access token per OA.
- Environment —
LINE_ENDPOINT(defaulthttps://api.line.me/v2). - Callers — Rich Menu, Rich Message, and Campaign Management. The module also receives
tracking.TrackingTokenServicefor generating tracking links.