Computer-Telephony Integration and Grandstream Phones







More and more modern means of communication are being integrated into the world around us, and office telephony is no exception. Grandstream decided not to lag behind and added support for a special CTI interface (Computer-Telephony Integration) to their phones. Initially, the GXP21XX series devices were updated, and later, the devices of the younger GXP16XX series, such as the GXP1610 , GXP1620 , etc., were updated .







In fact, the โ€œCTI interfaceโ€ is loudly said, in reality, a small REST API that allows you to control your phone using simple HTTP requests. It would seem: to initiate a call, to track the status of the lines used by the phone, it is possible on the PBX, but using, for example, a cloudy IP PBX, it is not always possible. In addition to this, CTI allows you to control speakerphone, speaker volume, microphone mute, etc., which is not always realizable at the PBX level.







So what can we do with CTI? In general, not very much, only five types of requests are available to us:







Request Description
api-get_line_status Line condition
api-get_phone_status Phone status
api-send_key Pressing a key (0-9, #, *, context-sensitive, etc.)
api-phone_operation The simplest manipulations with the phone (take a call, reset, etc.)
api-sys_operation Allows you to restart and reset the device to factory settings


It is very simple to use it, we form request of a type:







"http://IP  /cgi-bin/api-get_line_status?passcode=" // (     )
      
      





In response, we get a JSON of the form:







 { "response": "success", "body": [ { "line": 1, "state": "idle", "acct": 1, "active": 0, "remotename": "", "remotenumber": "" }, { "line": 2, "state": "connected", "acct": 2, "active": 1, "remotename": "", "remotenumber": "203" }, { "line": 3, "state": "idle", "acct": 1, "active": 0, "remotename": "", "remotenumber": "" }, ... { "line": 8, "state": "idle", "acct": 1, "active": 0, "remotename": "", "remotenumber": "" } ] }
      
      





Replacing the api-get_line_status request with api-get_phone_status, we will get a brief information on the telephone:







 { "response": "success", "body": "busy", "misc": "0" }
      
      





This method is convenient when we just need to interrogate the state of the device or telephone lines and is very inconvenient in cases when we want to track changes that are taking place. Received a call, we would take the incoming number and show the user a notification, but how to do it? We donโ€™t have the opportunity to subscribe to any events. Two or three times a second, itโ€™s not a good decision to peck the phone with state requests. Unfortunately, in this situation, CTI is not an assistant.







We look further, api-send_key , as the name implies, serves this request to send keystrokes on the phone, you can send one by one or several at once. Actually, pressing the transmitted keys is initiated at intervals of about a second and this process cannot be interrupted. At the same time, the keys on the phone are not blocked and they can be pressed freely, as a result, the phone executes into an incomprehensible โ€œmessโ€.







 "http://192.168.4.118/cgi-bin/api-send_key?passcode=admin&keys=LINE2:2:0:3:SEND"
      
      





As you can see, another keys parameter has been added, indicating which keys to press. (A table with a list of all the keys that can be virtually pressed is in the CTI documentation.)







The first thing that comes to mind is: โ€œBut would you not write a browser extension that would allow you to initiate a call directly from it?โ€. The simplest option was not long in coming. Since I have the main browser Google Chrome, I wrote for it, it took only something to create two files:







 // manifest.json { "manifest_version": 2, "name": "ArtDial", "version": "0.1", "permissions": ["contextMenus"], "background": { "scripts": ["background.js"] } }
      
      





 // background.js function dial(selectedText) { var serviceCall = 'http://192.168.4.118/cgi-bin/api-send_key?passcode=admin&keys='+ selectedText.replace(/[^\d]/g, '').split('').join(':') +':SEND'; var xhr = new XMLHttpRequest(); xhr.open("GET", serviceCall, true); xhr.send(); } chrome.contextMenus.create({ title: ": %s", contexts: ["selection"], onclick: function(info, tab) { dial(info.selectionText); } });
      
      





We put them in one folder, on the extensions page, turn on the developer mode and enable our extension.



















For call management, an api-phone_operation request is provided, with its help we can accept or reject an incoming call (acceptcall / rejectcall), put on hold or end the current call (holdcall / endcall). A more universal cancel command is also available, allowing you to reject and terminate calls. For sending we use a request of the form:







 "http://192.168.4.118/cgi-bin/api-phone_operation?passcode=admin&cmd=cancel"
      
      





And the latest: api-sys_operation , will allow us to restart the phone, or reset it to the factory settings (REBOOT and RESET, respectively). We use queries of the form:







 "http://192.168.4.118/cgi-bin/api-sys_operation?passcode=admin&request=REBOOT"
      
      





Using only Computer-Telephony Integration is unlikely to be able to create a rollicking application that will fully interact with your environment. But as an additional tool used in conjunction with other APIs (Action URL on phones or AMI in Asterisk), CTI has a right to exist.








All Articles