![Recibir mensajes con Api Oficial de WhatsApp en Laravel 1 RECIBIR DE WHATSAPP API WA LARAVEL](https://www.programadornovato.com/wp-content/uploads/2023/01/RECIBIR-DE-WHATSAPP-API-WA-LARAVEL-640x360.png)
Recibir mensajes con Api Oficial de WhatsApp en Laravel
En este tutorial aprenderemos a Recibir mensajes con Api Oficial de WhatsApp en Laravel , solo debemos seguir estos pasos:
Creamos una app en Facebook
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 2 Enviar mensajes con Api Oficial de WhatsApp en PHP](https://www.programadornovato.com/wp-content/uploads/2023/01/image-51.png)
O podemos aceder a este link Todas las apps – Meta for Developers (facebook.com)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 3 image 31](https://www.programadornovato.com/wp-content/uploads/2023/01/image-31-1024x361.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 4 image 32](https://www.programadornovato.com/wp-content/uploads/2023/01/image-32.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 5 image 33](https://www.programadornovato.com/wp-content/uploads/2023/01/image-33.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 6 image 34](https://www.programadornovato.com/wp-content/uploads/2023/01/image-34-1024x592.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 7 image 35](https://www.programadornovato.com/wp-content/uploads/2023/01/image-35-1024x699.png)
Configuramos el Api de WhatsApp
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 8 image 36](https://www.programadornovato.com/wp-content/uploads/2023/01/image-36-1024x671.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 9 image 37](https://www.programadornovato.com/wp-content/uploads/2023/01/image-37-1024x673.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 10 image 38](https://www.programadornovato.com/wp-content/uploads/2023/01/image-38-1024x678.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 11 image 49](https://www.programadornovato.com/wp-content/uploads/2023/01/image-49-1024x845.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 12 image 39](https://www.programadornovato.com/wp-content/uploads/2023/01/image-39-1024x748.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 13 image 40](https://www.programadornovato.com/wp-content/uploads/2023/01/image-40-1024x830.png)
En este tutorial aprenderemos a Enviar mensajes con Api Oficial de WhatsApp en PHP, solo debemos seguir estos pasos:
Creamos una app en Facebook
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 2 Enviar mensajes con Api Oficial de WhatsApp en PHP](https://www.programadornovato.com/wp-content/uploads/2023/01/image-51.png)
O podemos aceder a este link Todas las apps – Meta for Developers (facebook.com)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 3 image 31](https://www.programadornovato.com/wp-content/uploads/2023/01/image-31-1024x361.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 4 image 32](https://www.programadornovato.com/wp-content/uploads/2023/01/image-32.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 5 image 33](https://www.programadornovato.com/wp-content/uploads/2023/01/image-33.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 6 image 34](https://www.programadornovato.com/wp-content/uploads/2023/01/image-34-1024x592.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 7 image 35](https://www.programadornovato.com/wp-content/uploads/2023/01/image-35-1024x699.png)
Configuramos el Api de WhatsApp
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 8 image 36](https://www.programadornovato.com/wp-content/uploads/2023/01/image-36-1024x671.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 9 image 37](https://www.programadornovato.com/wp-content/uploads/2023/01/image-37-1024x673.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 10 image 38](https://www.programadornovato.com/wp-content/uploads/2023/01/image-38-1024x678.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 11 image 49](https://www.programadornovato.com/wp-content/uploads/2023/01/image-49-1024x845.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 12 image 39](https://www.programadornovato.com/wp-content/uploads/2023/01/image-39-1024x748.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 13 image 40](https://www.programadornovato.com/wp-content/uploads/2023/01/image-40-1024x830.png)
Creamos nuestro host
Creamos una cuenta gratuita en Hosting made for everyone | alwaysdata
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 26 image 69](https://www.programadornovato.com/wp-content/uploads/2023/01/image-69.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 27 image 70](https://www.programadornovato.com/wp-content/uploads/2023/01/image-70.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 28 image 71](https://www.programadornovato.com/wp-content/uploads/2023/01/image-71.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 29 image 102](https://www.programadornovato.com/wp-content/uploads/2023/01/image-102.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 30 image 103](https://www.programadornovato.com/wp-content/uploads/2023/01/image-103.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 31 image 74](https://www.programadornovato.com/wp-content/uploads/2023/01/image-74-1024x737.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 32 image 108](https://www.programadornovato.com/wp-content/uploads/2023/01/image-108-1024x737.png)
<?php // /www2/routes/web.php use Illuminate\Support\Facades\Route; use App\Http\Controllers\WaController; /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ Route::get('/', function () { return view('welcome'); }); Route::get('/webhook', [WaController::class,'webhook']); Route::post('/webhook', [WaController::class,'recibe']);
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 33 image 109](https://www.programadornovato.com/wp-content/uploads/2023/01/image-109-1024x837.png)
<?php // /www2/app/Http/Controllers/WaController.php namespace App\Http\Controllers; use Illuminate\Http\Request; class WaController extends Controller { /* * VERIFICACION DEL WEBHOOK */ public function webhook(){ //TOQUEN QUE QUERRAMOS PONER $token = 'HolaNovato'; //RETO QUE RECIBIREMOS DE FACEBOOK $hub_challenge = isset($_GET['hub_challenge']) ? $_GET['hub_challenge'] : ''; //TOQUEN DE VERIFICACION QUE RECIBIREMOS DE FACEBOOK $hub_verify_token = isset($_GET['hub_verify_token']) ? $_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 === $hub_verify_token) { echo $hub_challenge; exit; } } /* * RECEPCION DE MENSAJES */ public function recibe(){ //LEEMOS LOS DATOS ENVIADOS POR WHATSAPP $respuesta = file_get_contents("php://input"); //echo file_put_contents("text.txt", "Hola"); //SI NO HAY DATOS NOS SALIMOS if($respuesta==null){ exit; } //CONVERTIMOS EL JSON EN ARRAY DE PHP $respuesta = json_decode($respuesta, true); //EXTRAEMOS EL TELEFONO DEL ARRAY $mensaje="Telefono:".$respuesta['entry'][0]['changes'][0]['value']['messages'][0]['from']."\n"; //EXTRAEMOS EL MENSAJE DEL ARRAY $mensaje.="Mensaje:".$respuesta['entry'][0]['changes'][0]['value']['messages'][0]['text']['body']; //GUARDAMOS EL MENSAJE Y LA RESPUESTA EN EL ARCHIVO text.txt file_put_contents("text.txt", $mensaje); } }
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 34 image 110](https://www.programadornovato.com/wp-content/uploads/2023/01/image-110-1024x716.png)
<?php // /www2/app/Http/Middleware/VerifyCsrfToken.php namespace App\Http\Middleware; use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware; class VerifyCsrfToken extends Middleware { /** * The URIs that should be excluded from CSRF verification. * * @var array<int, string> */ protected $except = [ '/webhook' ]; }
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 35 image 111](https://www.programadornovato.com/wp-content/uploads/2023/01/image-111-1024x657.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 36 image 112](https://www.programadornovato.com/wp-content/uploads/2023/01/image-112.png)
![Recibir mensajes con Api Oficial de WhatsApp en Laravel 37 Recibir mensajes con Api Oficial de WhatsApp en Laravel](https://www.programadornovato.com/wp-content/uploads/2023/01/image-113-1024x596.png)