
Build a Conference Call with Node-RED
Inprevious tutorials you’ve had a chance to get your feet wet in the world of Nexmo APIs, making and receiving phone calls using theVoice API, and hopefully also customizing these experiences.
In today’s tutorial, we’ll take it a step further and build a voice-based conferencing service.
The user calls a predefined virtual number and inputs a meeting ID using the dial pad, then they get placed in the same conference call with everyone else who has provided the same ID.
Steps:
- Prerequisites
- Expose Your Local Server to the Internet
- Define the Webhook Endpoint for Inbound Calls
- Define the Webhook Endpoint for the Input Event
- Create a Nexmo Voice Application
- Set Up a Number to Call
- Handle Your Call Events
- Try it out!
Prerequisites
Before getting started, you’ll need a few things:
- Node.js andNode-RED installed on your machine
- A Nexmo account—create one for free if you haven’t already
- A way to expose your server to the internet. This either means you’re running a hosted version of Node-RED, or in case you’re developing locally, using a tunneling service likengrok—get up to speed with thisGetting Started with Ngrok in Node-RED tutorial
Getting Your Credentials
To interact with the Voice API, you’ll need to make note of a couple of things. Once you’ve created a Nexmo account, go to thedashboard to find your API key and secret.
Next, you’ll need aVoice-enabled virtual number. Go to Numbers >Buy numbers to get one.
Setting Up Your Node-RED Editor
First, you’ll need toinstall the runtime and editor. This could be done either on your local machine, on a Single Board Computer (eg. Raspberry Pi), or through several cloud-hosted options. This example will be using your local machine, so once you’ve installed Node-RED globally, type the command below in your terminal to get started.
$ node-red
You can then access the Node-RED editor by pointing your browser athttp://localhost:1880.
Once you have your editor open, you’ll need to install the Nexmo nodes. You can do so under theManage palette menu, by searching for thenode-red-contrib-nexmo
package and clicking install.
Now you should see all of the Nexmo nodes appear on the left side of your screen—in your node palette, among other default nodes.
Expose Your Local Server to the Internet
The Nexmo API will need access to this webhook to make calls against it, so let’smake the URL accessible over the public internet. If you’re running Node-RED on a public web server instead of your local machine, you’re all set and ready to move on to theCreate a Nexmo Voice Application step.
Otherwise, a convenient way to do this is by using a tunneling service likengrok.
First, you’ll need to install the ngrok node. To do so, open upManage palette from the hamburger menu in your Node-RED editor, search for thenode-red-contrib-ngrok
package, and click install. After restarting your editor, thengrok
node should appear in the node palette.
Thengrok
node takes the stringson oroff as input to start/stop the tunnel, and outputs the ngrok host address as themsg.payload
.
The easiest way to set this up is to wire twoinject
nodes as thengrok
node’s input, one with the payload of the stringon and the other withoff. For easier use, you could also set theName
of these nodes accordingly in the node properties, so that it’s clear what functionality they have. Next, to display the host address in the debug sidebar, connect adebug
node afterngrok
.
As the last step before hittingDeploy, open up thengrok
node properties and specify the port number. In case of Node-RED, the default value is1880
. The default ngrok Region is US but you can also set it to Europe or Asia. You can also add your authtoken for your ngrok account if you have one. Don’t worry if you don’t, just skip this step for now. The node will warn that it is not fully configured but this is not an issue.
And you’re all set! Once you hitDeploy and click on theoninject
node’s button, navigate to the URL displayed in the debug area (YOUR_URL for future reference) to find your Node-RED editor at a public address.
Define the Webhook Endpoint for Inbound Calls
Nexmo calls are controlled usingNexmo Call Control Objects, also known as NCCOs. An NCCO defines a list of actions to be followed when a call is handled. There are lots of different actions available; find the corresponding nodes under the Nexmo palette in your Node-RED editor or check out theNCCO Reference to find out more about them.
When handling inbound calls, you need your NCCO hosted at anAnswer URL. In this case, we’ll be using atalk
action to ask tor the meeting ID, then aninput
action to collect it.
Add avoice webhook
input node to your canvas, followed by atalk
node, aninput
node and areturn NCCO
output node.
Next, in thevoice webhook
node, selectGET
as aMethod
and type/answer
in the answer URL field.
In thetalk
node properties set theText{}
field to the message you’d like to be read out when the call is answered. E.g. “Please enter the meeting ID”. You can also select aVoice Name
, see theText to Speech Guide for the full list of options.
Finally open theinput
node editor, setYOUR_URL/input
as theURL {}
andPOST
as aMethod
.
At this time you could also set a couple of other parameters to further customize the experience:
Name | Description |
---|---|
Submit On Hash : | Set to true so the caller’s activity is sent to your webhook endpoint atYOUR_URL/input after they press# . If# is not pressed the result is submitted afterTime Out seconds. The default value is false. |
Time Out : | The result of the caller’s activity is sent to theYOUR_URL/input webhook endpointTime Out seconds after the last action. The default value is 3. Max is 10. |
Max Digits : | The number of digits the user can press. The maximum value is 20, the default is 4 digits. |
Find out more about these in theNCCO Reference.
Define the Webhook Endpoint for the Input Event
You’ll also need a second endpoint to capture the DTMF input from the user, and based on the code they have submitted, place them into aconversation.
Add anothervoice webhook
input node to your canvas, followed by atalk
node, aconversation
node and areturn NCCO
output node.
voice webhook
In thevoice webhook
node properties, selectPOST
as a method and type/input
in the answer URL field.
If you were to connect adebug
node after it, after finishing and running the flow, you would see the parameters returned to the/input
URL:
Name | Description |
---|---|
uuid | The unique ID of the Call leg for the user initiating the input. |
conversation_uuid | The unique ID for this conversation. |
timed_out | Returns true if this input timed out based on the value ofTime Out . |
dtmf | The numbers input by your caller, in order. |
In our use case, we are trying to get thedtmf
value, as this is the meeting ID provided by the caller.
Having a closer look at the debug sidebar on completions, we can see that it’s going to be in thedtmf
property of thecall
object nested inside themsg
object, so we can reference it as{{msg.call.dtmf}}
in the other nodes of this path.
talk
Next, open up thetalk
node editor and set theText{}
field to the message you’d like to be read out once the caller inputs the meeting ID.
Note the{}
sign next to theText
label, showing that this value can be set dynamically, usingMustache templating, so you could go with something likeJoining meeting {{msg.call.dtmf}}
.
Feel free to further personalize the experience by selecting aVoice Name
or by making use ofSSML tags
conversation
We’re using theconversation
action to create a standard conference, so the only parameter we have to set isName {}
. Using the conversation action with the same name reuses the same persisted Conversation, so it’s handy to name it after the meeting ID, referencing{{msg.call.dtmf}}
The first person to call the virtual number assigned to the conversation creates it.
In the future, you might want to take this a step further and create a moderated Conversation with selective audio controls. Check out theNCCO reference to find out more.
Once you’re done with this path, it should look similar to this:
Create a Nexmo Voice Application
Some of Nexmo’s APIs, including the Voice API, use Nexmo Applications to hold security and config information needed to connect to Nexmo endpoints.
In the Nexmo Node-RED palette, several nodes have the capability to create these applications:getrecording
,earmuff
,mute
,hangup
,transfer
,createcall
,playaudio
,playtts
andplaydtmf
.
Drag any of these nodes into your workspace, then double-click on it to open up the node properties.
Next to theNexmo Credentials
, select “Add new nexmovoiceapp…” from the drop-down menu and click the edit button. Fill in the details below and clickCreate New Application
.
KEY | DESCRIPTION |
---|---|
Name | Choose a name for your Voice Application, for exampleConference Call . |
API Key | Your Nexmo API key, shown in youraccount overview. |
API Secret | Your Nexmo API secret, shown in youraccount overview. |
Answer URL | YOUR_URL/answer, you’ll be hosting a Nexmo Call Control Object (NCCO) here. – more about this later on. |
Event URL | YOUR_URL/event, you’ll need to reference this when setting up the event handler. |
Node-RED will then create a new Nexmo Application on your account and fill in the App ID and Private Key fields for you to save. After this step, feel free to delete the Nexmo node you used, as anexmovoiceapp
config node has been created, and that contains all the Nexmo credentials this flow needs.
Set Up a Number to Call
Next, you’ll have to link your virtual number to this application.
Find the Voice Application you’ve just created in your Nexmo Dashboard by navigating toVoice >Your Applications.
Click on the name of this application, then under theNumbers tab click on theLink button next to the virtual number you’ve rented earlier.
In case the number you’d like to use is already linked to another app, click onManage number and configure it to forward incoming calls to your app.
Bonus tip: Use acomment
node to take note of the Nexmo number linked to your application, this way you always have it handy.
Handle Your Call Events
If you’d like to receive events about the progress of your call, you can also set up an event webhook.
Connect anhttp
input node to anhttp response
node, as well as to adebug
node, so that you can view your call events in the debug area.
In thehttp
input node, selectPOST
as aMethod
and fill in theURL
field with/event
.
Thehttp response
node should have200
set asStatus code
, but don’t worry about it; this is the default value as well.
Try it Out!
And that’s a wrap! Get a friend or more and take it for a spin! Don’t forget to take a peek in the debug area to follow your call events. Enjoy!
Where Next?
Resources:
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse