DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for How To Make and Receive calls using any Programming language ?
Ameed Jamous
Ameed Jamous

Posted on

How To Make and Receive calls using any Programming language ?

Programmable Voice API

Learn how to make and receive phone calls programmatically using Restcomm API (Twilio Alternative) where you can use / bring your own carrier.

A Call represents a connection between a phone or user agent and Restcomm CPaaS. This may be inbound or outbound. The Calls list resource represents the set of phone calls originated and terminated from an account.


curl -X POST https://cloud.restcomm.com/restcomm/2012-04-24/Accounts/ACCOUNT_SID/Calls.json  \
   -d 'From=16175551212' \
   -d 'To=16172221212' 
   -d 'Url=https://ACCOUNT_SID:AUTH_TOKEN@mycompany.com/restcomm/demos/hello-play.xml' \
   -u 'YourAccountSid:YourAuthToken'


Enter fullscreen mode Exit fullscreen mode

Making and receiving a call in JAVA

import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.util.Base64;

public class JavaSampleClass {
   // Provide your Account Sid and Auth Token from your Console Account page
   public static final String ACCOUNT_SID = "my_ACCOUNT_SID";
   public static final String AUTH_TOKEN = "my_AUTH_TOKEN";


   public static void main(String[] args) throws Exception {
      String userAndPass = ACCOUNT_SID + ':' + AUTH_TOKEN;
      String encoded = Base64.getEncoder().encodeToString(userAndPass.getBytes());

      URL url = new URL(("https://cloud.restcomm.com/restcomm/2012-04-24/Accounts/" + ACCOUNT_SID + "/Calls.json");
      HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
      conn.setRequestProperty("Authorization", "Basic " + encoded);
      conn.setRequestMethod("POST");
      conn.setDoOutput(true);
      DataOutputStream os = new DataOutputStream(conn.getOutputStream());

      // Update POST parameters accordingly
      os.writeBytes("From=16175551212&" +
        "To=16172221212" +
       "Url=https://ACCOUNT_SID:AUTH_TOKEN@mycompany.com/restcomm/demos/hello-play.xml");
      os.close();

      // Add your business logic below; response code can be obtained from 'conn.getResponseCode()' and input stream from 'conn.getInputStream()'
      ...
  }
}

Enter fullscreen mode Exit fullscreen mode

You can also provide a list of events you are interested in getting notified on and provide a URL to receive them at. Here’s an example for receiving answered and completed events. The callbacks will be made at http://status.callback.url


curl -X POST https://cloud.restcomm.com/restcomm/2012-04-24/Accounts/ACCOUNT_SID/Calls.json  \
   -d 'From=16175551212' \
   -d 'To=16172221212' \
   -d 'Url=https://ACCOUNT_SID:AUTH_TOKEN@mycompany.com/restcomm/demos/hello-play.xml' \
   -d 'StatusCallbackEvent=answered,completed' \
   -u 'YourAccountSid:YourAuthToken'

Enter fullscreen mode Exit fullscreen mode

For detailed and updated docs, visit https://cloud.restcomm.com/docs/api/calls-api.html

Top comments (0)

16 Libraries You Should Know as a React Developer

Being a modern React developer is not about knowing just React itself. To stay competitive, it is highly recommended to explore the whole ecosystem. This article contains some of the most useful React component libraries to speed up your developer workflow.