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
- Receive a payload containing
lineOaId, published by the CMS when a user clicks "sync followers". - Load the OA. If its status is not
active, set the sync status tofailedwith the Thai-language message codeLOA_004and stop. - 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. - Page through
GET /v2/bot/followers/ids, 1,000 IDs per call, carrying the cursor forward in thestartparameter. - For each page, bulk INSERT into
line_userwith or-ignore semantics — existing rows are skipped rather than overwritten — attaching the OA'sorganization_idandline_oa_id. - Once the API stops returning a
nextcursor, set the sync status to COMPLETED and clear the Redis flag. - If an error occurs at any point, set the status to
failedand record an explanatory message.
Key Files & Functions
internal/lineoa/syncfollower.goService.ProcessLineSyncFollowerUser(ctx, payload)— the main flowinsertFollowerBatch()— bulk-inserts 1,000 IDs per roundupdateSyncFollowerStatus()— writes the status and log message back to the database
internal/lineoa/consumer.go—Consumer.HandleLineSyncFollowerUserinternal/lineoa/types.go—LineSyncFollowerUserPayloadand the status constantsSyncFollowerStatusProcessing,SyncFollowerStatusCompleted, andSyncFollowerStatusFailedinternal/line/audience.goandinternal/line/client.go—Client.GetFollowerIDs(ctx, baseURL, limit, start)- Queue:
line_sync_follower_user(runtime profilemain)
Connections to Other Services
- Job source — cms-api-go (line-oa domain), from the follower sync button.
- Database —
line_oa(sync status and access token) andline_user(bulk insert). - Redis — the key
LINE_OA:SYNC_FOLLOWER_USER_PROCESSING:<lineOaId>, whose prefix is configurable viaREDIS_KEY_SYNC_FOLLOWER_USER_PROCESSING. - LINE API —
GET /v2/bot/followers/idswith a limit of 1,000 and a cursor, against the base URL fromLINE_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.