Computechsolution0

Test this app for free
22
import os
from flask import Flask, render_template, request
from twilio.rest import Client
from gunicorn.app.base import BaseApplication

app = Flask(__name__)

@app.route("/", methods=['GET'])
def home():
    twilio_account_sid = os.environ.get('TWILIO_ACCOUNT_SID', 'Not Set')
    twilio_auth_token = os.environ.get('TWILIO_AUTH_TOKEN', 'Not Set')
    
    return render_template('index.html', 
                           twilio_account_sid=twilio_account_sid if twilio_account_sid != 'Not Set' else None, 
                           twilio_auth_token=twilio_auth_token if twilio_auth_token != 'Not Set' else None)

@app.route("/wa", methods=['POST'])
def wa_hello():
    account_sid = os.environ.get('TWILIO_ACCOUNT_SID')
    auth_token = os.environ.get('TWILIO_AUTH_TOKEN')
    
    if not account_sid or not auth_token:
        return "Twilio credentials are not set. Please set them in the Env Secrets tab.", 200
Get full code

Created: | Last Updated:

Es una app de tecnología apto para todo público.

Here's a step-by-step guide for using the WhatsApp Bot template:

Introduction

This template provides a simple WhatsApp bot using Twilio's API. The bot sends a welcome message when a user sends a message to your Twilio WhatsApp number.

Getting Started

  1. Click "Start with this Template" to begin using this WhatsApp bot template in Lazy.

Initial Setup

To use this template, you'll need to set up a Twilio account and configure some environment variables:

  1. Sign up for a Twilio account at https://www.twilio.com if you haven't already.

  2. Once logged in, navigate to the Twilio Console to find your Account SID and Auth Token.

  3. In the Lazy Builder, go to the Environment Secrets tab and set the following variables:

  4. TWILIO_ACCOUNT_SID: Your Twilio Account SID
  5. TWILIO_AUTH_TOKEN: Your Twilio Auth Token

Test

After setting up the environment variables:

  1. Click the "Test" button in Lazy to deploy your WhatsApp bot.

Configuring Twilio

To connect your Twilio account with this bot:

  1. In the Twilio Console, navigate to the WhatsApp Sandbox.

  2. Set up your sandbox number if you haven't already.

  3. In the WhatsApp Sandbox settings, find the "When a message comes in" webhook URL field.

  4. After clicking "Test" in Lazy, you'll receive a dedicated server link. Set the webhook URL to: https://your-lazy-app-url.com/wa Replace your-lazy-app-url.com with the actual URL provided by Lazy.

Using the App

Once your bot is set up:

  1. Send a message to your Twilio WhatsApp Sandbox number.

  2. You should receive a welcome message in response: "Welcome to our WhatsApp Bot!"

Customizing the Bot

To customize the bot's response:

  1. In the Lazy Builder, locate the wa_hello() function in the main.py file.

  2. Modify the body parameter in the client.messages.create() method to change the welcome message.

  3. Click "Test" again to deploy your changes.

Remember, this is a basic template. You can expand its functionality by adding more complex logic, integrating with other services, or handling different types of user inputs.

Technologies

Flask Templates from Lazy AI – Boost Web App Development with Bootstrap, HTML, and Free Python Flask Flask Templates from Lazy AI – Boost Web App Development with Bootstrap, HTML, and Free Python Flask
Enhance Twilio Workflows with Lazy AI Templates: Automate SMS, Calls, WhatsApp, Notifications and More  Enhance Twilio Workflows with Lazy AI Templates: Automate SMS, Calls, WhatsApp, Notifications and More
WhatsApp Automation and Bots WhatsApp Automation and Bots

Similar templates

We found some blogs you might like...