Build a Conference Call with the Vonage Voice API and ASP.NET Core
Published on December 9, 2021

This is the sixth tutorial on how to use Voice APIs with ASP.NET series. In the previous tutorial, we learnt how to forward a call via voice proxy with ASP.NET Core. In today's tutorial, we will learn how to set up a conference call so multiple people can join the same call.

Learning objectives

In this tutorial, we will:

  • Create an ASP.NET Core app.

  • Use NancyFX with ASP.NET Core.

  • Create a Vonage voice application.

  • Create and return NCCOs.

  • Run and test the code using Ngrok.

Prerequisites

  • Visual Studio 2017 or higher.

  • A project that was created for this tutorial series, which you can find on Github.

  • Optional: The Vonage CLI.

<sign-up></sign-up>

Configuration

To use The Vonage Voice API, we need to create a voice application.

The configuration steps are detailed in the Vonage Voice API with ASP.NET: Before you start post.

Once the configuration is created successfully, we can move on to setting up a conference call.

Building a Conference Call

When a user calls the Vonage number, the Vonage Voice API will make a request to the application to figure out how to respond using a Vonage Call Control Object (NCCO).

The user will be greeted then will join the conference call.

For that purpose, we are going to use NancyFX alongside our ASP.NET Core project.

First of all, we need to add Nancy to our project:

PM> Install-Package Nancy
PM> Install-Package Microsoft.AspNetCore.Owin

To allow Nancy to handle any HTTP requests, we need to tell ASP.NET Core to use Nancy via Owin in the Configure method of Startup.cs.

using Microsoft.AspNetCore.Builder;
using Nancy.Owin;

namespace NexmoVoiceASPNetCoreQuickStarts
{
    public class Startup
    {
        public void Configure(IApplicationBuilder app)
        {
            app.UseOwin(x => x.UseNancy());
        }
    }
}

The next step is to create a Nancy module in which we create a route to /webhook/answer which will respond with the ncco returned by GetConferenceCallNCCO()

using Nancy;
using Vonage.Voice.Nccos;

namespace NexmoDotnetCodeSnippets.Modules
{
    public class ConferenceCallModule : NancyModule 
    {
        public ConferenceCallModule()
        {
            Get("/webhook/answer/", x => {
                var response = GetConferenceCallNCCO();
                response.ContentType = "application/json";
                return response;
            });
            Post("/webhook/event", x => Request.Query["status"]);
        }

        private Response GetConferenceCallNCCO()
        {
            var ncco = new Ncco();
            ncco.Actions.Add(new TalkAction
            {
                Text = "Hello. You will now be added to the conference call.",
                Language = "en-US",
                Style = 2
            });

            ncco.Actions.Add(new ConversationAction
            {
                Name = "conference-call"
            });

            return Response.AsJson(ncco);
        }
    }
}

The above code will do the following:

When a call is received, the user will hear "Hello. You will now be added to the conference call." then they will be added to the conference call.

Multiple callers can be added to the conference until they all have disconnected.

We are done! To test this sample app, some more configuration steps are required.

Linking Your App to Vonage

If you've been following along so far, you've already configured your Vonage account and created a voice app as shown in this post. We need to link this app to a Vonage phone number that we are going to call.

If you don't have a number, you can purchase one using the dashboard or the by using the Vonage CLI:

vonage numbers:search US vonage numbers:buy [NUMBER] [COUNTRYCODE]

Similarly to link the number, you can use the dashboard or the CLI:

vonage apps:link --number=VONAGE_NUMBER APP_ID

We need to tell Vonage which URL to make a request to when a call is received - this is called the answer_url. For me, this URL is http://localhost:63286/webhook/answer and that's only running locally.

To expose our webhook answer URL, we will use Ngrok.

ngrok http 63286

We now have a new URL (mine is http://<SUBDOMAIN>.ngrok.io) that can be used as the answer_url for the voice application.

Update your application with your new answer_url. It should look like http://subdomain.ngrok.io/webhook/answer. Run the app and give it a go by calling the TO_NUMBER.

Learn more

API References and Tools

Nexmo Getting Started Guides for ASP.NET

Rabeb OthmaniVonage Alumni

Rabeb was a Developer Advocate at Nexmo focusing on cloud communication APIs and helping developers get the best experience possible when building their apps. Other than writing code for a living, Rabeb advocates for bringing more women and minorities into tech, thus her involvement with Women Who Code and different tech communities. She leads the Women Who Code Network in Bristol.

Ready to start building?

Experience seamless connectivity, real-time messaging, and crystal-clear voice and video calls-all at your fingertips.