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 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:

KeyDescription
VOICE_CONFERENCE_NAME

The named identifier for your conference.

Prerequisites

npm install express body-parser

Write the code

Add the following to conference-call.js:

const Express = require('express');
const bodyParser = require('body-parser');

const app = new Express();
app.use(bodyParser.json());

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

  response.json(ncco);
};

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

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`);
});

View full source

Run your code

Save this file to your machine and run it:

node conference-call.js

Prerequisites

Add the following to build.gradle:

implementation 'com.vonage:server-sdk-kotlin:2.1.1'
implementation 'io.ktor:ktor-server-netty'
implementation 'io.ktor:ktor-serialization-jackson'

Write the code

Add the following to the main method of the ConnectCallersToConference file:

embeddedServer(Netty, port = 8000) {
    routing {
        route("/webhooks/answer") {
            handle {
                call.response.header("Content-Type", "application/json")
                call.respond(
                    Ncco(
                        talkAction("Please wait while we connect you to the conference."),
                        conversationAction(VOICE_CONFERENCE_NAME)
                    ).toJson()
                )
            }
        }
    }
}.start(wait = true)

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:

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

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

gradle run -Pmain=com.vonage.quickstart.kt.voice.ConnectCallersToConference

Prerequisites

Add the following to build.gradle:

implementation 'com.vonage:server-sdk:9.3.1'
implementation 'com.sparkjava:spark-core:2.9.4'

Write the code

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

final String CONF_NAME = "my-conference";

/*
 * 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:

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

Install-Package Vonage

Write the code

Add the following to ConnectCallersToConferenceController.cs:

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

View full source

Prerequisites

composer require vonage/client slim/slim:^3.8

Write the code

Add the following to index.php:

require 'vendor/autoload.php';

$app = new \Slim\App;

$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

pip install vonage python-dotenv fastapi[standard]

Write the code

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

import os
from os.path import dirname, join

from dotenv import load_dotenv
from fastapi import FastAPI
from vonage_voice import Conversation, NccoAction, Talk

dotenv_path = join(dirname(__file__), '../.env')
load_dotenv(dotenv_path)

VOICE_CONFERENCE_NAME = os.environ.get("VOICE_CONFERENCE_NAME")

app = FastAPI()


@app.get('/webhooks/answer')
async def answer_call():
    ncco: list[NccoAction] = [
        Talk(text="Please wait while we connect you to the conference"),
        Conversation(name=VOICE_CONFERENCE_NAME),
    ]

    return [action.model_dump(by_alias=True, exclude_none=True) for action in ncco]

View full source

Run your code

Save this file to your machine and run it:

fastapi dev voice/connect-callers-to-a-conference.py

Prerequisites

gem install sinatra sinatra-contrib

Write the code

Add the following to join_a_conference_call.rb:

require 'sinatra'
require 'sinatra/multi_route'
require 'json'

VOICE_CONFERENCE_NAME = ENV['VOICE_CONFERENCE_NAME']

before do
  content_type :json
end

route :get, :post, '/webhooks/answer' do
  [
    {
      action: 'talk',
      text: 'Please wait while we connect you to the conference'
    },
    {
      action: 'conversation',
      name: VOICE_CONFERENCE_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).

Further Reading

  • Conference Calling - This guide explains the two concepts Vonage associates with a call, a leg and a conversation.