Incomplete Whatsapp API message

Asked

Viewed 539 times

0

Good afternoon, I am developing a website and in it has a button to share a message to a certain contact, the problem is that this message is appearing incomplete. I used the Inspect Element on the site and the message is complete, but when testing the message both via Whatsapp Web, and by Smartphone it appears incomplete.

$destaque['share_whatsapp'] = "https://api.whatsapp.com/send?phone=55" . preg_replace("/[^0-9]/", "", $row_share['config_whatsapp']) . "&text=Olá, gostaria de conversar á respeito deste imóvel: https://" . $_SERVER['SERVER_NAME'] . "/imoveis.php?categoria=" . $destaque['imov_id_categ'] . "&imovel=" . $destaque['imov_id'] . "&galeria=" . $destaque['imov_id_galeria'];

How is it appearing in the source code of the site: inserir a descrição da imagem aqui

I thought the Whatsapp API would have some limitation regarding the number of characters, but removing some characters from the message still means the message is just "category".

  • Are you sending a link through the link itself? Look how crazy this is going to be. Search for text encoding before generating your URL dynamically.

2 answers

0

I have never used this api, but you may need to encode the url that is inside the api call (native PHP rawurlencode()), for example:

//Parâmetros
$row_share['Something is wrong_whatsapp'] = 123456789;
$destaque['server'] = 'localhost';
$destaque['imov_id_categ'] = 99;
$destaque['imov_id'] = 99;
$destaque['imov_id_galeria'] = 99;

//construção da url
$url = "Olá, gostaria de conversar á respeito deste imóvel: https://" .
    $destaque['server'] . "/imoveis.php?categoria=" .
    $destaque['imov_id_categ'] . "&imovel=" .
    $destaque['imov_id'] . "&galeria=" .
    $destaque['imov_id_galeria'];

// chamada na api, convertendo a url
$destaque['share_whatsapp'] = "https://api.whatsapp.com/send?phone=55" .
preg_replace("/[^0-9]/", "", $row_share['Something is wrong_whatsapp']) .
"&text=" . rawurlencode($url);

// resposta
echo $destaque['share_whatsapp'];

Will return this command: https://api.whatsapp.com/send?phone=55123456789&text=Ol%C3%A1%2C%20would like%20of%20talk%20%C3%A1%20respect%20this%20im%C3%B3vel%3A%20https%3A%2F%2Flocalhost%2Fimoveis.php%3Fcategory%3D99%26imovel%3D99%26galeria%3D99

See more about url here: http://php.net/manual/en/function.rawurlencode.php

I hope I helped. Let me know if it works. :)

0


Buddy, you need to close the Anchor tag. To use the Whats Api you need to open a URL, and like any URL, you need to encode the URL (URL Encode).

So in your case it would look like this, example below: (51) 99778-5300

$destaque['share_whatsapp'] = "https://api.whatsapp.com/send?phone=55" . preg_replace("/[^0-9]/", "", $row_share['config_whatsapp']) . "&text=Olá,%20gostaria%20de%20conversar%20á%20respeito%20deste%20imóvel:%20https://".$_SERVER['SERVER_NAME']."/imoveis.php?categoria=" . $destaque['imov_id_categ'] . "&imovel=" . $destaque['imov_id'] . "&galeria=" . $destaque['imov_id_galeria'];

In php you can use the urlencode function to encode the url.

I hope I’ve helped

Browser other questions tagged

You are not signed in. Login or sign up in order to post.