right  Talk To Us!

UAS API - Uas Connection Test Sample Application

  • Filename:

    samples/uas_connection_test.py

    Description:

    This is an inbound application that rings the call for 2 seconds, answers the call, then reads out some text.

    The application grabs the host name and, if application_parameters is not an empty string, it will get that too (application_parameters is configured on the Inbound Services page). The call is then rung and answered using the channel.ring() and channel.answer() functions. A welcome message is played which contains machine's host name and the text from application_parameters.

    Code:

    """
        This is an inbound application that rings the call for 2 seconds, 
        answers the call, then reads out the following text::
    
        "Welcome to your U.A.S application."
        "The voice you are hearing has been commanded by your machine."
        "The hostname of the machine is <hostname>."
        "The application parameter supplied to the application is <application_parameters>. Goodbye."
    
    """
    
    __uas_identify__ = "application"
    __uas_version__ = "1.0b3"
    
    import sys, os, socket
    from prosody.uas import Hangup, Error
    
    def main(channel, application_instance_id, file_man, my_log, application_parameters):
        log_pref = "connection_test"
        call_to = channel.Details.call_to
        my_log.info("{0} started with call_to [{1}]".format(log_pref, call_to))
    
        #grab the machine hostname
        hostname = socket.gethostname()
    
        # Our default text for the application_parameters are "Nothing", which is replaced if there's any text to play
        test_args = "Nothing"
        if application_parameters != "":
            test_args = application_parameters
    
        # The main program
        try:
            # ring for two seconds
            channel.ring(2)
            # answer the call
            channel.answer()
            # say some text. The text is converted to speech using an inbuilt Text-To-Speech (TTS) converter
            channel.FilePlayer.say("Welcome to your U.A.S application. \
                                    The voice you are hearing has been commanded by your machine. \
                                    The hostname of the machine is {0}. \
                                    The application parameters supplied to the application are {1}. Goodbye.".format(hostname, test_args))
            # Hang up the call!
            channel.hang_up()
            
        except Hangup as exc:
            my_log.info("{0} completed with Hangup".format(log_pref))
    
        except Error as exc:
            my_log.error("{0} completed with Error exception! {1}".format(log_pref, exc))
            return -101
    
        except Exception as exc:
            my_log.exception("{0} completed with exception! {1}".format(log_pref, exc))
            return -102
    
        my_log.info("{0} completed".format(log_pref))
        return 0
    
  • Filename:

    Samples\C#\UASConnectionTest\UASConnectionTest.cs

    Description:

    When this application starts, we log the caller and then grab the hostname of the machine from System.Environment.MachineName. We then access the applicationParameters argument, that is specified in the calling inbound service on the Cloud and sent to our application when it is run on our UAS. If there's anything in the parameter list we store it in parametersToSay. Otherwise we set parametersToSay to be "Empty".

    The application simulates the phone ringing with channel.Ring(2), answers the call with channel.Answer() and then uses Text-To-Speech (TTS) to convert some text to voice data. The text to say includes the hostname, gathered from the above code, just to confirm to the user that the UAS is running on their local machine. Additionally, the parametersToSay are played. Finally, the channel is disconnected with channel.HangUp.

    Code:

    using System;
    using System.Threading;
    using AMSClassLibrary;
    using UASAppAPI;
    
    // A simple inbound application that rings the call for 2 seconds, 
    // answers the call, then reads out some text including the machine name on 
    // which the UAS is running and the application parameters sent to the 
    // application, before hanging up.
    //
    // Requires:
    // [applicationParameters = the text to say]
    namespace UASConnectionTest
    {
        public class UASConnectionTest : UASInboundApplication
        {
            public override int Run(UASCallChannel channel,
                                    string applicationParameters)
            {
                string callTo = channel.CallDetails.CallTo;
                this.Trace.TraceInfo("Call started with callTo [{0}]", callTo);
    
                // Grab the machine hostname
                string hostname = System.Environment.MachineName;
    
                // Set what to say if applicationParameters is empty 
                string parametersToSay = "Empty";
                if (applicationParameters.Length > 0)
                {
                    parametersToSay = applicationParameters;
                }
    
                try
                {
                    // Ring for two seconds
                    channel.Ring(2);
    
                    // Answer the call
                    channel.Answer();
            
                    // Say some text. 
                    // The text is converted to speech using the inbuilt Text-To-Speech (TTS) converter
                    channel.FilePlayer.Say("Welcome to your U A S application. " + 
                                           "The voice you are hearing has been commanded by your machine. " +
                                           "The hostname of the machine is {0}.", 
                                           hostname);
                    channel.FilePlayer.Say("The application parameter supplied to the application is {0}.",
                                           parametersToSay);
                    channel.FilePlayer.Say("Goodbye.");
                }
                catch (Exception e)
                {
                    this.Trace.TraceError("Exception thrown {0}", e.Message);
                }
                finally
                {
                    // Hang up the call
                    channel.HangUp();
                }
    
                this.Trace.TraceInfo("Completed");
                return 0;
            }
        }
    }
  • Filename:

    Samples\VB\UASConnectionTest\UASConnectionTest.vb

    Description:

    When this application starts, we log the caller and then grab the hostname of the machine from System.Environment.MachineName. We then access the applicationParameters argument, that is specified in the calling inbound service on the Cloud and sent to our application when it is run on our UAS. If there's anything in the parameter list we store it in parametersToSay. Otherwise we set parametersToSay to be "Empty".

    The application simulates the phone ringing with channel.Ring(2), answers the call with channel.Answer() and then uses Text-To-Speech (TTS) to convert some text to voice data. The text to say includes the hostname, gathered from the above code, just to confirm to the user that the UAS is running on their local machine. Additionally, the parametersToSay are played. Finally, the channel is disconnected with channel.HangUp.

    Code:

    Imports AMSClassLibrary
    Imports UASAppAPI
    
    ' A simple inbound application that rings the call for 2 seconds, 
    ' answers the call, then reads out some text including the machine name on 
    ' which the UAS is running and the application parameters sent to the 
    ' application, before hanging up.
    '
    ' Requires:
    ' [applicationParameters = the text to say]
    Namespace UASConnectionTest
    
        Public Class UASConnectionTest
            Inherits UASInboundApplication
    
            Overrides Function Run(ByVal channel As UASCallChannel, _
                                   ByVal applicationParameters As String) _
                                   As Integer
    
                Dim callTo = channel.CallDetails.CallTo
                Me.Trace.TraceInfo("Call started with callTo [{0}]", callTo)
    
                ' Grab the machine hostname
                Dim hostname = System.Environment.MachineName
    
                ' Set what to say if applicationParameters is empty 
                Dim parametersToSay = "Empty"
                If applicationParameters.Length > 0 Then
                    parametersToSay = applicationParameters
                End If
    
                Try
                    ' Ring for two seconds
                    channel.Ring(2)
    
                    ' Answer the call
                    channel.Answer()
    
                    ' Say some text. 
                    ' The text is converted to speech using the inbuilt Text-To-Speech (TTS) converter
                    channel.FilePlayer.Say("Welcome to your U A S application. " + _
                                           "The voice you are hearing has been commanded by your machine. " + _
                                           "The hostname of the machine is {0}.", _
                                           hostname)
                    channel.FilePlayer.Say("The application parameter supplied to the application is {0}.", _
                                           parametersToSay)
                    channel.FilePlayer.Say("Goodbye.")
                Catch e As Exception
                    Me.Trace.TraceError("Exception thrown {0}", e.Message)
                Finally
                    ' Hang up the call
                    channel.HangUp()
                End Try
    
                Me.Trace.TraceInfo("Completed")
                Return 0
    
            End Function
    
        End Class
    
    End Namespace
  • Filename:

    Samples\F#\UASConnectionTest\UASConnectionTest.fs

    Description:

    When this application starts, we log the caller and then grab the hostname of the machine from System.Environment.MachineName. We then access the applicationParameters argument, that is specified in the calling inbound service on the Cloud and sent to our application when it is run on our UAS. If there's anything in the parameter list we store it in parametersToSay. Otherwise we set parametersToSay to be "Empty".

    The application simulates the phone ringing with channel.Ring(2), answers the call with channel.Answer() and then uses Text-To-Speech (TTS) to convert some text to voice data. The text to say includes the hostname, gathered from the above code, just to confirm to the user that the UAS is running on their local machine. Additionally, the parametersToSay parameter is played. Finally, the channel is disconnected with channel.HangUp and we return 0 to indicate success.

    Code:

    // A simple inbound application that rings the call for 2 seconds, 
    // answers the call, then reads out some text including the machine name on 
    // which the UAS is running and the application parameters sent to the 
    // application, before hanging up.
    //
    // Requires:
    // [applicationParameters = the text to say]
    namespace UASConnectionTest
    
        open AMSClassLibrary
        open UASAppAPI
        open System.Threading
    
        // 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.
        type UASConnectionTest() = 
            inherit UASInboundApplication()
    
            // This is the entry point for the application
            override obj.Run(channel:UASCallChannel, applicationParameters:string) : int = 
    
                let callTo = channel.CallDetails.CallTo
                obj.Trace.TraceInfo("Call started with callTo [{0}]", callTo)
    
                // Grab the machine hostname
                let hostname = System.Environment.MachineName
    
                // Set what to say if applicationParameters is empty 
                let parametersToSay = if (applicationParameters.Length > 0) then applicationParameters else "Empty"
    
                try
                    try
                        // Ring for two seconds
                        channel.Ring(2) |> ignore
    
                        // Answer the call
                        channel.Answer() |> ignore
            
                        // Say some text. 
                        // The text is converted to speech using the inbuilt Text-To-Speech (TTS) converter
                        channel.FilePlayer.Say("Welcome to your U A S application. " + 
                                               "The voice you are hearing has been commanded by your machine. " +
                                               "The hostname of the machine is {0}.", 
                                               hostname) |> ignore
                        channel.FilePlayer.Say("The application parameter supplied to the application is {0}.",
                                               parametersToSay) |> ignore
                        channel.FilePlayer.Say("Goodbye.") |> ignore
                    with
                        | _ as e ->
                            obj.Trace.TraceError("Exception thrown {0}", e.Message)
                finally
                    // Hang up the call
                    channel.HangUp() |> ignore
    
                obj.Trace.TraceInfo("Completed")
                0
                
  • Filename:

    Samples\C++\UASConnectionTest\UASConnectionTest.cpp

    Description:

    When this application starts, we log the caller and then grab the hostname of the machine from System::Environment::MachineName. We then access the applicationParameters argument, that is specified in the calling inbound service on the Cloud and sent to our application when it is run on our UAS. If there's anything in the parameter list we store it in parametersToSay. Otherwise we set parametersToSay to be "Empty".

    The application simulates the phone ringing with channel->Ring(2), answers the call with channel->Answer() and then uses Text-To-Speech (TTS) to convert some text to voice data. The text to say includes the hostname, gathered from the above code, just to confirm to the user that the UAS is running on their local machine. Additionally, the parametersToSay are played. Finally, the channel is disconnected with channel->HangUp.

    Code:

    // This is the main DLL file.
    
    #include "stdafx.h"
    #include "UASConnectionTest.h"
    
    // A simple inbound application that rings the call for 2 seconds, 
    // answers the call, then reads out some text including the machine name on 
    // which the UAS is running and the application parameters sent to the 
    // application, before hanging up.
    //
    // Requires:
    // [applicationParameters = the text to say]
    namespace UASConnectionTest 
    {
    	// Possible return codes
    	enum ReturnCode
    	{
    		// Success Codes:
    		Success = 0
    		// ... any positive integer
    
    		// Fail Codes:
    		// -1 to -99 reserved
    	};
    
    	// This is the entry point for the application
    	int UASConnectionTest::Run(UASCallChannel^ channel, String^ applicationParameters)
    	{
    		String^ callTo = channel->CallDetails->CallTo;
    		this->Trace->TraceInfo("Call started with callTo [{0}]", callTo);
    
    		// Grab the machine hostname
    		String^ hostname = System::Environment::MachineName;
    
    		// Set what to say if applicationParameters is empty 
    		String^ parametersToSay = "Empty";
    		if (applicationParameters->Length > 0)
    		{
    			parametersToSay = applicationParameters;
    		}
    
    		try
    		{
    			// Ring for two seconds
    			channel->Ring(2);
    
    			// Answer the call
    			array<String^>^ emptyCodecs = gcnew array<String^>(0);
    			channel->Answer(emptyCodecs);
    
    			// Say some text. 
    			// The text is converted to speech using the inbuilt Text-To-Speech (TTS) converter
    			channel->FilePlayer->Say("Welcome to your U A S application. " + 
    									 "The voice you are hearing has been commanded by your machine. " +
    									 "The hostname of the machine is {0}.", 
    									 hostname);
    			channel->FilePlayer->Say("The application parameter supplied to the application is {0}.",
    									 parametersToSay);
    			channel->FilePlayer->Say("Goodbye.");
    		}
    		catch (Exception^ e)
    		{
    			this->Trace->TraceError("Exception thrown {0}", e->Message);
    		}
    		finally
    		{
    			// Hang up the call
    			channel->HangUp();
    		}
    
    		this->Trace->TraceInfo("Completed");
    
    		return Success;
    	};
    }