In this example project, we will create an application that answers phone calls and, after a specified time, initiates a callback to the callee.
sipgate.io is a collection of APIs, which enables sipgate's customers to build flexible integrations matching their individual needs. It provides interfaces for sending and receiving text messages or faxes, monitoring the call history, and initiating and manipulating calls. In this tutorial, we will use sipgate.io's Push and REST APIs for automatically responding to calls and initiating callbacks after a specified time.
The script in this project sets up a simple web server running on your local machine. If someone tries to reach your sipgate number, this webserver will answer the call and play a sound file that announces that all lines are currently busy. It will also initiate a callback to the caller after a specified time using the sipgate.io REST API. Our application consists of three phases:
- The application answers a call with a sound clip that announces that customer support is busy and we will get back to the caller soon.
- A timer is set. After the time elapses, it will initiate the callback.
- Once the call gets accepted on the callers' phone, the phone call will be redirected to the callee.
- node.js
- npm
- sipgate personal access token with scope
sessions:calls:write
To launch this example, navigate to a directory where you want the example service to be stored. In your terminal, clone this repository from GitHub and install the required dependencies using npm install
.
git clone https://github.com/sipgate-io/io-labs-time-controlled-callback.git
cd io-labs-time-controlled-callback
npm install
To run the project on your local machine, follow these steps:
- In the terminal, run
ssh -R 80:localhost:8080 nokey@localhost.run
- There will be some output. Copy the last URL.
- Duplicate .env.example and rename the file to .env
- Paste the URL from step 2 in
SIPGATE_WEBHOOK_SERVER_ADDRESS
. Your .env should look similar to this:
SIPGATE_WEBHOOK_SERVER_ADDRESS=https://d4a3f97e7ccbf2.localhost.run
SIPGATE_WEBHOOK_SERVER_PORT=8080
- Go to your sipgate app-web account and set both the incoming and outgoing webhook URLs as the URL from step 2.
- Create a personal access token in your personal access token settings. You will need the
sessions:calls:write
permission to facilitate phone calls. Once you saved the token and token ID, set theSIPGATE_TOKEN
andSIPGATE_TOKEN_ID
variables in your .env file. - Set the
ANNOUNCEMENT_FILE_URL
,DEVICE_ID
andCALLBACK_TIMEOUT
variables in the .env file according to their documentation. You can find the device ID in your routing settings or by querying the /{userId}/devices endpoint. - Run
npm start
from the root folder of this project.
Now you can call your sipgate account number to test the application. If the call builds successfully, your terminal will log some information and, after the specified time, the callback gets initiated.