I
I
IgorPlays2021-07-27 10:18:33
PHP
IgorPlays, 2021-07-27 10:18:33

How to send a message via wazzup api?

I took wazzup24 api from the docks, decided to test it, it doesn't show anything.
What's wrong here?

<?php
$apiKey = '**********************'; // Ключ авторизации интеграции по API
$defaultChannelId = '654bae5f-2981-41e1-8279-4cd6898511da';
$url = 'https://api.wazzup24.com/v2/send_message';
 
$curl = curl_init(); // Используем curl для запроса к Wazzup API
 
// Если в теле запроса не указан канал, то используем дефолтный
$channelId  = (empty($_POST['channel'])) ?  $defaultChannelId : $_POST['channel'];
$channelId  = $_POST['channel'];
$chatId = $_POST['contact'];
$chatType = $_POST['messenger_type'];
$text = $_POST['text'];
 
/**
* Тут может быть код для записи сообщения в БД
*/
 
// Формируем тело запроса
$post_data = json_encode(array(
   'channelId'=>$channelId,
   'chatId'=>$chatId,
   'chatType'=>$chatType,
   'text'=>$text
));
 
// Отправляем запрос в Wazzup
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
 'Authorization: Basic '. $apiKey,
 'Content-Type:application/json'
));
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS,$post_data);
 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
 
$server_response = curl_exec($curl);
$http_response_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
 
// Парсим ответ
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$header = substr($server_response, 0, $header_size);
 
if ($http_response_code != 201) {
 error_log($header);
} else {
 // Если все ок, то вернется guid отправленного сообщения
 $res = json_decode($header);
 $msg_guid = $res->messageId;
}
 
curl_close ($curl);
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kuznetsov, 2021-07-27
@dima9595

You use the function error_log()when you should have received some kind of response. I do not know what this function is and where it saves the data, but probably in some kind of log file.
Try to replace error_log()with the echooutput and if something outputs, then it remains only to display the answer correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question