Say Hello

Now, get to know how to say an automated greeting message when you have an incoming call. When your installed API Extension gets a call, it will be forwarded to the Incoming call URL to your application. For better understanding please select your programming language and check the following code example.

Now, get to know how to say an automated greeting message when you have an incoming call. First of all, please login and connect to the API Extension. Wait for an Incoming call, and when it is occured just attach a TextToSpeech engine into the call and add the "Hello" as Text.

Next: Greet Caller by Name

Example code coming soon...
public ActionResult SayHello(string notificationName, string callLegID, string caller, string apiExtension)
	return Content(
	"<Response>" +
		"<Speak>Hello!</Speak>" +
	"</Response>", "text/xml");
class SayHelloController < ApplicationController

  protect_from_forgery except: :index

  # In routes.rb you need to set the following routing rule
  # post '/say_hello' => 'say_hello#index'
  def index
    render :xml => '<?xml version="1.0" encoding="UTF-8"?>

	print "<Response>";
		print "<Speak>Hello</Speak>";
	print "</Response>";
print "Content-Type: text/plain\n\n";
#You have to add the directory route of perl.exe, and print the content type

#Send response by print
'<?xml version="1.0" encoding="UTF-8"?>
Imports OPSSDK
Imports Ozeki.Media.MediaHandlers
Imports OPSSDKCommon.Model.Call
Imports Ozeki.VoIP

Module Module1
    Public Sub Main(args As String())
        Dim client = New OpsClient()
        AddHandler client.ErrorOccurred, Sub(sender, info)
                                         End Sub

        If Not client.Login("ozekixepbx.ip", "admin", "12345") Then
        End If

        Dim apiExtension = client.GetAPIExtension("9000")
        AddHandler apiExtension.IncomingCall, AddressOf IncomingCall
    End Sub

    Private Sub IncomingCall(sender As Object, e As VoIPEventArgs(Of ICall))
        Dim [call] = e.Item
        Dim tts = New TextToSpeech()
        AddHandler tts.Stopped, Sub(s, ev)
                                End Sub

        AddHandler [call].CallStateChanged, Sub(s, ev)
                                                If ev.Item = CallState.Answered Then
                                                ElseIf ev.Item.IsCallEnded() Then
                                                End If
                                            End Sub

    End Sub
End Module
def application(environ, start_response):
    result ="""
    <?xml version="1.0" encoding="UTF-8"?>
    response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(result)))]
    start_response('200 OK', response_headers)

    return [result]
using System;
using OPSSDK;
using OPSSDKCommon.Model.Call;
using Ozeki.Media.MediaHandlers;
using Ozeki.VoIP;

namespace OPS_QuickStartExample_CSharp
    class Program
        static void Main(string[] args)
            var client = new OpsClient();
            client.ErrorOccurred += (sender, info) =>

            if (!client.Login("ozekixepbx.ip", "admin", "12345"))

            var apiExtension = client.GetAPIExtension("9000");
            apiExtension.IncomingCall += IncomingCall;

        private static void IncomingCall(object sender, VoIPEventArgs e)
            var call = e.Item;
            var tts = new TextToSpeech();
            tts.Stopped += (s, ev) => call.HangUp();

            call.CallStateChanged += (s, ev) =>
                if (ev.Item == CallState.Answered)
                else if (ev.Item.IsCallEnded())

package pbxsampleapp;


public class SayHello 
     public static void main(String[] args)
            System.out.println("Starting http server...");
            HttpServer server = HttpServer.create(new InetSocketAddress(InetAddress.getByAddress(new byte[]{ 0, 0, 0, 0 }), 12345), 0);
            server.createContext("/sendsmstocaller", new PbxSampleApp.PBXRequestHandler());
            System.out.println("http server running on " + server.getAddress().toString());
        catch (IOException ex) { System.out.println("Error" + ex.toString()); }

    static class PBXRequestHandler implements HttpHandler
        public void handle(HttpExchange httpExchange) throws IOException
            httpExchange.getResponseHeaders().add("Content-type", "text/xml");
            String response = "<?xml version=\"1.0\"?>"
                    + "<Response>"
                    + "<Speak>Hello!</Speak>"
                    + "</Response>";
            httpExchange.sendResponseHeaders(200, response.length());
            OutputStream os = httpExchange.getResponseBody();
Code example 1 - Say “Hello” to the caller

The program will send back the OzML response to the API Extension and the caller. As you can see, it is just a simple Speak command. So when the application (the subscribing API Extension) will be called, the caller will hear a simple “Hello” message.

Get the OPSSDK.dll

First you need to add the OPSSDK.dll reference to your project
(You can find OPSSDK.dll at C:\Program Files\Ozeki\Ozeki Phone System\Examples\.NET API\OPSSDK.dll).

Login and connect

Create a new instance of OpsClient, and subscribe to the ErrorOccurred event. Your program will communicate with the Ozeki Phone System through this client. Try to login with the client into the running Ozeki Phone System, with the address of the server(ozekixepbx.ip) and a valid username, password combination.
If you are ready, try to get an existing API Extension, with the GetApiExtension method of the OpsClient. Read more about installation of API Extension.

Further steps

When you are ready with the initial steps above, subscribe the IncomingCall event of the apiExtension. This event will be triggered every time when the selected API Extension is called. In the mentioned event handler you will see the e.Item parameter, this parameter will be the call object. This call object has a CallState property, when the CallState is Ringing subscribe the CallStateChanged event of the call object and Accept the call.

The CallStateChanged event will be triggered when the call is going to another state . When the CallState is Answered, you can connect the devices to the call. When the call has ended, please do not forget to disconnect all devices from the call.

When the CallState is Answered, start and connect a TextToSpeech object to the call, that will read the "Hello" text to the caller. When the TextToSpeech is finished the call will hung up.

With these steps, you learned how to receive an incoming call, and say "Hello" to the caller.

Recommended reading

More information