Skip to main content

Template Messages

Overview

Template Message is a library of ready-made messages that you author once and reuse across multiple channels. Its defining feature is the merge tag system: placeholders that are resolved per recipient at send time, such as the recipient's name, loyalty points, or the value of a custom attribute defined by the organisation.

Beyond plain text, the module supports a Card Builder that accepts an uploaded hero image. The number of templates an organisation may create is capped by the maxTemplates quota attached to its plan.

Business Flow

  1. The template management screen calls GET /api/template-message to list templates with pagination, scoped to the current user's lineOaId.
  2. While editing content, the editor calls GET /api/template-message/merge-tags to fetch the available merge tags. The response combines system tags (name, LINE display name, and so on) with tags derived from the OA's Attribute Master. The showSystem parameter controls whether system tags are included.
  3. New templates are created through POST /api/template-message (multipart/form-data). The service verifies the maxTemplates quota and checks for a duplicate name before saving; exceeding the quota returns an error.
  4. Card Builder hero images are uploaded via POST /api/template-message/upload-image. Because this is a static path, it is registered ahead of /:id so routing resolves to the correct handler.
  5. Other modules that need a picker call GET /api/template-message/find-all-object.
  6. Standard detail, edit, and delete operations use GET /api/template-message/:id, PUT /api/template-message/:id (form-data), and DELETE /api/template-message/:id.
  7. At actual send time — from a campaign, an auto-response, or a workflow — merge tags are substituted by linemessageapi/mergetag.go while the outbound payload is assembled.

Key Files & Functions

Core code lives in internal/modules/templatemessage/, comprising controller.go, service.go, and dto.go.

MethodRouteHandlerPolicy (metadata)
GET/api/template-messagect.findAllread template-message
GET/api/template-message/merge-tagsct.getMergeTagsread template-message
GET/api/template-message/find-all-objectct.findAllObject
GET/api/template-message/:idct.findOneread template-message
POST/api/template-messagect.createcreate template-message
POST/api/template-message/upload-imagect.uploadImagecreate template-message
PUT/api/template-message/:idct.updateupdate template-message
DELETE/api/template-message/:idct.deletedelete template-message

Every route is wrapped by modulegate.ModuleGate(d, "template-message").

Connections to Other Services

  • Access control — requests must pass ModuleGate("template-message"); PolicyModuleTemplateMessage is declared as per-handler metadata.
  • Tablestemplate_message, attribute_master, system_attribute, line_oa
  • Redis — caches both the list view and individual template details.
  • Storage Service — stores hero images uploaded through the Card Builder.
  • Cross-moduleplanlimits for the maxTemplates quota, and auth for user context.
  • Related modules — Attribute Master (the source of merge tags), Campaign Management, Auto Response, and the LINE Message API (which performs merge tag substitution on send).