Workflow Action Execution
Overview
Once the trigger engine has decided that "this customer meets the conditions, so this action must
run", the real work is handed to the action_execute queue, where ActionExecutorService
carries it out. This is the largest file in the project — around 1,200 lines — because it has to
support many action types, each touching a completely different part of the system.
Splitting this into its own queue cleanly separates rule evaluation, which is fast, from actual execution, which is slower and calls external APIs.
Business Flow
- Receive an
ActionExecutePayloadcontainingruleId,ruleName,actionType,actionConfig,sourceConfig,userId,lineOaId,organizationId,triggerDepth,workflowId, andworkflowNodePath. - Always check for a delay first — if
actionConfig.delayis set, nothing runs now;ScheduleActionrecords the work intoscheduled_actioninstead (see Delayed / Scheduled Actions). - Dispatch on
actionType.
actionType | What it does |
|---|---|
switch_rich_menu | Publishes a setRichMenuByTriggerRule payload onto the line_change_richmenu queue |
send_message | sendRichMessageToUser — loads the rich message, builds per-user tracking links, resolves merge tags, attaches quick replies, and pushes via LINE |
advanced_send_message | Sends a custom message through ResponseSenderService, reusing the same pipeline as AI responses |
send_booking_link | Same logic as advanced_send_message, with bookingPayload as the merge tag source |
add_to_audience | Adds the user to an audience by updating line_user.audience_ids, regenerating the CSV file if it is a manual audience |
remove_from_audience | Removes the user from an audience and regenerates the CSV |
update_attribute | Updates a line_user column, or merges the value into the custom_attribute jsonb field |
talk_to_agent | Forwards to mbox handoff, transferring the chat to a human agent |
update_booking_status | Updates a booking's status in the appointment schema |
| anything else | Logs a warning and returns an error, sending the message to the DLQ |
- Tracking link generation —
createTriggerRedirectMappingswraps every URL and image in the message with a tracking link bound toruleIdanduserId, so it is clear who clicked what from which workflow.appendGaIdentityParamappends GA parameters when the OA has enabled them. regenerateAudienceCsv— when a manual audience's membership changes, a fresh CSV is built and uploaded to S3 under a path of the formprivate/{lineOaHash}/audience/{filename}.csv, so the next multicast uses current data.- Errors are logged with their rule and user context, then returned upward so the mq layer can decide between retry and DLQ.
Key Files & Functions
internal/actionexecute/service.go(roughly 1,236 lines)ActionExecutorService.Execute(ctx, payload)— the main dispatch pointswitchRichMenu(),sendRichMessageToUser(),handleAdvancedSendMessage(),handleTalkToAgent(),addToAudience(),removeFromAudience(),updateAttribute(),handleUpdateBookingStatus()createTriggerRedirectMappings(),appendGaIdentityParam(),isManualAudience(),regenerateAudienceCsv(),buildAudienceCSV(),getLineUser()
internal/actionexecute/consumer.go—Consumer.HandleActionExecuteinternal/actionexecute/deps.go— the interface seam:MessageTransformer,ResponseSender,MboxHandoff,AudienceCsvStorage,RedirectClient,LineClientFactoryinternal/actionexecute/scheduler.go—ActionSchedulerService, which records delayed actionsinternal/actionexecute/payloads.goandinternal/actionexecute/helpers.gocmd/worker/integration.go— wiring foractionMessageTransformer,actionResponseSender,actionMboxHandoff, andactionCsvStorage, binding each to its real domain service- Queue: consumes
action_executeand publishesline_change_richmenu(profilemain)
Connections to Other Services
- Receives jobs from: the Trigger / Workflow Automation Engine, Delayed / Scheduled Actions, and the booking event trigger
- Tables:
line_user(attributes andaudience_ids),audience,rich_message,trigger_rule,line_oa,appointment.booking, and the quick reply tables - S3: writes regenerated audience CSV files
- LINE API:
POST /v2/bot/message/pushfor message delivery, plus rich menu linking via the queue - Other services inside the worker:
messagetrigger.ResponseSenderServicefor advanced and AI-driven messages,mbox.MboxHandoffServicefor agent handoff, and thelinemessageapitransform utilitiesTransformMessageObjects,ResolveMergeTags, andExtractUrls - The redirect service and campaignlink — used to build tracked URLs