Step 5: Send, receive, or import messages

Description

🚧

Please be aware that you won't be able to execute this step described above directly in the API Reference section due to tool limitations: it is not possible to calculate required headers and send a request simultaneously.

This method allows you to send incoming and outgoing messages, or import messages that were sent in a third-party application.

Example of a message

Example of a message

The method will generate a message and, if needed, the chat itself for the specified msgid and conversation_id.

Message typeUse caseParameters that should be passed
Incoming
from: client
A client sends a message to the connected channelOnly the payload[sender] field is filled in, the payload[receiver] field is not sent
Outgoing
from: Kommo user to: client
A manager writes a message to the client, we can identify who sends the messageThe fields payload[sender](information about the manager) and payload[receiver](information about the client) are filled in. A Kommo user ID is passed to payload[sender][ref_id].
Outgoing
from: integration bot
to: client
A manager writes a message to the client, we can't identify who sends the messageFields payload[sender] (information about the bot) and payload[receiver] (information about the client) are filled in.
The ID of the integration bot, which was received when registering the channel in the chat API, is passed to the payload[sender][ref_id] field.

Using this API method, you can bulk import old messages into a chat.

We recommend performing the import without notifications to managers or creating an incoming lead for all messages except the last one (the most recent).

To do this, you should pass the body parameter payload[silent] a true value for all messages except for the last one that passes the payload[silent] a false value. This way, an incoming lead will be created for the last message, and only one notification will come. Thus we will not create unnecessary disturbance for the user.

When importing messages from the integration bot, hooks are not sent.

Headers & Authorization type

ParameterData typeDescription
DatestringDate and time when the request was generated. The signature will be valid for 15 minutes from this Date. The date should be in the format “Thu, 01 Jan 2023 12:00:00 +0000” (RFC2822)
Content-typestringRequest data type. Currently, only application/json is supported.
Content-MD5stringFor the request body, it is necessary to calculate the MD5 hash and indicate it in the header in lowercase. At the same time, it is important to keep in mind that the request body is calculated as a stream of bytes without considering the end of JSON markup, and if there are “\n” or spaces at the end, they will also be taken into account.
X-SignaturestringSignature of the request as a string. It is formed from the name of the method (GET/POST) in uppercase, with the values of the headers concatenated by “\n”. Header values ​​come in a specific order. If there is no header, an empty string is specified instead. Next, add the requested path from the URL without the protocol and domain (without GET parameters) to the line. The resulting string is calculated using HMAC-SHA1, and as a secret, we use the channel secret obtained during registration. The resulting hash in lowercase is indicated in the X-Signature header.

Data type header when the request is successful/in case of an error

Content-Type: application/json

Response parameters

The method returns the amojo_id of the message that will appear in the chat feed when processed.

ParameterDate typeDescription
new_message[msgid]stringMessage ID in the Chats API
new_message[ref_id]stringChat ID on the integration side
Language