Skip to main content

Rich Messages

Overview

A rich message is the message payload that gets sent out. It can combine several blocks in one set: text, images, video, Flex Messages, buttons, and links. This module is the library where reusable rich messages are stored, and its main consumers are campaign management and auto-response.

It supports uploading images and video via multipart/form-data, and provides an endpoint that generates a thumbnail from a video.

Business Flow

  1. GET /api/rich-message returns a paginated list shaped as {data, total}, scoped by lineOaId.
  2. GET /api/rich-message/find-all-object returns an object/dropdown shape and carries no policy annotation, matching the original TypeScript implementation.
  3. POST /api/rich-message accepts multipart/form-data to create a new entry:
    • Attachments are uploaded to object storage through the storage service.
    • Flex Messages are sent to LINE for validation via validateJsonFlexMessage; failure returns error RMS_002 (Failed to validate with LINE API).
    • A duplicate name returns error RMS_001 (Duplicate title).
  4. POST /api/rich-message/gen-thumbnail-video accepts form-data to upload a video and request a thumbnail. This is used when configuring a video block, since LINE requires a preview image.
  5. GET /api/rich-message/:id returns the detail view, and PUT /api/rich-message/:id updates it, also as form-data.
  6. DELETE /api/rich-message/:id soft-deletes, while DELETE /api/rich-message/:id/hard?confirm=true deletes permanently and is restricted to super admins.
  7. When a campaign is due to send, it reads this rich message, assembles the payload, and publishes it to RabbitMQ.

Key Files & Functions

The code lives in internal/modules/richmessage/, consisting of controller.go, service.go, responses.go, js.go, and dto.go.

MethodRouteHandlerPolicy (metadata)
GET/api/rich-messagect.findAllreadAll rich-message
GET/api/rich-message/find-all-objectct.findAllObject
GET/api/rich-message/:idct.findByIDread rich-message
POST/api/rich-messagect.createcreate rich-message
POST/api/rich-message/gen-thumbnail-videoct.genThumbnailVideoread rich-message
PUT/api/rich-message/:idct.updateupdate rich-message
DELETE/api/rich-message/:idct.deletedelete rich-message
DELETE/api/rich-message/:id/hardct.hardDeleteauth.SuperAdmin()

Every route is wrapped in modulegate.ModuleGate(d, "rich-message").

Connections to Other Services

  • PermissionsModuleGate("rich-message") is the guard that actually applies; PolicyModuleRichMessage is metadata only, and hard delete additionally requires auth.SuperAdmin().
  • Tablesrich_message, line_oa
  • Redis — caches both the list and the detail views, with keys and TTLs matching the original TypeScript implementation
  • Storage — holds images, video, and thumbnails
  • External — the LINE API for Flex Message validation
  • Consumers — campaign management, auto-response (which reads the rich_message table directly), and message templates
  • Error codesRMS_001 for a duplicate title, RMS_002 when LINE validation fails