Skip to main content

Live Chat Callback Handling

Overview

Mbox, the live chat platform, sends webhooks back to report what is happening on the agent side: an agent replied, a conversation was created or closed, customer details were edited, and so on. This job is the consumer that processes those events in order to sync the state back into LINE Management.

It produces three main outcomes: extending the agent session, closing agent mode when a conversation is resolved, and syncing customer custom attributes edited in Mbox back into the line_user table.

Business Flow

The handler dispatches on the payload's event field; the payload itself arrives as an untyped map.

EventBehaviour
message_createdOnly outgoing messages matter — those are agent replies. The session is extended: the score in agent_sessions is updated, the conversation ID is stored in the hash, the team is assigned on the first callback, and warningSent is reset to 0.
conversation_createdBinds the conversation ID to the agent_mode key and resolves which OA this inbox belongs to.
conversation_status_changedIf the status becomes resolved, agent mode is closed: the agent_mode key is deleted, the member is removed from agent_sessions, and the closing message is pushed to the user over LINE.
contact_updatedPulls the custom attributes the agent edited in Mbox and merges them into line_user.custom_attribute with a prefix. The schema in attribute_master is created or updated automatically, with the data type inferred from the value.
conversation_updatedApplies the same treatment to conversation-level data, such as conversation custom attributes.
Anything elseNo action is taken and the message is acknowledged.

Additional details worth knowing:

  • resolveLineOaID maps an Mbox inbox back to a lineOaId via the Redis key mbox_inbox:<inboxId>, which is warmed during webhook processing.
  • inferDataType and parseableDate guess the type of a newly seen attribute — string, number, date or boolean — so the schema written to attribute_master is correct.
  • A payload that cannot be decoded is treated as a permanent failure and routed to the DLQ.

Key Files & Functions

FileResponsibility
internal/mbox/service_callback.goMboxCallbackService.ProcessCallback dispatches on event, backed by the handlers handleMessageCreated, handleConversationCreated, handleConversationStatusChanged, handleContactUpdated, handleConversationUpdated and the helpers assignTeam, ensureMboxAttributeMaster, resolveLineOaID, sendLineMessage, parseSchema, inferDataType, parseableDate, equalsNumber
internal/mbox/consumer.goConsumer.HandleMboxCallback
internal/mboxx/mboxx.goMbox REST client

Queue: mbox_callback on the cron-scheduler profile.

Connections to Other Services

  • Receives jobs from the endpoint that accepts Mbox webhooks on the webhook-go or client-api side, which republishes them onto the queue.
  • Redisagent_mode:<lineOaId>:<userId>, the agent_sessions sorted set, and mbox_inbox:<inboxId>.
  • Database tablesline_user (merging custom_attribute), attribute_master (attribute schema) and line_oa (token for pushing messages).
  • Mbox REST API — used to assign a team to a conversation.
  • LINE APIPOST /v2/bot/message/push for the conversation-ended notice.
  • Works together with Chat Handoff to Human Agents.