Connect callers to a conference

This code snippet shows how to join multiple calls into a conversation.

Multiple inbound calls can be joined into a conversation (conference call) by simply connecting the call into the same named conference.

Conference names are scoped at the Vonage Application level. For example, VonageApp1 and VonageApp2 could both have a conference called vonage-conference and there would be no problem.

Example

Replace the following variables in the example code:

Key Description
CONF_NAME The named identifier for your conference

Prerequisites

A Nexmo application contains the required configuration for your project. You can create an application using the Nexmo CLI (see below) or via the dashboard. To learn more about applications see our Nexmo concepts guide.

Install the CLI

npm install -g nexmo-cli

Create an application

Once you have the CLI installed you can use it to create a Nexmo application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step

Nexmo needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.

nexmo app:create "Conference Call Example" http://demo.ngrok.io/webhooks/answer http://demo.ngrok.io/webhooks/events --keyfile private.key

npm install express body-parser

Create a file named conference-call.js and add the following code:

Copy to Clipboard
const app = require('express')()
const bodyParser = require('body-parser')

app.use(bodyParser.json())

View full source

Write the code

Add the following to conference-call.js:

Copy to Clipboard
const onInboundCall = (request, response) => {
  const ncco = [
    {
      action: 'talk',
      text: 'Please wait while we connect you to the conference'
    },
    {
      action: 'conversation',
      name: CONF_NAME
    }
  ]

  response.json(ncco)
}

app.get('/webhooks/answer', onInboundCall)

app.listen(3000)

View full source

Run your code

Save this file to your machine and run it:

node conference-call.js

Prerequisites

A Nexmo application contains the required configuration for your project. You can create an application using the Nexmo CLI (see below) or via the dashboard. To learn more about applications see our Nexmo concepts guide.

Install the CLI

npm install -g nexmo-cli

Create an application

Once you have the CLI installed you can use it to create a Nexmo application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step

Nexmo needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.

nexmo app:create "Conference Call Example" http://demo.ngrok.io/webhooks/answer http://demo.ngrok.io/webhooks/events --keyfile private.key

Add the following to `build.gradle`:

compile 'com.vonage:client:5.5.0'
compile 'com.sparkjava:spark-core:2.7.2'

Write the code

Add the following to the main method of the ConferenceCall class:

Copy to Clipboard
/*
 * Route to answer incoming calls with an NCCO response.
 */
Route answerRoute = (req, res) -> {
    TalkAction intro = TalkAction.builder("Please wait while we connect you to the conference.").build();
    ConversationAction conversation = ConversationAction.builder(CONF_NAME).build();

    res.type("application/json");

    return new Ncco(intro, conversation).toJson();
};

Spark.port(3000);
Spark.get("/webhooks/answer", answerRoute);
Spark.post("/webhooks/answer", answerRoute);

View full source

Run your code

We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:

Copy to Clipboard
  apply plugin: 'application'
  mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''

Run the following gradle command to execute your application, replacing com.vonage.quickstart.voice with the package containing ConferenceCall:

gradle run -Pmain=com.vonage.quickstart.voice.ConferenceCall

Prerequisites

A Nexmo application contains the required configuration for your project. You can create an application using the Nexmo CLI (see below) or via the dashboard. To learn more about applications see our Nexmo concepts guide.

Install the CLI

npm install -g nexmo-cli

Create an application

Once you have the CLI installed you can use it to create a Nexmo application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step

Nexmo needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.

nexmo app:create "Conference Call Example" http://demo.ngrok.io/webhooks/answer http://demo.ngrok.io/webhooks/events --keyfile private.key

Install-Package Vonage

Create a file named ConnectCallersToConferenceController.cs and add the following code:

Copy to Clipboard
using Vonage.Voice.Nccos;

View full source

Write the code

Add the following to ConnectCallersToConferenceController.cs:

Copy to Clipboard
[HttpGet("webhooks/answer")]
public string Answer()
{
    var CONF_NAME = Environment.GetEnvironmentVariable("CONF_NAME") ?? "CONF_NAME";
    var talkAction = new TalkAction() { Text = "Please wait while we connect you to the conference" };
    var conversationAction = new ConversationAction() { Name = CONF_NAME };
    var ncco = new Ncco(talkAction, conversationAction);
    return ncco.ToString();
}

