![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 1 01. ChatBot python](https://www.programadornovato.com/wp-content/uploads/2023/01/01.-ChatBot-python-640x360.png)
Crear un ChatBot inteligente con WhatsApp en Python (Gratis)
En este tutorial aprenderemos a crear un ChatBot inteligente con WhatsApp en Python 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 información que recibiremos y enviaremos será completamente fiable. Solo debemos seguir estos pasos:
Creamos una app en Facebook
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 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)
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 3 image 31](https://www.programadornovato.com/wp-content/uploads/2023/01/image-31-1024x361.png)
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 4 image 32](https://www.programadornovato.com/wp-content/uploads/2023/01/image-32.png)
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 5 image 33](https://www.programadornovato.com/wp-content/uploads/2023/01/image-33.png)
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 6 image 34](https://www.programadornovato.com/wp-content/uploads/2023/01/image-34-1024x592.png)
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 7 image 35](https://www.programadornovato.com/wp-content/uploads/2023/01/image-35-1024x699.png)
Configuramos el Api de WhatsApp
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 8 image 36](https://www.programadornovato.com/wp-content/uploads/2023/01/image-36-1024x671.png)
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 9 image 37](https://www.programadornovato.com/wp-content/uploads/2023/01/image-37-1024x673.png)
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 10 image 38](https://www.programadornovato.com/wp-content/uploads/2023/01/image-38-1024x678.png)
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 11 image 49](https://www.programadornovato.com/wp-content/uploads/2023/01/image-49-1024x845.png)
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 12 image 39](https://www.programadornovato.com/wp-content/uploads/2023/01/image-39-1024x748.png)
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 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
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 14 image 69](https://www.programadornovato.com/wp-content/uploads/2023/01/image-69.png)
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 15 image 70](https://www.programadornovato.com/wp-content/uploads/2023/01/image-70.png)
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 16 image 71](https://www.programadornovato.com/wp-content/uploads/2023/01/image-71.png)
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 17 image 72](https://www.programadornovato.com/wp-content/uploads/2023/01/image-72.png)
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 18 image 73](https://www.programadornovato.com/wp-content/uploads/2023/01/image-73.png)
Subimos el código a nuestro host
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 19 image 74](https://www.programadornovato.com/wp-content/uploads/2023/01/image-74-1024x737.png)
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 20 image 75](https://www.programadornovato.com/wp-content/uploads/2023/01/image-75.png)
Codigo de ChatBot inteligente con WhatsApp en Python
#ChatBot inteligente con WhatsApp en Python from flask import Flask, jsonify, request app = Flask(__name__) #CUANDO RECIBAMOS LAS PETICIONES EN ESTA RUTA @app.route("/webhook/", methods=["POST", "GET"]) def webhook_whatsapp(): #SI HAY DATOS RECIBIDOS VIA GET if request.method == "GET": #SI EL TOKEN ES IGUAL AL QUE RECIBIMOS if request.args.get('hub.verify_token') == "HolaNovato": #ESCRIBIMOS EN EL NAVEGADOR EL VALOR DEL RETO RECIBIDO DESDE FACEBOOK return request.args.get('hub.challenge') else: #SI NO SON IGUALES RETORNAMOS UN MENSAJE DE ERROR return "Error de autentificacion." #RECIBIMOS TODOS LOS DATOS ENVIADO VIA JSON data=request.get_json() #EXTRAEMOS EL NUMERO DE TELEFONO Y EL MANSAJE telefonoCliente=data['entry'][0]['changes'][0]['value']['messages'][0]['from'] #EXTRAEMOS EL TELEFONO DEL CLIENTE mensaje=data['entry'][0]['changes'][0]['value']['messages'][0]['text']['body'] #EXTRAEMOS EL ID DE WHATSAPP DEL ARRAY idWA=data['entry'][0]['changes'][0]['value']['messages'][0]['id'] #EXTRAEMOS EL TIEMPO DE WHATSAPP DEL ARRAY timestamp=data['entry'][0]['changes'][0]['value']['messages'][0]['timestamp'] #ESCRIBIMOS EL NUMERO DE TELEFONO Y EL MENSAJE EN EL ARCHIVO TEXTO #SI HAY UN MENSAJE if mensaje is not None: f = open("texto.txt", "w") f.write(mensaje) f.close() #RETORNAMOS EL STATUS EN UN JSON return jsonify({"status": "success"}, 200) #INICIAMSO FLASK if __name__ == "__main__": app.run(debug=True)
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 21 image 76](https://www.programadornovato.com/wp-content/uploads/2023/01/image-76-1024x422.png)
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 22 image 47](https://www.programadornovato.com/wp-content/uploads/2023/01/image-47-1024x808.png)
![Crear un ChatBot inteligente con WhatsApp en Python (Gratis) 23 ChatBot inteligente con WhatsApp en Python](https://www.programadornovato.com/wp-content/uploads/2023/01/image-77-1024x485.png)