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:
| Key | Description |
|---|---|
VOICE_CONFERENCE_NAME | The named identifier for your conference. |
Prerequisites
npm install express body-parserWrite 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}`);
});Run your code
Save this file to your machine and run it:
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 class:
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)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:
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 class:
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);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:
Prerequisites
Install-Package VonageWrite 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();
}Prerequisites
composer require vonage/client slim/slim:^3.8Run your code
Save this file to your machine and run it:
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]Run your code
Save this file to your machine and run it:
Prerequisites
gem install sinatra sinatra-contribRun your code
Save this file to your machine and run it:
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.