View full source

Prerequisites

A Nexmo application contains the required configuration for your project. You can create an application using the Nexmo CLI (see below) or via the dashboard. To learn more about applications see our Nexmo concepts guide.

Install the CLI

npm install -g nexmo-cli

Create an application

Once you have the CLI installed you can use it to create a Nexmo application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step

Nexmo needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.

nexmo app:create "Conference Call Example" http://demo.ngrok.io/webhooks/answer http://demo.ngrok.io/webhooks/events --keyfile private.key

composer require vonage/client slim/slim:^3.8

Create a file named index.php and add the following code:

Copy to Clipboard
use Laminas\Diactoros\Response\JsonResponse;
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

View full source

Add the following to index.php:

Copy to Clipboard
require 'vendor/autoload.php';

$app = new \Slim\App;

View full source

Write the code

Add the following to index.php:

Copy to Clipboard
$app->get('/webhooks/answer', function (Request $request, Response $response) {
    $talk = new \Vonage\Voice\NCCO\Action\Talk('Hi, welcome to this Nexmo conference call');
    $convo = new \Vonage\Voice\NCCO\Action\Conversation('nexmo-conference-standard');

    $ncco = new \Vonage\Voice\NCCO\NCCO();
    $ncco->addAction($talk);
    $ncco->addAction($convo);

    return new JsonResponse($ncco->toArray());
});

$app->run();

View full source

Run your code

Save this file to your machine and run it:

php -S localhost:3000 -t .

Prerequisites

A Nexmo application contains the required configuration for your project. You can create an application using the Nexmo CLI (see below) or via the dashboard. To learn more about applications see our Nexmo concepts guide.

Install the CLI

npm install -g nexmo-cli

Create an application

Once you have the CLI installed you can use it to create a Nexmo application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step

Nexmo needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.

nexmo app:create "Conference Call Example" http://demo.ngrok.io/webhooks/answer http://demo.ngrok.io/webhooks/events --keyfile private.key

pip install 'flask>=1.0'

Create a file named connect-callers-to-a-conference.py and add the following code:

Copy to Clipboard
from flask import Flask, jsonify

app = Flask(__name__)

View full source

Write the code

Add the following to connect-callers-to-a-conference.py:

Copy to Clipboard
@app.route("/webhooks/answer")
def answer_call():
    ncco = [
        {
            "action": "talk",
            "text": "Please wait while we connect you to the conference"
        },
        {
            "action": "conversation",
            "name": CONF_NAME
        }]
    return jsonify(ncco)


if __name__ == '__main__':
    app.run(port=3000)

View full source

Run your code

Save this file to your machine and run it:

python3 connect-callers-to-a-conference.py

Prerequisites

A Nexmo application contains the required configuration for your project. You can create an application using the Nexmo CLI (see below) or via the dashboard. To learn more about applications see our Nexmo concepts guide.

Install the CLI

npm install -g nexmo-cli

Create an application

Once you have the CLI installed you can use it to create a Nexmo application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step

Nexmo needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.

nexmo app:create "Conference Call Example" http://demo.ngrok.io/webhooks/answer http://demo.ngrok.io/webhooks/events --keyfile private.key

gem install sinatra sinatra-contrib

Create a file named join_a_conference_call.rb and add the following code:

Copy to Clipboard
require 'sinatra'
require 'sinatra/multi_route'
require 'json'

before do
  content_type :json
end

View full source

Write the code

Add the following to join_a_conference_call.rb:

Copy to Clipboard
route :get, :post, '/webhooks/answer' do
  [
    {
      action: 'talk',
      text: 'Welcome to a Vonage powered conference call'
    },
    {
      action: 'conversation',
      name: 'room-name'
    }
  ].to_json
end

set :port, 3000

View full source

Run your code

Save this file to your machine and run it:

ruby join_a_conference_call.rb

Try it out

Start your server and make multiple inbound calls to the Vonage Number assigned to this Vonage Application. The inbound calls will be connected into the same conversation (conference).