Telephony API
IVR API
Create and configure Voice Response applications (IVR) via an API.
The Sonetel API allows you to set up and change IVR applications via an API.
Types of IVR apps that can be created via the API
You can create and manage the following types of Voice Response apps via the API.
- IVR menu
Offer you callers a menu, where different things happen dependent on what digit they press. - Voicemail
Take a message and deliver it somewhere. - Announcement
Play a message and then forward the call somewhere or hang up.
All creation and management of IVR apps can be done via the Sonetel web app or via the API. There is no difference between IVR apps created in the web app or via the API.
How the IVR API works
All of the API documentation for Voice apps can be found here.
Here are some definitions that are good to know before you get started.
- Voice app
A voice app can either be a menu or an announcement (“ivr”) or a voicemail box (“mailbox”). - Prompt
Each Voice app has a set of pre-defined prompts to be played to callers. This can be a “greeting message” or “menu” or similar. It is possible to define custom prompts for playing various types of information messages – such as “Opening hours” or “Deal of the week”. - Default messages
All pre-defined Prompts come with a default recordings which will be played until you replace it with your own recording. - Voice
“Voice” is a parameter in each Voice app that defines what language and voice (female or male) to use for the default recordings in the pre-defined prompts. For example: “US English – female”. This setting only has a meaning until you have replaced all default messages with custom messages. - Custom message
A custom message is a recording that you upload and assign to a prompt (either a default prompt or a custom prompt. You can optionally create audio files with the Text to speech API.
Sample Python scripts for IVR
Creating a new IVR
import requests import json base_url = "https://public-api.sonetel.com/" # API Access token access_token = "ENTER_ACCESS_TOKEN" # Sonetel account ID acc_id = "ENTER_ACCOUNT_ID" ###################### New IVR inputs############################ ivr_name = "TYPE_NAME_OF_NEW_IVR" #########################JSON#################################### json_data = json.dumps({ "app_type": "ivr", "play_menu": "yes", "name": ivr_name, "voice": "en", "play_welcome": "yes", "get_extension": "yes", "menu": { "digit_0":{ "action": "call", "to": "user", "id": "ENTER_USER_ID" }, "digit_1":{ "action": "call", "to": "phnum", "id": "ENTER_PHONE_NUMBER" }, "digit_2":{ "action": "connect", "to": "app", "id": "ENTER_APP_ID" } } }) ###########################Para######################################## headers = {"Authorization": "Bearer {}".format(access_token), 'Content-Type': 'application/json;charset=UTF-8' } ################Create New IVR##################### def create_new_ivr(): response_create_ivr = requests.request("POST", "{}account/{}/voiceapp".format(base_url, acc_id), headers=headers, data=json_data).json() print(response_create_ivr) if response_create_ivr["status"]=="success": return True else: return False if(create_new_ivr()): print("IVR Created successfully")
Configuring an existing IVR
import requests import json base_url = "https://public-api.sonetel.com/" # API Access token access_token = "ENTER_ACCESS_TOKEN" # Sonetel account ID acc_id = "ENTER_ACCOUNT_ID" # Voice app ID app_id = "ENTER_APP_ID" # SAMPLE JSON BODY json = json.dumps({ "app_type": "ivr", "play_menu": "yes", "name": "ENTER_IVR_NAME", "voice": "en", "play_welcome": "yes", "get_extension": "yes", "menu": { "digit_1": { "action": "call", "to": "phnum", "id": "ENTER_PHONE_NUMBER" }, "digit_2": { "action": "call", "to": "user", "id": "ENTER_USER_ID" }, "digit_3": { "action": "connect", "to": "app", "id": "ENTER_APP_ID" } } }) headers = {"Authorization": "Bearer {}".format(access_token), 'Content-Type': 'application/json;charset=UTF-8' } # Update the IVR def update_ivr(): global update_ivr_response update_ivr_response = requests.request("PUT", "{}account/{}/voiceapp/{}".format(base_url, acc_id, app_id), headers=headers, data=json).json() if update_ivr_response["status"]=="success": return True else: return False if(update_ivr()): print("IVR updated successfully")