Build Instant Lead Alerts with Twilio SMS

Instant lead alerts allow salespeople to close more deals by talking to interested customers moments after they are identified. In this tutorial, you will learn how to implement real-time lead alerts via SMS text messages.

You probably already have landing pages or product detail views in your web application which you're using to generate some excellent leads for your business.  Would you like to let the sales team know right away when you've got a new qualified lead?

In this tutorial, we'll use Twilio Programmable SMS to send a message when a new lead is found by implementing instant lead alerts for real estate. We'll create a landing page for a new house on the market and notify a real estate agent when a user requests more information.

Twilio customers like Trulia and ShowingTime use lead alerts in real estate, connecting agents to potential home buyers right after they register their interest in a property. Is real estate not your game? Use these same techniques in your own application to notify any type of sales professional when a new lead has been received by your system.

Loading Code Samples...
Language
from lead_alerts import app
from flask import flash, redirect, render_template, request
from twilio.base.exceptions import TwilioRestException


from .services.twilio_service import TwilioService

@app.route('/')
def index():
    house = {
                'title': '555 Sunnybrook Lane',
                'price': '$349,999',
                'description':
                    'You and your family will love this charming home. ' +
                    'Featuring granite appliances, stainless steel windows, and ' +
                    'high efficiency dual mud rooms, this joint is loaded to the max. ' +
                    'Motivated sellers have priced for a quick sale, act now!'
            }
    return render_template('index.html', house=house)

@app.route('/notifications', methods=['POST'])
def create():
    house_title = request.form["house_title"]
    name = request.form["name"]
    phone = request.form["phone"]
    message = request.form["message"]

    twilio_service = TwilioService()

    formatted_message = build_message(house_title, name, phone, message)
    try:
        twilio_service.send_message(formatted_message)
        flash('Thanks! An agent will be contacting you shortly', 'success')
    except TwilioRestException as e:
        print(e)
        flash('Oops! There was an error. Please try again.', 'danger')

    return redirect('/')

def build_message(house_title, name, phone, message):
    template = 'New lead received for {}. Call {} at {}. Message {}'
    return template.format(house_title, name, phone, message)
lead_alerts/views.py
Process a user-submitted form and send an SMS to the agent

lead_alerts/views.py

Find your language and framework of choice below to get to the source code in your language and follow step-by-step instructions to learn how to build instant SMS lead alerts yourself:

Happy building!

Kat King

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.

Loading Code Samples...
from lead_alerts import app
from flask import flash, redirect, render_template, request
from twilio.base.exceptions import TwilioRestException


from .services.twilio_service import TwilioService

@app.route('/')
def index():
    house = {
                'title': '555 Sunnybrook Lane',
                'price': '$349,999',
                'description':
                    'You and your family will love this charming home. ' +
                    'Featuring granite appliances, stainless steel windows, and ' +
                    'high efficiency dual mud rooms, this joint is loaded to the max. ' +
                    'Motivated sellers have priced for a quick sale, act now!'
            }
    return render_template('index.html', house=house)

@app.route('/notifications', methods=['POST'])
def create():
    house_title = request.form["house_title"]
    name = request.form["name"]
    phone = request.form["phone"]
    message = request.form["message"]

    twilio_service = TwilioService()

    formatted_message = build_message(house_title, name, phone, message)
    try:
        twilio_service.send_message(formatted_message)
        flash('Thanks! An agent will be contacting you shortly', 'success')
    except TwilioRestException as e:
        print(e)
        flash('Oops! There was an error. Please try again.', 'danger')

    return redirect('/')

def build_message(house_title, name, phone, message):
    template = 'New lead received for {}. Call {} at {}. Message {}'
    return template.format(house_title, name, phone, message)