Sending a chat message
POST https://secure.usedesk.com/uapi/chat/sendMessage
Warning. If you use the server version of Usedesk, you will have a different URL of methods. Check the URL for the API with our team — support@usedesk.com.
The method is intended to send a message to a chat client (widget, messenger or SDK). It gets the following parameters:
* — required fields
| Parameter |
Value |
| api_token* | Channel API token |
| chat_id* | Chat ID |
| user_id* | ID of the agent on whose behalf the message will be sent |
| text* |
Message Text Markup is not supported |
PHP request example
$data = array(
'api_token'=> 'e1cbe1c1c9d910ef2ae975215644cb53dd555de4',
'chat_id' => 675,
'user_id' => 27,
'text' => "Hello World",
);
$mch_api = curl_init();
curl_setopt($mch_api, CURLOPT_URL, 'https://secure.usedesk.com/uapi/chat/sendMessage');
curl_setopt($mch_api, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($mch_api, CURLOPT_RETURNTRANSFER, true);
curl_setopt($mch_api, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($mch_api, CURLOPT_TIMEOUT, 10);
curl_setopt($mch_api, CURLOPT_POST, true);
curl_setopt($mch_api, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($mch_api, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($mch_api);
return $result;
If the request is successful, the server will return the message about successful execution.
Example of a response from server
{
"status":"success"
}
Server response description
| Parameter | Description |
| chat_id | Chat ID |
| ticket_id | Request ID |