RetailCRM

Message Gateway: registering the module, the transport token, channel features and events.

The setup order #

The client key is needed only to register the module: after that the whole exchange uses the transport token the CRM issues itself.

StepWhereWhat
1CRMenable the Message Gateway integration
2CRMcreate an API key allowed to manage integration modules
3Dashboardenter the CRM address and the key, save
4we register the module, get the transport token and create the channel
5CRMcheck that the WidgetChat channel appeared in the Chats section

Channel features #

The channel declares to the CRM what it can do, and the interface adapts. We declare text, files and images with one attachment each, quoting, deletion and the delivered and read statuses. Orders and products are not declared: we cannot do them, and a declared feature would show the operator a button that does nothing.

The exchange #

The event arrives on an address like /retailcrm/hook/{clientId}. Transport events carry no signature, so authenticity rests on the random connection id in the address; it is also matched against the ClientId header.

MG sends an event for our own message too — those are dropped by the originator field, otherwise the reply would reach the visitor twice.

DirectionMethod or event
outboundPOST /api/transport/v1/messages, originator: customer
outboundPUT and DELETE /api/transport/v1/messages by our external_id
outboundPOST /api/transport/v1/files/upload_by_url for attachments
inboundmessage_sent: the manager's reply
inboundmessage_updated, message_deleted: edits

Limits #

The transport limit is 30 requests per second per token, above which 429 arrives. Such tasks are postponed and retried; edits and deletions are retried freely: they go by our external_id and do not duplicate anything.

Tested on a live RetailCRM (upsoft.retailcrm.ru).