Skip to main content

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

  1. Receive an ActionExecutePayload containing ruleId, ruleName, actionType, actionConfig, sourceConfig, userId, lineOaId, organizationId, triggerDepth, workflowId, and workflowNodePath.
  2. Always check for a delay first — if actionConfig.delay is set, nothing runs now; ScheduleAction records the work into scheduled_action instead (see Delayed / Scheduled Actions).
  3. Dispatch on actionType.
actionTypeWhat it does
switch_rich_menuPublishes a setRichMenuByTriggerRule payload onto the line_change_richmenu queue
send_messagesendRichMessageToUser — loads the rich message, builds per-user tracking links, resolves merge tags, attaches quick replies, and pushes via LINE
advanced_send_messageSends a custom message through ResponseSenderService, reusing the same pipeline as AI responses
send_booking_linkSame logic as advanced_send_message, with bookingPayload as the merge tag source
add_to_audienceAdds the user to an audience by updating line_user.audience_ids, regenerating the CSV file if it is a manual audience
remove_from_audienceRemoves the user from an audience and regenerates the CSV
update_attributeUpdates a line_user column, or merges the value into the custom_attribute jsonb field
talk_to_agentForwards to mbox handoff, transferring the chat to a human agent
update_booking_statusUpdates a booking's status in the appointment schema
anything elseLogs a warning and returns an error, sending the message to the DLQ
  1. Tracking link generationcreateTriggerRedirectMappings wraps every URL and image in the message with a tracking link bound to ruleId and userId, so it is clear who clicked what from which workflow. appendGaIdentityParam appends GA parameters when the OA has enabled them.
  2. regenerateAudienceCsv — when a manual audience's membership changes, a fresh CSV is built and uploaded to S3 under a path of the form private/{lineOaHash}/audience/{filename}.csv, so the next multicast uses current data.
  3. 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 point
    • switchRichMenu(), sendRichMessageToUser(), handleAdvancedSendMessage(), handleTalkToAgent(), addToAudience(), removeFromAudience(), updateAttribute(), handleUpdateBookingStatus()
    • createTriggerRedirectMappings(), appendGaIdentityParam(), isManualAudience(), regenerateAudienceCsv(), buildAudienceCSV(), getLineUser()
  • internal/actionexecute/consumer.goConsumer.HandleActionExecute
  • internal/actionexecute/deps.go — the interface seam: MessageTransformer, ResponseSender, MboxHandoff, AudienceCsvStorage, RedirectClient, LineClientFactory
  • internal/actionexecute/scheduler.goActionSchedulerService, which records delayed actions
  • internal/actionexecute/payloads.go and internal/actionexecute/helpers.go
  • cmd/worker/integration.go — wiring for actionMessageTransformer, actionResponseSender, actionMboxHandoff, and actionCsvStorage, binding each to its real domain service
  • Queue: consumes action_execute and publishes line_change_richmenu (profile main)

Connections to Other Services

  • Receives jobs from: the Trigger / Workflow Automation Engine, Delayed / Scheduled Actions, and the booking event trigger
  • Tables: line_user (attributes and audience_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/push for message delivery, plus rich menu linking via the queue
  • Other services inside the worker: messagetrigger.ResponseSenderService for advanced and AI-driven messages, mbox.MboxHandoffService for agent handoff, and the linemessageapi transform utilities TransformMessageObjects, ResolveMergeTags, and ExtractUrls
  • The redirect service and campaignlink — used to build tracked URLs