Last-activity Updates
Overview
The platform needs to know whether each user is still engaged — when they last did something, what kind of activity it was, and how long they have been quiet. That data feeds three places: segmentation (for conditions such as "inactive for more than 30 days"), the user list in the CMS, and the conditions of certain trigger rules.
This is a lightweight consumer whose only job is to update the last_activity_ fields on the line_user row. It is split into its own queue so that the database write never slows down the real-time paths that respond to the user.
Business Flow
- Receive a
LineUserActivityPayloadcontaininglineUserId,lineOaId,organizationId, and the activity type and status. ProcessLineUserLastActivitylooks up theline_userrow matching organizationId, lineOaId, and lineUserId.- Update four fields:
last_activity_type— the activity kind, such as message, follow, or clicklast_activity_status— active or inactivelast_activity_period— the bucket derived from the gap between activitieslast_activity_date— the current timestamp
- A Redis cache of the
line_userrow lives atLINE_USER:<lineUserId>and is read by other flows in the system. - The service handles its own errors — it logs and returns — so the handler always returns nil and acks every message. This matches the legacy behaviour: a metadata update should never leave messages stuck in the queue.
Key Files & Functions
internal/lineuser/service.goService.ProcessLineUserLastActivity(ctx, payload)— the main flowfindByLineUserId()— reads the Redis cache atLINE_USER:<id>first and falls back to the database. Note that it does not write the cache on a miss, matching the original source.moduleNameisLINE_USER, used as the Redis key prefix
internal/lineuser/consumer.go—Consumer.HandleTrackingLog, bound to theline_user_last_activityqueueinternal/lineuser/types.go— definesLineUserActivityPayload- Queue:
line_user_last_activity(runtime profilemain)
Connections to Other Services
- Job source —
line-management-webhook-go, plus the tracking and redirect paths that need to record activity without blocking their response. - Database — the
line_usertable, updatinglast_activity_type,last_activity_status,last_activity_period, andlast_activity_date. - Redis — the key
LINE_USER:<lineUserId>. - No LINE API calls.
- Downstream consumers of this data — audience filters in cms-api, attribute-based trigger rules, and the user reports in cms-web.