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.
| Event | Behaviour |
|---|---|
message_created | Only 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_created | Binds the conversation ID to the agent_mode key and resolves which OA this inbox belongs to. |
conversation_status_changed | If 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_updated | Pulls 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_updated | Applies the same treatment to conversation-level data, such as conversation custom attributes. |
| Anything else | No action is taken and the message is acknowledged. |
Additional details worth knowing:
resolveLineOaIDmaps an Mbox inbox back to alineOaIdvia the Redis keymbox_inbox:<inboxId>, which is warmed during webhook processing.inferDataTypeandparseableDateguess the type of a newly seen attribute — string, number, date or boolean — so the schema written toattribute_masteris correct.- A payload that cannot be decoded is treated as a permanent failure and routed to the DLQ.
Key Files & Functions
| File | Responsibility |
|---|---|
internal/mbox/service_callback.go | MboxCallbackService.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.go | Consumer.HandleMboxCallback |
internal/mboxx/mboxx.go | Mbox 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.
- Redis —
agent_mode:<lineOaId>:<userId>, theagent_sessionssorted set, andmbox_inbox:<inboxId>. - Database tables —
line_user(mergingcustom_attribute),attribute_master(attribute schema) andline_oa(token for pushing messages). - Mbox REST API — used to assign a team to a conversation.
- LINE API —
POST /v2/bot/message/pushfor the conversation-ended notice. - Works together with Chat Handoff to Human Agents.