Skip to main content

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

  1. The rich menu, campaign, and rich message modules call this service when a user hits publish.
  2. 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 (default https://api.line.me/v2) for /oauth/accessToken and /oauth/verify
    • LINE bot SDK v9, which uses fixed base URLs: https://api.line.me for the API and https://api-data.line.me for blobs
  3. Each OA's access token is cached in Redis so it does not have to be re-requested every time.
  4. The main functions other modules rely on:
    • callCreateRichMenuOnLineOA, setRichMenuImage, deleteRichMenu
    • linkRichMenuIdToUsers, setDefaultRichMenu
    • callCreateRichMenuAliasOnLineOA, callGetRichMenuAliasOnLineOA, callUpdateRichMenuAliasOnLineOA
    • getRichMenuImage and validateJsonFlexMessage
    • Layout and merge-tag helpers in layout.go, mergetag.go, and richmenu.go

Error-handling behaviour preserved from the original code

These details matter when debugging, because some errors are swallowed on purpose.

  • linkRichMenuIdToUsers — catches and calls JSON.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.

FileRole
service.goLineMessageApiService — talks to the LINE API and blob API
richmenu.goLineMessageApiRichMenuService — rich-menu-specific flows
layout.goComputes rich menu layout and tap areas
mergetag.goSubstitutes merge tags such as {{name}} in message bodies
controller.goRegisterRoutes is a no-op (0 routes)

Companion module internal/modules/lineapictl/controller.go:

MethodRouteHandler
GET/api/line-apigetProfile(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_oa to obtain channel_access_token.
  • Redis — caches the access token per OA.
  • EnvironmentLINE_ENDPOINT (default https://api.line.me/v2).
  • Callers — Rich Menu, Rich Message, and Campaign Management. The module also receives tracking.TrackingTokenService for generating tracking links.