-1

This is my code for send Personal or custom messages from WhatsApp API

==================================

$token='654464645321813vbnj3hj5g3jg1j5g3j131j3ghj1';
$telefono = '44596565965';
$url = 'https://graph.facebook.com/v16.0/109571185362363/messages';


$mensaje=''
.'{'
.'"messaging_product": "whatsapp",' 
.'"recipient-type": "individual",'

.'"to": "'.$telefono.'",' 

.'"type":"text",'

.'"text": '
.'{'
.'"preview_url": "false",'
.'"body": ""hello this is Test"'
.'}' 

.'}';

$header = array("Authorization: Bearer " . $token, "Content-Type: application/json",);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POSTFIELDS, $mensaje);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = json_decode(curl_exec($curl), true);
print_r($response);
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
?>

================================

The problem is not send nothing, the code don´t show errors but not send message, if use tempates yes, but in this way no

The Result is this :

Array ( [messaging_product] => whatsapp [contacts] => Array ( [0] => Array ( [input] => 44596565965[wa_id] => 44596565965 ) ) [messages] => Array ( [0] => Array ( [id] => wamid.HBgLMzQ2MzI4Njc4NTgVAgARGBI1MUNBQUVGOTM3NkE1MjZFREIA ) ) )

I try all for find solution in the official API but don´t find nothing about this.

Jean
  • 13
  • 3
  • 1
    If the credentials/tokens you put in the question are real ones, you should change them asap. Don't put confidential information in your public question. What is the returned HTTP status code? – Daniel W. May 04 '23 at 16:19
  • Not real data, put as example not real – Jean May 04 '23 at 16:26
  • It appears that you have posted sensitive/private information. If that's the case, please reset your passwords and/or revoke API keys and tokens, as they are considered compromised when posted on the internet. – Samuel Liew May 04 '23 at 16:41
  • Not real data, i answer until, not real only example randon numbers and letters no more – Jean May 04 '23 at 16:46
  • refer to this answer https://stackoverflow.com/a/75856649/8987128 – turivishal May 04 '23 at 17:27
  • 1
    Does this answer your question? [WhatsappAPI - How to know if can send any message or just template messages](https://stackoverflow.com/questions/75850969/whatsappapi-how-to-know-if-can-send-any-message-or-just-template-messages) – turivishal May 04 '23 at 17:29

2 Answers2

0

Your JSON in $mensaje is not valid because of a quotation mark near

"body": ""
    hello this is Test "}} {
        "messaging_product": "whatsapp",

Use json_encode() instead of manually putting it together to avoid errors.

You need to check the returned HTTP status code!

Daniel W.
  • 31,164
  • 13
  • 93
  • 151
0

Before engaging in a conversation, it's essential to follow the initial template-based approach. As per the process, when you receive a WhatsApp message (WAM) from the recipient, your message status will be marked as "sent" but not "delivered" to the recipient. Conversations can only be initiated by businesses using pre-approved templates. Once the recipient responds, businesses can then proceed to send custom messages.

For more detailed information on this process, you can refer to the following link: WhatsApp Business API Pricing.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 03 '23 at 21:26