Sending or withdrawing a reaction
POST /v2/origin/custom/{scope_id}/react
Description
The method allows you to send or remove a reaction from a specific message.
Restrictions
Requires Date, Content-Type, Content-MD5, X-Signature headers
Request header
Content-Type: application/json
Date: current time in RFC 2822 format (for example: Mon, 03 Oct 2020 15:11:21 +0000)
Content-MD5: md5 hash of the request body
X-Signature: HMAC-SHA1 code with a channel secret key
Body parameters
Parameter | Data type | Description |
---|---|---|
conversation_id | string | Chat ID on the integration side |
id | string | Message ID on the Kommo side. The field is required if the msgid field is not passed |
msgid | string | Message ID on the integration side. The field is required if the id field is not passed |
user[id] | string | ID of the user who has sent/removed the reaction on the integration side |
user[ref_id] | string | ID of the user who has sent/removed the reaction on the Kommo side. Required field when entering a reaction by the user of Kommo |
type | string | Action type: react, unreact |
emoji | string | Required field for the “react” type |
Request example
{
"conversation_id": "my_integration-8e3e7640-49af-4448-a2c6-d5a421f7f217",
"msgid": "fbd27636-0c4b-11ea-8d71-362b9e155667",
"user": {
"id": "my_int-1376265f-86df-4c49-a0c3-a4816df41af8"
},
"type": "react",
"emoji": "😍"
}
Data type header on success
Content-Type: application/json
Data type header on error
Content-Type: application/json
HTTP response codes
Response code | Condition |
---|---|
200 | Reaction is accepted for the processing |
404 | Message doesn’t exist |
403 | The request signature is incorrect |
400 | Incorrect data transmitted. Details are available in the response body |
Example of the response
If the information is successfully received, the method does not return a response.
Example of request implementation
<?php
$secret = '5a44c5dff55f3c15a4cce8d7c4cc27e207c7e189';
$method = 'POST';
$contentType = 'application/json';
$date = date(DateTimeInterface::RFC2822);
$path = '/v2/origin/custom/344a5002-f8ca-454d-af3d-396180102ac7_52e591f7-c98f-4255-8495-827210138c81/079e44fb-fc22-476b-9e8a-421b688ec53b/react';
$url = "https://amojo.kommo.com" . $path;
$body = [
'msgid' => '079e44fb-fc22-476b-9e8a-421b688ec53b',
'user' => [
'id' => 'my_int-1376265f-86df-4c49-a0c3-a4816df41af8',
],
'type' => 'react',
'emoji' => '😍'
];
$requestBody = json_encode($body);
$checkSum = md5($requestBody);
$str = implode("\n", [
strtoupper($method),
$checkSum,
$contentType,
$date,
$path,
]);
$signature = hash_hmac('sha1', $str, $secret);
$headers = [
'Date' => $date,
'Content-Type' => $contentType,
'Content-MD5' => strtolower($checkSum),
'X-Signature' => strtolower($signature),
];
$curlHeaders = [];
foreach ($headers as $name => $value) {
$curlHeaders[] = $name . ": " . $value;
}
echo $method . ' ' . $url . PHP_EOL;
foreach ($curlHeaders as $header) {
echo $header . PHP_EOL;
}
echo PHP_EOL . $requestBody . PHP_EOL;
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 5,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_POSTFIELDS => $requestBody,
CURLOPT_HTTPHEADER => $curlHeaders,
]);
$response = curl_exec($curl);
$err = curl_error($curl);
$info = curl_getinfo($curl);
curl_close($curl);
if ($err) {
$result = "cURL Error #:" . $err;
echo $result;
} else {
echo "Status: " . $info['http_code'] . PHP_EOL;
echo $response . PHP_EOL;
}