Skip to main content

LINE OA Follower Sync

Overview

When a LINE OA is first connected to the platform, the line_user table is empty even though the account may already have hundreds of thousands of friends. This job pulls the complete follower list from the LINE Messaging API into line_user, so multicast delivery, segmentation, and reporting work immediately instead of waiting for followers to interact first.

Because it is a long-running job that pages through the list 1,000 IDs at a time, it maintains a sync status the CMS can surface as progress.

Business Flow

  1. Receive a payload containing lineOaId, published by the CMS when a user clicks "sync followers".
  2. Load the OA. If its status is not active, set the sync status to failed with the Thai-language message code LOA_004 and stop.
  3. Set the sync status to PROCESSING and write the Redis key LINE_OA:<REDIS_KEY_SYNC_FOLLOWER_USER_PROCESSING>:<lineOaId> as an in-progress flag.
  4. Page through GET /v2/bot/followers/ids, 1,000 IDs per call, carrying the cursor forward in the start parameter.
  5. For each page, bulk INSERT into line_user with or-ignore semantics — existing rows are skipped rather than overwritten — attaching the OA's organization_id and line_oa_id.
  6. Once the API stops returning a next cursor, set the sync status to COMPLETED and clear the Redis flag.
  7. If an error occurs at any point, set the status to failed and record an explanatory message.

Key Files & Functions

  • internal/lineoa/syncfollower.go
    • Service.ProcessLineSyncFollowerUser(ctx, payload) — the main flow
    • insertFollowerBatch() — bulk-inserts 1,000 IDs per round
    • updateSyncFollowerStatus() — writes the status and log message back to the database
  • internal/lineoa/consumer.goConsumer.HandleLineSyncFollowerUser
  • internal/lineoa/types.goLineSyncFollowerUserPayload and the status constants SyncFollowerStatusProcessing, SyncFollowerStatusCompleted, and SyncFollowerStatusFailed
  • internal/line/audience.go and internal/line/client.goClient.GetFollowerIDs(ctx, baseURL, limit, start)
  • Queue: line_sync_follower_user (runtime profile main)

Connections to Other Services

  • Job source — cms-api-go (line-oa domain), from the follower sync button.
  • Databaseline_oa (sync status and access token) and line_user (bulk insert).
  • Redis — the key LINE_OA:SYNC_FOLLOWER_USER_PROCESSING:<lineOaId>, whose prefix is configurable via REDIS_KEY_SYNC_FOLLOWER_USER_PROCESSING.
  • LINE APIGET /v2/bot/followers/ids with a limit of 1,000 and a cursor, against the base URL from LINE_ENDPOINT.
  • Limits of the imported data — synced users have no profile information (display name or picture) until they actually interact, or until it is filled in by the CSV user-list import.