Do you fancy making an outbound call to your customer from the comfort of your own application? Would you be interested in creating your own customer journey without compromising to the current tech stack? Do you wish to be the master of your own scenario logic down to every single action?

Then, read on, as our new Calls API might be a perfect solution for you!

This blog post will show you how easy it is to make an outbound call using Calls API and your own application.

What is Calls API?

In May, we released a new set of APIs, Calls that allow you to create outbound/inbound calls as well as create conferences. The Calls API has been designed specifically for those who don’t want an out-of-the-box solution and prefer to create their own tailor-made products that cater best to their customers’ business needs. With the Calls API, you can use your own application stack hosted on-premise or in a cloud to easily integrate voice messaging, IVR, click-to-call, conferencing, or number management and number masking.

Quick workflow overview

Creating an outbound call is as easy as an A-P-I. Simply put, your application that you have configured to work with the Calls API continuously listens to the incoming events to which your application has subscribed, and triggers an appropriate series of actions.

To make an outbound call all you need is to establish a call and then design its flow by adding various actions through an API request (e.g. play. audio during a call, send a file, send a text-to-speech message, etc.). The actions are requested to the Infobip platform via API and as a result, an event is sent to your application’s webhooks.

What you need before you can start

To start your Calls adventure, you’ll need an active Infobip account with Voice enabled as a channel. Ideally, you also need to have your own application, but if you want to start testing the Calls API without developing an application, you can use an online webhook simulator, such as Beeceptor or Mocky.

Set up your app with Infobip

On the Infobip side, you’ll need to declare your application, set up an authentication method (HMAC or Basic), and expose two webhooks, receiveUrl and eventUrl . The first webhook receives all CALL_RECEIVED events. The eventUrl will catch all events, which you have subscribed your app to, that are related to calls, conferences, and their actions. Keep reading to find out how to subscribe to events.

To declare which call-related events you want to subscribe your app to, you need to pass them in the subscribedEvents field, so that Infobip platform knows which events it needs to send to the app. The sample request below shows you the basic payload you need to declare in your application environment.

curl -L -g -X POST 'https://{baseUrl}/calls/1/applications' \
-H 'Authorization: {authorization}' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
--data-raw '{
  "name": "Example application",
  "subscribedEvents": [
    "CALL_RECEIVED",
    "CALL_RINGING",
    "CALL_ESTABLISHED",
    "CALL_FINISHED",
    "SAY_FINISHED"
  ],
  "webhook": {
    "receiveUrl": "https://www.example.com/receive",
    "eventUrl": "https://www.example.com/event"
  }
}'

Key points:

baseUrl is a custom URL you’ll see in your Infobip account where you can also grab the API Key. • Check out the complete list of events you can subscribe your app to.

As part of the response, you will get the applicationId which you will then use when creating calls.

Establish a call

Once your app is configured to work with the Infobip platform, you will need to create a call so that when it’s live you can add actions to it, e.g. play audio during a call, record a call, send a text-to-speech message. In this post, we will show you how to send a text-to-speech message inside a live call and how to end the call.

curl -L -g -X POST 'https://{baseUrl}/calls/1/calls' \
-H 'Authorization: {authorization}' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
--data-raw '{
  "applicationId": "61c060db2675060027d8c7a6",
  "endpoint": {
    "phoneNumber": "41792036727",
    "type": "PHONE"
  },
  "from": "41793026834",
  "connectTimeout": 30
}'

Key points:

applicationId is returned in the response when you fire the POST calls/1/applications endpoint.
• Use endpoint to pass in the details of who you want to connect your call to. In this case, we’re going to call a phone number, but you could also do a SIP or a WebRTC call.

As part of the response, you will get the id of the call which you will then use to modify your call.

Add actions to your call

Once the call has been established, your application can start using Calls API to submit individual actions to the call, the outcome of which will be sent as an event to your webhooks. All we need to know at this point is the ID of the call, and we can start designing the call flow. In this case, we want to send a text-to-speech message and then the user can hang up terminating the call with their action. To send an STT message, we need to use the say method, as shown below.

curl -L -g -X POST 'https://{baseUrl}/calls/1/calls/{callId}/say' \
-H 'Authorization: {authorization}' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
--data-raw '{
  "callId": "d8d84155-3831-43fb-91c9-bb897149a79d",
  "text": "Hello world",
  "language": "en"
}'

Key points:

  • Use callId to pass the id field you received in your POST calls/1/calls response.
  • The call finishes when the end user hangs up the phone.

As you can see, creating an outbound call with the Calls API is not only easy but it allows you to have control over all aspects of the call so that you can create an amazing bespoke user experience just the way you like it!

For more information on Calls, check out our Documentation Hub or head over to our API Reference.