Bu eğitimde, php kullanarak gelen WhatsApp mesaj web kancalarını işlemek için bir sayfa oluşturacağız.
yerel kalkınma amaçları için bir tünel açma hizmeti gereklidir. Bu örnek kullanır ngrok
Ngrok'u buradan indirebilirsiniz: https://ngrok.com/download
Bu, sunucunun gövdeyi istekten log.txt
file .
The body contains the complete webhook information sent from Ultramsg API whatsapp instance.
$data = file_get_contents("php://input");
$event = json_decode($data, true);
if(isset($event)){
//Here, you now have event and can process them how you like e.g Add to the database or generate a response
$file = 'log.txt';
$data =json_encode($event)."\n";
file_put_contents($file, $data, FILE_APPEND | LOCK_EX);
}
Yukarıdaki örnek dosyayı webhook.php olarak kaydedin ve sunucunuza yükleyin Webhook URL'si :
http://your-server/webhook.php
Yukarıdaki örnek dosyayı yerel ana makinenize webhook.php olarak kaydedin ve webhook url'si :
http://localhost/webhook.php
ngrok'u başlat
ngrok http 80
Bundan sonra, bir görmelisiniz
*.ngrok.io URL.
Örneğin :
https://7647-115-83-121-164.ngrok.io
localhost ile değiştir
ngrok.io URL
Web kancası URL'si:
https://7647-115-83-121-164.ngrok.io/webhook.php
Webhook URL'nizi Örnek ayarlarına yapıştırın.
Web kancalarını şimdi alabilmelisiniz ve bunları şurada görebilirsiniz: log.txt
file .