Skip to main content

LINE Official Account Management

Overview

The LINE OA is the tenant unit of this system — nearly every table is scoped by line_oa_id, which makes this module the backbone of the platform. It covers creating, updating, and deleting OAs, storing channel credentials (channel id, channel secret, access token), managing webhook URLs, configuring audience auto-refresh, configuring GA tracking, configuring inbound message handling, and integrating with the external mbox (live chat) system.

Most routes sit on the public group alongside JwtLoginAuth, because they must be callable before the token carries a lineOaId: the post-login OA picker has to fetch the list of OAs first.

Business Flow

Connecting an OA

  1. The user enters the channel id, channel secret, and access token, then calls POST /api/line-oa/get-oa-info. The system queries the LINE API to confirm the credentials work and pulls back the OA's name and picture for display.
  2. POST /api/line-oa creates the row in line_oa, checking the maxChannels quota via plan limits and generating a webhook_id and a line_oa_hash.
  3. The user copies the generated webhook URL into the LINE Developer Console. GET /api/line-oa/webhook/:webhookId provides the reverse lookup from webhook id to OA.
  4. PUT /api/line-oa/:id/regenerate-webhook issues a fresh webhook id if the old one leaks.

Day-to-day use

  1. GET /api/line-oa returns a paginated list shaped as {data, total, totalOverAll}.
  2. GET /api/line-oa/find-all-object, which has no guard at all, returns a dropdown, dropdown-group, or object shape depending on the ?format= query parameter.
  3. PUT /api/line-oa/:id updates the record and PUT /api/line-oa/:id/status enables or disables it.
  4. DELETE /api/line-oa/:id soft-deletes; DELETE /api/line-oa/:id/hard deletes permanently and requires a super admin plus the ?confirm= parameter.

Specialised settings

  1. Audience auto-refresh via GET /api/line-oa/:id/audience-refresh-settings and PUT /api/line-oa/:id/audience-refresh-settings, which control how the cron that refreshes this OA's audiences behaves.
  2. GA tracking via GET /api/line-oa/:id/ga-tracking-settings and PUT /api/line-oa/:id/ga-tracking-settings, storing the measurement id and API secret used to send events to Google Analytics.
  3. Message handling via PUT /api/line-oa/:id/message-handling, which selects whether inbound messages are picked up by auto-response, a workflow, or mbox.
  4. mbox via POST /api/line-oa/:id/mbox/test-connection (testing baseUrl, apiToken, and accountId) and GET /api/line-oa/:id/mbox/teams (fetching the team list to bind against).

OA access control, super admin only

  1. GET /api/line-oa/:id/user-access and PUT /api/line-oa/:id/user-access define who may access this OA, writing to user_line_oa. Unlike the ported routes, this pair sits on the authed group, because CLS must be populated before SuperAdmin() reads from it.

Key Files & Functions

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

MethodRouteHandlerGuard / Policy
GET/api/line-oact.findAllJwtLogin + readAll line-oa
GET/api/line-oa/find-all-objectct.findAllObjectno guard
GET/api/line-oa/:idct.findByIDJwtLogin + read
GET/api/line-oa/webhook/:webhookIdct.findByWebhookIDJwtLogin + read
POST/api/line-oact.createJwtLogin + create
POST/api/line-oa/get-oa-infoct.getOaInfo
POST/api/line-oa/validate-loginct.validateLogin
PUT/api/line-oa/:idct.updateJwtLogin + update
PUT/api/line-oa/:id/statusct.updateStatusJwtLogin + update
PUT/api/line-oa/:id/regenerate-webhookct.regenerateWebhookJwtLogin + update
GET / PUT/api/line-oa/:id/audience-refresh-settingsct.getAudienceRefreshSettings / ct.updateAudienceRefreshSettingsJwtLogin + read/update
GET / PUT/api/line-oa/:id/ga-tracking-settingsct.getGaTrackingSettings / ct.updateGaTrackingSettingsJwtLogin + read/update
PUT/api/line-oa/:id/message-handlingct.updateMessageHandlingJwtLogin + update
POST/api/line-oa/:id/mbox/test-connectionct.testMboxConnectionJwtLogin + update
GET/api/line-oa/:id/mbox/teamsct.getMboxTeamsJwtLogin + read
DELETE/api/line-oa/:idct.deleteJwtLogin + delete
DELETE/api/line-oa/:id/hardct.hardDeleteauth.SuperAdmin()
GET / PUT/api/line-oa/:id/user-accessct.getUserAccess / ct.updateUserAccessauthed + auth.SuperAdmin()

Connections to Other Services

  • Permissions — the PolicyModuleLineOa metadata is not yet enforced; the guards that actually apply are auth.SuperAdmin() on hard delete and on user-access.
  • Tablesline_oa, line_oa_app, user_line_oa, organization
  • Redis — caches OA records and LINE access tokens
  • RabbitMQ — publishes to the line_sync_follower_user queue when a follower sync is requested
  • External — the LINE Messaging API through internal/externals/lineapi, and the mbox system over HTTP
  • Cross-moduleplanlimits for the maxChannels quota, and auth.GenerateLineOaHash
  • Nearly every feature in the system depends on the lineOaId this module produces.