Developers

Build an Automated AI Pollster for the 2024 Election Cycle

Creating an AI Pollster with an Auto Dialer and AMD

Senior Escalations Engineer

Shane Harrell

Creating an AI Pollster with an Auto Dialer and AMD

With the 2024 US election cycle swinging into high gear, you can now use SignalWire to create an automated pollster using our AI Agent in conjunction with Answering Machine Detection (AMD).

SignalWire AI Agent is a powerful low-code tool that allows you to program a voice assistant in a drag-and-drop interface. However, you can use a little bit of extra code to build something more complex. The example below provides everything you need for a simple user interface, including all of the code necessary to add questions and participants into the poll, and the ability to review the poll results.

After all participants and questions have been added, an automated dialer will systematically call each contact and connect them with the AI pollster agent if the call is answered. With the help of AMD, if the call is answered by voicemail, the pollster will simply leave a message.

The AI then retrieves poll questions from the database, and is instructed to only ask questions that are provided to it. For the purposes of this example, the AI agent has been configured to only allow responses on a scale of 1 to 10.

Prerequisites

How to set up the AI pollster

Setting up the pollster agent can be broken down into three simple steps:

Step 1

Clone the following github, which contains all of the necessary code, including a simple configuration UI and a Dockerfile to easily create the environment for the application.

git clone https://github.com/shane-signalwire/sw_dialer_agent_docker

Step 2

Change into the directory, and then build the Docker container using the following commands:

NOTE: You will need your NGROK API token for this step.

cd sw_dialer_agent_docker
# Build the docker image
docker build -t ai_dailer_agent –build-arg “NGROK_AUTHTOKEN_ARG=<NGROK AUTH TOKEN>” .
# Run the container
docker run -p 8000:5000 ai_dialer_agent

Step 3

Now that the container is running, use a web browser to navigate to the UI to complete configuration of the dialer, poll targets, and poll questions.

In a web browser, navigate to

http://127.0.0.1:8000

Configure Dialer

In the UI shown below, fill out the information for your SignalWire Space URL, SignalWire Project ID, SignalWire API Token, and Caller ID Number.

The Caller ID number must be a SignalWire number, and will also be the number used for connecting to the AI Agent.

Save the dialer configuration. Then you can add poll participants and questions.


Poll Participants

Add the list of participants to be called by the dialer. Include first name, last name, and phone number for each contact.

Save each entry into the database before moving on to poll questions.


Poll Questions

Add questions for the participant to answer. For this example, these should be questions that can be answered on a scale of 1-10, with 10 being the most positive value.


When all participants and questions have been added, click on START POLL to start the dialer.


Behind the scenes

How do all of the pieces fit together? There are many separate SignalWire offerings working cohesively on the backend to make this whole application work.

The main web application is written in python using the flask module as a front end web server. The application serves both the frontend user interface, and handles the webhooks from SignalWire.

The webhooks dynamically generate the SignalWire Markup Language (SWML) for the main AI Agent prompt, and all of the functions used by the AI to conduct the survey.

A separate backend process controls the outbound dialer. This script uses the SignalWire RELAY SDK to create a websocket connection and generate the individual calls. When a call is answered, AMD is used to determine whether a human user has answered, or if the call went to voicemail.

Have questions as you start building with SignalWire? Bring them to our team of developers on our community Forum or Slack!

Related Articles