right  Talk To Us!

UAS API - Connect To Conference Sample Application

  • Filename:

    samples/connect_to_conference.py

    Description:

    This sample application will connect the caller to a conference room. Using channel.FilePlayer.say(), the application askes the caller to enter a four digit PIN, representing a conference room ID, channel.DTMFDetector.get_digits() is used to retrieve the digits. If the right number of digits has been collected, the application will call use the high level API function call_and_connect_to_conference() to connect the caller to the conference room. If the conference room does not already exist, it will be created. There will be silence on the line until someone else enters.

    Code:

    """
        An inbound application that prompts the user to enter a 4-digit pin that represents a 
        conference room, to which they are then connected. Please read the documentation about
        conference rooms.
    
        The application uses TTS to communicate with the caller.
    
        This application requires 1 extra channel.
    
        Actions:
            - wait for inbound call
            - wait for four DTMF digits
            - create a tone player
            - connect the call to the conference room
            - wait for the caller to hang up
    
    """
    
    from prosody.uas import Hangup, Error
    from prosody.uas.highlevel import HighLevelCallChannel
    
    __uas_identify__ = "application"
    __uas_version__  = "1.0b1"
    
    def main(channel, application_instance_id, file_man, my_log, application_parameters):
    
        return_code = 0
    
        try:
            if channel.state() == channel.State.CALL_INCOMING:
                channel.ring()   # this can raise a Hangup exception
                channel.answer() # this can raise a Hangup exception
            else:
                raise Hangup('No inbound call')
    
            # get the extra channel
            try:
                out_channel = channel.ExtraChannel[0]
            except:
                raise Error("You need to register an extra channel for this application")
    
            channel.FilePlayer.say("Please enter a four digit conference i d.", barge_in = True)
    
            digits = channel.DTMFDetector.get_digits(count=4, seconds_predigits_timeout = 10)
    
            if channel.DTMFDetector.cause() == channel.DTMFDetector.Cause.COUNT:
                channel.FilePlayer.say("Adding you to conference {0}".format(", ".join(digits)))
    
                high_level_channel = HighLevelCallChannel(channel, my_log)
                if high_level_channel.call_and_connect_to_conference(other_call=out_channel, 
                                                                     conference_room_name=digits) is False:
                    my_log.error("Connect to conference. Hanging up")
                    channel.FilePlayer.say ("Sorry, I could not connect you to your conference. Good bye")
                    return_code = -104
                else:
                    my_log.info ("Connect to conference {0} succeeded. Waiting for idle.".format (digits))
                    channel.wait_for_idle(seconds_timeout=None)
            else:
                channel.FilePlayer.say ("I did not receive four digits. Hanging up.")
                return_code = -103
                
        except Hangup as exc:
            my_log.info("Got Hangup")
            return_code = -100
    
        except Error as exc:
            my_log.error("Got Error {0}".format(exc))
            return_code = -102
    
        except Exception as exc:
            my_log.exception("Got unexpected exception {0}".format(exc))
            return_code = -101
    
        finally:
            if channel.state() != channel.State.IDLE:
                channel.hang_up()
        return return_code
    
  • Filename:

    Samples\C#\ConnectToConference\ConnectToConference.cs

    Description:

    We ask for a four digit PIN code, representing the conference ID number, receive it using DTMF detection and then repeat the number back to the caller for confirmation. We can then use the CallConferenceRoom() method, that will call the conference on the extra channel supplied.

    We construct a ConferencePartyMediaSettings object to allow us to disable DTMF suppression which is enabled by default. The conference is configured to produce silence on the line until someone else enters the conference room.

    Code:

    using System;
    using System.Threading;
    
    using AMSClassLibrary;
    using UASAppAPI;
    
    // An inbound application that prompts the user to enter a 4-digit pin that represents 
    // the id of a conference to which they are then connected.
    //
    // Requires:
    // [1 extra channel]
    namespace ConnectToConference
    {
        // The application class.
        // This must have the same name as the assembly and must inherit from either 
        // UASInboundApplication or UASOutboundApplication.
        // It must override the Run method.
        public class ConnectToConference : UASInboundApplication
        {
            // Possible return codes
            enum ReturnCode
            {
                // Success Codes:
                Success = 0,
                // ... any positive integer
    
                // Fail Codes:
                // -1 to -99 reserved
                ExceptionThrown = -100,
                NotSufficientExtraChannels = -101
            }
    
            // This is the entry point for the application
            public override int Run(UASCallChannel channel,
                                    string applicationParameters)
            {
                this.Trace.TraceInfo("Started");
                ReturnCode reply = ReturnCode.Success;
                string conferenceId;
    
                // Check we've got an extra Channel
                if (channel.ExtraChannels.Length < 1)
                {
                    this.Trace.TraceWarning("Needs 1 extra channel to be configured");
                    return (int)ReturnCode.NotSufficientExtraChannels;
                }
                UASCallChannel conferenceChannel = channel.ExtraChannels[0];
    
                try
                {
                    // Answer the call
                    CallState state = channel.Answer();
                    if (state == CallState.Answered)
                    {
                        this.Trace.TraceInfo("Call answered");
    
                        // Prompt for a conference id, enabling bargein
                        channel.FilePlayer.Say("Please Enter a four digit conference i d.", true);
    
                        string digits;
                        DtmfDetectorCause cause = channel.DtmfDetector.GetDigits(4, out digits, 30);
                        if (cause == DtmfDetectorCause.Count)
                        {
                            conferenceId = digits;
    
                            // Inform the caller what is happening
                            channel.FilePlayer.Say(
                                "Adding you to conference <say-as interpret-as='vxml:digits'>{0}</say-as>",
                                conferenceId);
    
                            // Create settings to determine how the party is connected to the conference room
                            ConferencePartyMuteDigits muteDigits = new ConferencePartyMuteDigits('*', '#');
                            ConferencePartyMediaSettings settings = new ConferencePartyMediaSettings(
                                null, null, false, '\0', muteDigits);
                            settings.SuppressDtmf = false;
    
                            // Uncomment this to start the party muted. 
                            // settings.StartMuted = true;
    
                            if (conferenceChannel.CallConferenceRoom(
                                conferenceId,
                                ConferencePartyType.TalkerAndListener,
                                ConferenceLifetimeControl.FullControl,
                                settings,
                                30) == CallState.Answered)
                            {
                                // Connect the calls together
                                if (!channel.Connect(conferenceChannel))
                                {
                                    channel.FilePlayer.Say(
                                        "Failed to connect to conference. Hanging up.");
                                    channel.HangUp();
                                }
                            }
                            else
                            {
                                channel.FilePlayer.Say(
                                    "Failed to call conference <say-as interpret-as='vxml:digits'>{0}</say-as>. Hanging up.",
                                    conferenceId);
                                channel.HangUp();
                            }
                        }
                        else
                        {
                            channel.FilePlayer.Say("No digits received. Hanging up.");
                        }
                    }
    
                    // Wait for the call to be Idle
                    channel.WaitForIdle(360);
                }
                catch (Exception e)
                {
                    this.Trace.TraceError("Exception thrown {0}", e.Message);
                    reply = ReturnCode.ExceptionThrown;
                }
    
                this.Trace.TraceInfo("Completed");
                return (int)reply;
            }
        }
    }
  • Filename:

    Samples\VB\ConnectToConference\ConnectToConference.vb

    Description:

    We ask for a four digit PIN code, representing the conference ID number, receive it using DTMF detection and then repeat the number back to the caller for confirmation. We can then use the CallConferenceRoom() method, that will call the conference on the extra channel supplied. This conference is configured to produce silence on the line until someone else enters the conference.

    We construct a ConferencePartyMediaSettings object to allow us to disable DTMF suppression which is enabled by default. The conference is configured to produce silence on the line until someone else enters the conference room.

    Code:

    Imports AMSClassLibrary
    Imports UASAppAPI
    
    ' An inbound application that prompts the user to enter a 4-digit pin that represents 
    ' the id of a conference to which they are then connected.
    '
    ' Requires:
    ' [1 extra channel]
    Namespace ConnectToConference
    
        ' The application class.
        ' This must have the same name as the assembly and must inherit from either 
        ' UASInboundApplication or UASOutboundApplication.
        ' It must override the Run method.
        Public Class ConnectToConference
            Inherits UASInboundApplication
    
            ' Possible return codes
            Enum ReturnCode
                ' Success Codes:
                Success = 0
                ' ... any positive integer
    
                ' Fail Codes:
                ' -1 to -99 reserved
                ExceptionThrown = -100
                NotSufficientExtraChannels = -101
            End Enum
    
            ' This is the entry point for the application
            Overrides Function Run(ByVal channel As UASCallChannel, _
                                   ByVal applicationParameters As String) _
                                   As Integer
    
                Me.Trace.TraceInfo("Started")
                Dim reply As ReturnCode = ReturnCode.Success
                Dim conferenceId As String
    
                ' Check we've got an extra Channel
                If channel.ExtraChannels.Length < 1 Then
                    Me.Trace.TraceWarning("Needs 1 extra channel to be configured")
                    Return ReturnCode.NotSufficientExtraChannels
                End If
                Dim conferenceChannel = channel.ExtraChannels(0)
    
                Try
                    ' Answer the call
                    Dim state As CallState
                    state = channel.Answer()
    
                    If state = CallState.Answered Then
                        Me.Trace.TraceInfo("Call answered")
    
                        ' Prompt for a conference id, enabling bargein
                        channel.FilePlayer.Say("Please Enter a four digit conference i d.", True)
    
                        Dim digits As String = ""
                        Dim cause = channel.DtmfDetector.GetDigits(4, digits, 30)
                        If cause = DtmfDetectorCause.Count Then
                            conferenceId = digits
    
                            ' Inform the caller what is happening
                            channel.FilePlayer.Say( _
                                "Adding you to conference <say-as interpret-as='vxml:digits'>{0}</say-as>", _
                                conferenceId)
    
                            ' Create settings to determine how the party is connected to the conference room
                            Dim muteDigits = New ConferencePartyMuteDigits("*", "#")
                            Dim settings = New ConferencePartyMediaSettings(Nothing, Nothing, False, "\0", muteDigits)
                            settings.SuppressDtmf = False
    
                            ' Uncomment this to start the party muted. 
                            ' settings.StartMuted = True;
    
                            If (conferenceChannel.CallConferenceRoom( _
                                conferenceId, _
                                ConferencePartyType.TalkerAndListener, _
                                ConferenceLifetimeControl.FullControl, _
                                settings, _
                                30) = CallState.Answered) Then
                                ' Connect the calls together
                                If Not channel.Connect(conferenceChannel) Then
                                    channel.FilePlayer.Say( _
                                        "Failed to connect to conference. Hanging up.")
                                    channel.HangUp()
                                End If
                            Else
                                channel.FilePlayer.Say( _
                                    "Failed to call conference <say-as interpret-as='vxml:digits'>{0}</say-as>. Hanging up.", _
                                    conferenceId)
                                channel.HangUp()
                            End If
                        Else
                            channel.FilePlayer.Say("No digits received. Hanging up.")
                            channel.HangUp()
                        End If
                    End If
    
                    ' Wait for 10min for the call to be Idle
                    channel.WaitForIdle(60 * 10)
    
                Catch ex As Exception
                    Me.Trace.TraceError("Exception thrown {0}", ex.Message)
                    reply = ReturnCode.ExceptionThrown
                End Try
    
                Me.Trace.TraceInfo("Completed")
                Return reply
    
            End Function
    
        End Class
    
    End Namespace