
Crear un ChatBot inteligente con WhatsApp en PHP (Gratis)
En este tutorial aprenderemos a crear un ChatBot inteligente con WhatsApp en PHP totalmente gratis y con la plataforma oficial de WhatsApp (WhatsApp cloud API). La ventaja que tenemos al trabajar con la plataforma oficial es que la informacion que recibiremos y enviaremos será completamente fiable. solo debemos seguir estos pasos:
Creamos una app en Facebook

O podemos aceder a este link Todas las apps – Meta for Developers (facebook.com)





Configuramos el Api de WhatsApp






Código de ChatBot inteligente con WhatsApp en PHP
Colocamos nuestro código en nuestro servidor local en nuestro caso C:\xampp\htdocs\ChatWA\index.php
<?php /* * VERIFICACION DEL WEBHOOK */ //TOQUEN QUE QUERRAMOS PONER $token = 'HolaNovato'; //RETO QUE RECIBIREMOS DE FACEBOOK $palabraReto = $_GET['hub_challenge']; //TOQUEN DE VERIFICACION QUE RECIBIREMOS DE FACEBOOK $tokenVerificacion = $_GET['hub_verify_token']; //SI EL TOKEN QUE GENERAMOS ES EL MISMO QUE NOS ENVIA FACEBOOK RETORNAMOS EL RETO PARA VALIDAR QUE SOMOS NOSOTROS if ($token === $tokenVerificacion) { echo $palabraReto; exit; } /* * RECEPCION DE MENSAJES */ //LEEMOS LOS DATOS ENVIADOS POR WHATSAPP $respuesta = file_get_contents("php://input"); //CONVERTIMOS EL JSON EN ARRAY DE PHP $respuesta = json_decode($respuesta, true); //EXTRAEMOS EL MENSAJE DEL ARRAY $mensaje=$respuesta['entry'][0]['changes'][0]['value']['messages'][0]['text']['body']; //EXTRAEMOS EL TELEFONO DEL ARRAY $telefonoCliente=$respuesta['entry'][0]['changes'][0]['value']['messages'][0]['from']; //EXTRAEMOS EL ID DE WHATSAPP DEL ARRAY $id=$respuesta['entry'][0]['changes'][0]['value']['messages'][0]['id']; //EXTRAEMOS EL TIEMPO DE WHATSAPP DEL ARRAY $timestamp=$respuesta['entry'][0]['changes'][0]['value']['messages'][0]['timestamp']; //SI HAY UN MENSAJE if($mensaje!=null){ file_put_contents("text.txt", $mensaje); }
Activamos un servidor ngrok





🔗 Codigo: programadornovato/ChatBotWA (github.com)