right  Talk To Us!

UAS API - Add To Conference Sample Application

  • Filename:

    samples/add_to_conference.py

    Description:

    This sample application will transfer 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 channel.transfer_to_conference() to transfer 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 transferred. 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 anbound call
            - wait for four DTMF digits
            - create a tone player
            - transfer the call to the conference room
            - wait for the caller to hang up
    
    """
    
    from prosody.uas import Hangup, Error, ToneManager
    
    __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)))
    
                # because this is a transfer, we need to create the tone player
                tone_manager = ToneManager(my_log)
                channel.create_tone_player(tone_manager)
                                        
                if channel.transfer_to_conference_room(out_channel, digits) is False:
                    my_log.error("Transfer 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 ("Transfer 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#\AddToConference\AddToConference.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 channel.TransferToConferenceRoom() method, that will manage the transfer for us, passing it one of the extra channels to use for the transfer.

    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 transferred.
    //
    // Note: this sample will only run on platforms that support Transfer.
    //
    // Requires:
    // [1 extra channel]
    namespace AddToConference
    {
        // 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 AddToConference : 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 targetChannel = 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 (!channel.TransferToConferenceRoom(
                                    conferenceId, targetChannel, ConferencePartyType.TalkerAndListener,
                                    ConferenceLifetimeControl.FullControl,
                                    settings, 30))
                            {
                                channel.FilePlayer.Say("Failed to transfer to conference. Hanging up.");
                                channel.HangUp();
                            }
                        }
                        else
                        {
                            channel.FilePlayer.Say("No digits received. Hanging up.");
                            channel.HangUp();
                        }
                    }
    
                    // Wait for 10min for the call to be Idle
                    channel.WaitForIdle(60 * 10);
                }
                catch (Exception e)
                {
                    this.Trace.TraceError("Exception thrown {0}", e.Message);
                    reply = ReturnCode.ExceptionThrown;
                }
    
                this.Trace.TraceInfo("Completed");
                return (int)reply;
            }
        }
    }
  • Filename:

    Samples\VB\AddToConference\AddToConference.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 channel.TransferToConference() method, that will manage the transfer for us, passing it one of the extra channels to use for the transfer. 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 transferred.
    '
    ' Note: this sample will only run on platforms that support Transfer.
    '
    ' Requires:
    ' [1 extra channel]
    Namespace AddToConference
    
        ' 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 AddToConference
            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 targetChannel = 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 Not channel.TransferToConferenceRoom( _
                                    conferenceId, targetChannel, ConferencePartyType.TalkerAndListener, _
                                    ConferenceLifetimeControl.FullControl, _
                                    settings, 30) Then
                                channel.FilePlayer.Say("Failed to transfer to conference. Hanging up.")
                                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