Reputation: 4268
I would like send an interactive message via php and chatwoot api. https://www.chatwoot.com/developers/api/#tag/Messages/operation/create-a-new-message-in-a-conversation
interactive message like type 1: https://www.chatwoot.com/docs/product/others/interactive-messages/#1-options
my php code:
$ch = curl_init("https://mydomain.de/api/v1/accounts/1/conversations/19/messages");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2TLS);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(
array(
"content" => "Hi",
"message_type" => "outgoing",
"content_type" => "input_select",
"content_attributes" => '{"items": [{ "title": "Option1", "value": "Option 1" }, { "title": "Option2", "value": "Option 2" }]}',
"private" => false
)
));
curl_setopt($ch, CURLOPT_HTTPHEADER,
array (
'api_access_token: XXX'
),
);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
echo '<pre>';
print_r($response);
echo '</pre>';
Response
Array
(
[error] => String does not have #dig method
)
I can send simple messages without problems. but this message I get when I tried to send interactive messages. where is my mistake?
Upvotes: 0
Views: 617
Reputation: 1
I had the same problem when using the unofficial typescript SDK -> "@figuro/chatwoot-sdk".
I did the same with Axios and it worked.
const response = await axios.post('https://HOST/api/v1/accounts/ACCOUNT_ID/conversations/CONVERSATION_ID/messages',
{
"content": "Select one of the items below",
"content_type": "input_select",
"content_attributes": {
"items": [
{ "title": "Option1", "value": "Option 1" },
{ "title": "Option2", "value": "Option 2" }
]
},
"private":false
},
{
headers: {
'Content-Type': 'application/json',
'api_access_token': 'YOUR TOKEN'
}
});
Sorry, I know you work in PHP. I assume your library does the parsing wrong. Try using another PHP library for sending the POST request.
Upvotes: 0