What are we gonna build?

A well functioning switchboard many of us take for granted. Wouldn’t it be nice to be able to adjust it after your growing or flexible day-to-day needs?

You have one customer facing number that everyone can call in to. The people that can take incoming calls have opted-in via SMS, can opt-out when needed during the day. The switchboard will automatically opt-out everyone out and switch over to an audio recording at the end of the business day and during weekends.

If your company after some time grows, it’s easy to add new co-workers to your switchboard so that you are several that are ready to help any of your customers 🛠

Getting started

To follow along with this tutorial, you need the following:

  1. A 46elks account.

  2. A virtual number with voice & SMS capabilities
  3. A public server on which you can run python code.
    If you don't have a public server yet you can set up a temporary ngrok link just to be able to follow along.

Configure the switchboard

Before we configure our switchboard, let's download the project's source code. You will see a structure like this:


      

Let's open app.py.

  1. We are gonna define our base url in the variable baseurl. In this example we'll use the value https://46elks.com and you should change this to your own domain. When we have entered the value it will look something like this.

    
              
  2. If no one is available to answer, the call will be passed on to the answering machine. In this case we have set up the answering machine so that it’s an audio file that will play a message for the caller.

    
              
  3. Save and close the file.

Now we'll define which numbers we want to be able to receive the incoming calls in our switchboard.

  1. Open the file users.txt and add each number on a new row, like so:

    
              
  2. Save and close the file.

Set up a virtual number

  1. Now that our code is done we need to do the last important step; Get the actual phone number our customers are gonna call.

    We have a short tutorial for getting a virtual phone number. Follow that one and come back here. The number you get must have both voice and sms capabilities.

  2. When you have a virtual number, let's configure it to receive incoming calls. We have a tutorial for configuring voice_start. The value you enter should be your base url + /incommingCalls, so it will look something like this https://46elks.com/incommingCalls.

  3. The last thing is to configure our number to also be able to receive incoming SMS. This time we'll configure sms_url. The value you enter should be your base url + /sms, and then look something like this https://46elks.com/sms.

You have now completed the phone number configuration. Well done 🥳

Run the code

To get our code running on our server we are gonna use Flask. Flask is a framework for building web applications with Python.
If you never have worked with Flask before we have a tutorial for setting it up. Follow that and come back here.

Besides Flask, we also need to install a module called Flask-APScheduler on our server. You install it by typing the following command in the terminal:


    

Now, let's run flask:


    

Opt-in and opt-out

To let the system know whether you are available or not you need to be able to opt-in and opt-out somehow.
To do this you simply send a SMS to your virtual number with the text "login" and "logout" depending on your choice. It works with both Upper- or lowercase.

SMS conversation showing how to log in and log out

Everyone is automatically logged out at 17:00. That's just how we have set up the original switchboards code.
You can easily change this in your own set up. Find the row that looks like the code below and change 17 to the time you want (note that we are using a 24 hour clock in our code).


    

Now what?

Now you're done 🥳
When a customer calls your virtual number, one of the ones that are configured as the recipents and have opted-in for the day, are getting that incoming call.

This switchboard can be extended with other functionalities based on what your specific needs might be. Here are a couple of suggestions as inspiration on how you can adjust your new switchboard: