Connect callers to a conference

This building block 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 Nexmo Application level. For example, NexmoApp1 and NexmoApp2 could both have a conference called nexmo-conference and there would be no problem.

Example

Prerequisites

Create an application

Install dependencies

Initialize your dependencies

Write the code

Add the following to app.js:

const onInboundCall = (request, response) => {
  const ncco = [
    {
      action: 'talk',
      text: 'Welcome to a Nexmo powered conference call'
    },
    {
      action: 'conversation',
      name: 'room-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 app.js

Prerequisites

Create an application

Install dependencies

Write the code

Add the following to ConferenceCall.java:

/*
 * Route to answer incoming calls with an NCCO response.
 */
Route answerRoute = (req, res) -> {
    TalkNcco intro = new TalkNcco("Please wait while we connect you to the conference.");
    ConversationNcco conversation = new ConversationNcco(CONF_NAME);

    Ncco[] nccos = new Ncco[]{intro, conversation};

    res.type("application/json");
    return new ObjectMapper().writer().writeValueAsString(nccos);
};

Spark.port(3000);
Spark.get("/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 command to execute your application replacing com.nexmo.quickstart.voice with the package containing ConferenceCall:

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

Prerequisites

Create an application

Install dependencies

Initialize your dependencies

Write the code

Add the following to index.php:

$app->get('/webhooks/answer', function (Request $request, Response $response) {
    $ncco = [
        [
            'action' => 'talk',
            'text' => 'Hi, welcome to this Nexmo conference call.'
        ],
        [
            'action' => 'conversation',
            'name' => 'nexmo-conference-standard'
        ]
    ];

    return $response->withJson($ncco);
});

View full source 

Run your code

Save this file to your machine and run it:

$ php index.php

Prerequisites

Create an application

Install dependencies

Initialize your dependencies

Write the code

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

@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

Create an application

Install dependencies

Initialize your dependencies

Write the code

Add the following to join_a_conference_call.rb:

route :get, :post, '/webhooks/answer' do
  [
    {
      action: 'talk',
      text: 'Welcome to a Nexmo 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 Nexmo Number assigned to this Nexmo Application. The inbound calls will be connected into the same conversation (conference).