Contact Sales

All fields are required

How to Build a Text Notifications Service | SignalWire
Developers

How to Build a Text Notifications Service

A comprehensive guide with code snippets.

Stack Engineer

Kevin Garabedian

Right now notifications services are hot! Whether as individual reminders for appointments with doctors or in large quantities to send advice to the inhabitants of a given area like information on school events, SMS notifications are helping all industries stay connected.

There have been platforms to do these things out there for a while, but never has it been quite so easy and quite so cost-effective to deliver this functionality as it is with SignalWire today!

In order to ‘put our money where our mouth is’ and demonstrate the ease with which a text notification system can be created from scratch (or, indeed, moved over from a legacy platform) to take advantage of the extremely disruptive pricing offered by SignalWire, I've created a snippet that can be used as a starting point for such an application.

We’re going to bring you a series of ‘How to’ pieces that will cover some of the main applications that SignalWire can be used to deliver, both in terms of an overview of what they are, how they work, and (crucially) some ‘get you going’ code.

Our aim is to allow you to see results fast, and to encourage you to develop the solutions you need by building up from the easy-to-follow examples we’ll give you!


Getting Started

You will need a machine with Python installed, the SignalWire SDK, a provisioned SignalWire phone number, and optionally Docker if you decide to run it in a container.

For this demo we will be using Python.


Methods and Endpoints
Endpoint: /text_inbound
Methods: GET OR POST
Endpoint to accept incoming text messages from SignalWire space.
Handles campaign subscriptions and removal requests
Endpoint: /broadcast_msg
Methods: GET OR POST
Send message to campaign subscribers by phrase and message.

Setup Your Environment File
  1. Copy from example.env and fill in your values
  2. Save new file called .env

Your file should look something like this:

## This is the full name of your SignalWire Space. e.g.: example.signalwire.com
SIGNALWIRE_SPACE=
# Your Project ID - you can find it on the `API` page in your Dashboard.
SIGNALWIRE_PROJECT=
# Your API token - you can generate one on the `API` page in your Dashboard
SIGNALWIRE_TOKEN=
# The phone number you'll be using for this Snippets. Must include the `+1` , e$
SIGNALWIRE_NUMBER=
# MailGun domain associated with your MailGun account
MAILGUN_DOMAIN=
# MailGun token associated with your MailGun Account
MAILGUN_API_TOKEN=
# Send Email From Address
EMAIL_FROM=info@yourdomain.com
# Send email to address for administrator notifications
EMAIL_TO=youremail@yourdomain.com
# Email subject for admin notifications
EMAIL_SUBJECT=Text Subscription Admin Notification

Setup Your Campaign File
  1. Edit campaign.json to suit your needs, the file is a json object, that can handle multiple campaigns.

Your file should look something like this:

[
  {
    "Id": "1",
    "Name": "signalwire-demo-1",
    "Phrases": [
      "signalwire"
    ],
    "Subscribers": [
    ]
  },
  {
    "Id": "2",
    "Name": "signalwire-demo-2",
    "Phrases": [
      "original"
    ],
    "Subscribers": [
    ]
  }
]

Setup Your Do Not Contact File
  1. Edit donotcontact.json to suit your needs, the file is a json object and is global. This has no entries by default.

Your file should look something like this

{
"DoNotContact": []
}

Build and Run on Docker

Let's get started!

  1. Use our pre-built image from Docker Hub
For Python:
docker pull signalwire/snippets-text-subscription:python

(or build your own image)

  1. Build your image
docker build -t snippets-text-subscription .

2. Run your image

docker run --publish 5000:5000 --env-file .env snippets-text-subscription

3. The application will run on port 5000


Build and Run Natively
1. Replace environment variables
2. From command line run, python3 app.py

More Documentation

Support

If you have any issues or want to engage further about this snippet, please open an issue on this repo or join our fantastic Slack community and chat with others in the SignalWire community!

If you need assistance or support with your SignalWire services please file a support ticket from your Dashboard.