Transfer the Call

Now, it is time to learn how to transfer a call to another phone number and how to handle DTMF simply. First of all, please install an API Extension and subscribe to Incoming Call URL using the URL of your application.

Now, you can learn how to transfer a call to another number and how to handle DTMF simply. First of all, please login and connect to the API Extension. Wait for an Incoming call, and when it is occured just use the BlindTransfer method on the call.

Example code coming soon...
[HttpPost]
public ActionResult RouteCall(string notificationName, string callLegID, 
string caller, string apiExtension)
{
	return Content(
	"<Response>" +
	  "<UserInput timeout=\"10\" repeat=\"true\">" +
		"<InitialCommands>" +
		  "<Speak>Hello</Speak>  " +
		  "<Speak>To transfer the call to 882 Extension, press 1.</Speak>" +
		"</InitialCommands>" +
		"<Inputs>" +
		  "<Input key=\"1\">" +
			"<BlindTransfer>882</BlindTransfer>" +
			"<Speak>Sorry, but blind transfer failed to extension 882. 
			Please setup an extension in the system.</Speak>" +
		  "</Input>" +
		"</Inputs>" +
	  "</UserInput>" +
	"</Response>", "text/xml");
}
class TransferCallController < ApplicationController
  protect_from_forgery except: :index

  # In routes.rb you need to set the following routing rule
  # post '/transfer_call' => 'transfer_call#index'
  
  def index

    render :xml => '<?xml version="1.0" encoding="UTF-8"?>
    <Response>
      <UserInput timeout="10" repeat="true">
        <InitialCommands>
          <Speak>Hello</Speak>
          <Speak>To transfer the call to 882 Extension, press 1.</Speak>
        </InitialCommands>
        <Inputs>
          <Input key="1">
            <BlindTransfer>882</BlindTransfer>
            <Speak>Sorry, but blind transfer failed to extension 882. 
            Please setup an extension in the system.</Speak>
          </Input>
        </Inputs>
      </UserInput>
    </Response>'

  end

end
<?php
	print "<Response>";
		print "<UserInput timeout=\"10\" repeat=\"true\">";
			print "<InitialCommands>";	
				print "<Speak>Hello</Speak>";	
				print "<Speak>To transfer the call to 882 Extension, press 1.</Speak>";	
			print "</InitialCommands>";	
			print "<Inputs>";	
				print "<Input key=\"1\">";
					print "<BlindTransfer>882</BlindTransfer>";	
					print "<Speak>Sorry, but blind transfer failed to extension 882. 
					Please setup an extension in the system.</Speak>";
				print "</Input>";
			print "</Inputs>";	
		print "</UserInput>";
	print "</Response>";
?>
#!c:/Perl64/bin/perl.exe   
print "Content-Type: text/plain\n\n";
#You have to add the directory route of perl.exe, and print the content type

#Send response
print 
'<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <UserInput timeout="10" repeat="true">
    <InitialCommands>
      <Speak>Hello</Speak>			
      <Speak>To transfer the call to 882 Extension, press 1.</Speak>
    </InitialCommands>
    <Inputs>
      <Input key="1">
        <BlindTransfer>882</BlindTransfer>
        <Speak>Sorry, but blind transfer failed to extension 882. 
        Please setup an extension in the system.</Speak>
      </Input>
    </Inputs>
  </UserInput>
</Response>'
Imports OPSSDK
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)
                                             Console.WriteLine(info.Message)
                                         End Sub

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

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

    Private Sub IncomingCall(sender As Object, e As VoIPEventArgs(Of ICall))
        Dim [call] = e.Item

        AddHandler [call].CallStateChanged,
            Sub(s, ev)
                If ev.Item = CallState.Answered Then
                    [call].BlindTransfer("882") 'please add existing extension
                End If
            End Sub

        [call].Accept()
    End Sub
End Module
def application(environ, start_response):
   
    result = receiveCall(environ)

    response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(result)))]
    start_response('200 OK', response_headers)

    return [result]

def receiveCall(environ):
    transferNumber = "882"
    
    return """<?xml version="1.0" encoding="UTF-8"?>
            <Response>
              <UserInput timeout="10" repeat="true">
                <InitialCommands>
                  <Speak>Hello</Speak>			
                  <Speak>To transfer the call to {0} Extension, press 1.</Speak>
                </InitialCommands>
                <Inputs>
                  <Input key="1">
                    <BlindTransfer>{0}</BlindTransfer>
                    <Speak>Sorry, but blind transfer failed to extension {0}. 
                    Please setup an extension in the system.</Speak>
                  </Input>
                </Inputs>
              </UserInput>
            </Response>""".format(transferNumber)
using System;
using OPSSDK;
using OPSSDKCommon.Model.Call;
using Ozeki.VoIP;

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

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

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

        private static void IncomingCall(object sender, VoIPEventArgs e)
        {
            var call = e.Item;

            call.CallStateChanged += (s, ev) =>
            {
                if (ev.Item == CallState.Answered)
                    call.BlindTransfer("882"); //please add existing extension
            };

            call.Accept();
        }
    }
}
package pbxsampleapp;

import com.sun.net.httpserver.*;
import java.io.*;
import java.net.*;

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

    static class PBXRequestHandler implements HttpHandler
    {
        @Override
        public void handle(HttpExchange httpExchange) throws IOException
        {
            String response = "<Response>"
                    + "<UserInput timeout=\"10\" repeat=\"true\">"
                    + "<InitialCommands>"
                    + "<Speak>Hello</Speak>  "
                    + "<Speak>To transfer the call to 882 Extension, press 1.</Speak>"
                    + "</InitialCommands>"
                    + "<Inputs>"
                    + "<Input key=\"1\">"
                    + "<BlindTransfer>882</BlindTransfer>"
                    + "<Speak>Sorry, but blind transfer failed to extension 882." 
                    +        "Please setup an extension in the system.</Speak>"
                    + "</Input>"
                    + "</Inputs>"
                    + "</UserInput>"
                    + "</Response>";
            httpExchange.getResponseHeaders().add("Content-type", "text/xml");
            httpExchange.sendResponseHeaders(200, response.length());
            OutputStream os = httpExchange.getResponseBody();
            os.write(response.getBytes());
            os.close();
        }
    }
}
Code example 1 - Transfer a call by pressing button

The program will send back the OzML response to the caller. When you called, the caller is informed about the possibility of call transferring. If the Caller press the 1 button, he is transferred to the “882” telephone number by BlindTransfer command.

If the transferring is not successful, the Caller is informed about that. You can add more InitialCommands, or more Input keys with various actions.

IN MORE DETAILS

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 and the CallErrorOccurred events of the call object and Accept the call.

The CallStateChanged event will trigger 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 incoming call is Answered by the Accept() command, the program executes the BlindTransfer (transferNumber) method of the call. It is a simple method, what is automatically try to connect the actual caller to the given telephone number. If the given telephone number is not registered in your PBX, the CallState will step back the previous call state, in this case it will be InCall() again.

With these steps you learned how to transfer a call.

Next: Make an outbound call

More information