Calling via TAPI

posted on Oct 14 by admin in the Tutorials category
Featured Post Image

Some days ago i finished a project which was about using the TAPI. I will give you a short introduction into TAPI and give my example for that project.

Here a short description about what TAPI is.
The Telephony Application Programming Interface (TAPI) is a Microsoft Windows API, which provides computer telephony integration and enables PCs running Microsoft Windows to use telephone services.
With it you can control a telephone which uses this TAPI. You can listen for calls, make calls and many other things.

For this project I only needed to make a call by clicking on a number in the browser, of course it should work in every browser.
First of all we will check how to get the number from the browser to the telephone. A client has installed the telephone so we need a client solution. So what can we do on the client to pass a number as parameter via TAPI to a telephone? Probably via desktop command line application which is using the TAPI-Library.
Okay now we know how will communicate with the telephone, but how will that application get the number from browser?
On way could be via Javascript, which is probably not realizable. The other choice and I think that’s the last option we have is to register a new protocol, like HTTP. So we have for example something like “phone:0123456789″ instead of “http://…”.

How can we register such a protocol now?
I don’t know how to do that on UNIX Systems but on Windows we just need a registry entry!

REGEDIT4

[HKEY_CLASSES_ROOT\PROTOCOL_NAME]
@=”URL:PROTOCOL_NAME Protocol”
“URL Protocol”=”"

[HKEY_CLASSES_ROOT\PROTOCOL_NAME\shell]
[HKEY_CLASSES_ROOT\PROTOCOL_NAME\shell\open]
[HKEY_CLASSES_ROOT\PROTOCOL_NAME\shell\open\command]
@=”\”PATH_TO_EXE\” \”%1\”"

By replacing the PROTOCOL_NAME with your own protocol and the PATH_TO_EXE with the absolute path to your exe file you can pass parameters to the program.

tapi.reg

REGEDIT4

[HKEY_CLASSES_ROOT\phone]
@=”URL:phone Protocol”
“URL Protocol”=”"

[HKEY_CLASSES_ROOT\phone\shell]
[HKEY_CLASSES_ROOT\phone\shell\open]
[HKEY_CLASSES_ROOT\phone\shell\open\command]
@=”\”C:\\TAPI\\TapiCall.exe\” \”%1\”"

The %1 is for a parameter, you will get that parameter through the arguments in the main method.
I have made a batch file which installs the the whole thing…

install.bat

mkdir “C:\TAPI”
copy Interop.TAPI3Lib.dll “C:\TAPI”
copy TapiCall.exe “C:\TAPI”
tapi.reg

This batch file creates the directory TAPI on C: and copies the files which are needed and finally executes the regedit file.
Now we just need the program which sends the number to the TAPI-Device.
I decided to use C# because I found a TAPI Library for C# and of course because I know C# really good.
It is easy to make programs with C#, you can be really fast and the community is really big.
I used an example from Codeprojects to test the dialing process and the final solution look like that…

Mainmethod

Here you can see the main method which takes the main parameters and parses it.
Don’t forget to include the TAPI-Library.

Tapilib

Finally the call method which takes the number as string. Here i use the line which name contains “Agfeo” because the TAPI devices are from Agfeo.

Callmethod

When you click on a link now which has the value phone:123456 in the href attribute the program sends the number 123456 to the TAPI device to and starts the call.
This is a browser independent solution of using your own protocol on a windows machine via browsers.
I hope this helped you a bit if you try to make something like that.

The Visual Studio Project is in the source files which you can download here.

TAPI Project Files

2 Comments

criscap85, postet this comment on Sep 17th, 2012

Hi,
interesting project. But it works in console or? I’m trying to make a program that makes use of the libraries TAPI. In practice I have to make sure that the server is connected to the exchange and the client using a button on a small interface to call other clients in the network and outside. How can I do? Do you have the right path? Thank you so much for any future response.

admin, postet this comment on Sep 17th, 2012

Well this is made for the console which can be applied to a protocol like “phone” to make use of it in a webapp.
Anyway you could also just make the calls that are made in the main method in something like an onclick event handler of a button.
Basically you instantiate the TapiCall class, initialize it and the you can pass in numbers as string via the “call” method to actually initiate a call.
I am not sure if the calls can be made via network, even though I didn’t look for such features when I last read the docs about TAPI.
The exchange thing is something that you will have to handle yourself, but as I said you can totally reuse the code to just initiate a call.

Leave a Response