Wednesday, February 14, 2018

Build a MeetMe conference bridge using Twilio Studio

If I had a dollar for every hour I sat on conference bridges, I'd be rich!  Even then, we've all had the experience where the conferencing platform that's being used absolutely sucks.  Maybe it's that the hold music is some horrible, distracting "news feed" that keeps you from getting work done while you're waiting to jump into the conference.  Or maybe it's that you're trying to use some conferencing service based in Redmond that pulls awesome tricks like occasionally putting you on an isolated bridge by yourself, with no contact to the rest of the folks on the conference (I've been assured that never actually happens, it's only my imagination). 

As I often say, when in doubt, build your own!  Thanks to Twilio's new Studio product (currently in Beta), you can do just that in 10 minutes.  That's right, 10 minutes from nothing to fully-functioning MeetMe conference bridge.  (Seriously, it took a lot longer to write this blog post than to build a conference bridge system).

Enough already.  Let's do it!

First, log into to Twilio Console (getting a Twilio account is left as an exercise for the reader).

Then, click on the Studio icon in the left nav bar -- it looks like a string of boxes:


Next, click on create a flow, and name your conference bridge:



And you'll want to "start from scratch":


Studio is easy to use -- just drag widgets from the library on the right over to the canvas, and connect them.  Most widgets are configurable, and when you click on the widget you can type in parameters.  

Since we're building a conference bridge, the first thing we'll want to do is greet our caller.  Drag a Say/Play widget onto the canvas, and then click on it.  Change it's name to something like "GreetCaller" (note that widget instance names can't contain spaces), and then type in the text you want the caller to hear.



 Click "Save", then then use your most to connect the Incoming Call transition from the Trigger to the start point of the GreetCaller widget:



Note that in this example, the Say/Play widget is going to "speak" the text using computer-generated text-to-speech, but if you want an ultra-professional sound, head over to VoiceBunny to get a professional recording of your prompts for cheap.

Of course, now we need to have our caller type in a conference ID.  Go ahead and drag both a "Gather Input on Call" and a "Split Based On" widget onto the canvas and connect them.  The first one will wait for the user to press digits, and the second will decide what to do with the digits.  In the Split widget, select Variable to Test based on Digits (as shown below):


Next, click on the Transitions tab of the Split widget.  Add at least 2 new transitions for conference IDs -- I'm going to use "654321" as the moderator ID who can start/end the conference, and "123456" for all the participants in this example.


Good work!  Let's go ahead and congratulate the caller who successfully entered the participant conference ID, 123456, by connecting a Say/Play widget to that transition:



Let's go ahead and finish the participant call flow (and we'll go back and do the moderator in a bit).  For this, we need to create a function that uses the Twilio conference service.  Here's some quick javascript for this:

exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
        // Change the conference name to anything you like. 
let conferenceName = "ExampleConf"  
   
    if (event.ConfModerator == "1") {
      twiml.dial().conference(conferenceName, { waitUrl: "http://twimlets.com/holdmusic?Bucket=com.twilio.music.rock", startConferenceOnEnter: true, endConferenceOnExit: true } );
    } else {
       twiml.dial().conference(conferenceName, { waitUrl: "http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient", startConferenceOnEnter: false } );
    }  
callback(null, twiml);

};

Wow, I had forgotten how much I hate JavaScript!  Anyway... this code is going to test the variable "ConfModerator" to determine if it's a participant or the moderator.  The moderator will start the conference when he/she joins, otherwise the participants will listen to the joyous ambient music-on-hold.  Create a function using Twilio Runtime, and just slap that code in:


Now, go back into Studio and drag a Run Function widget onto the canvas.  Select the function you created above from the FUNCTION URL dropdown, and since this flow is for the participant, add "ConfModerator" and "0" to the FUNCTION PARAMETERS boxes.  Don't forget to click "ADD" after you type the values in.

Whew, we're almost done!  Drag one more Run Function widget onto the canvas, connect it to your moderator code, but this time set "ConfModerator" to "1" in the FUNCTION PARAMETERS.



The last step is to connect it to an inbound phone number!  Use the Twilio tool "Phone Numbers" to purchase and configure an inbound phone number.  Select "Studio Flow" as the "A CALL COMES IN" destination, and then select your Studio projects from the drop down.


Voila!  You have a basic MeetMe conference bridge!  Test it by dialing the phone number and entering the moderator or participant conference codes.  Ridiculously easy, right?   Enjoy!