The Subscribe method allows you to monitor extension for events such as:
- Answer
- Hangup
- Dial
- Connected
- Ringing
The Subscrive Subscribe uses a long poll method. After receiving a 'subscribe' request the server will wait upto up to "timeout" seconds for call 14.0 Events on the target extension(s).
The method will return as soon as any events occurs on one of the target extensions or when the timeout occurs.
To guarentee guarantee that you don't miss any events between calls to subscribe you use the 'seq' data returned by a call to subscribe as the value of lastSequenceNumber in the next call to subscribe.
This method can immeditately immediately return the current state of all requested extensions, use timeout=0 and lastSequenceNumber=0. There is actually a minimum poll period of around 100ms.
...
Sample response when two calls are received from 400 at extension 410. The first call arrives and the API returns, then the second call arrives and the API returns the information about the second call only. Both of the calls are rejected simultaneously and the final reponse response contains a Data resource with a collection of Extension resources (e.g. 400 in the sampe below). Each Extension resource contains an array of CallData resources. The associated uniqueCallId is used to asnwer answer a call (see below).
Code Block | ||
---|---|---|
| ||
https://127.0.0.1:8080/servicemanager/rest/CallManagementAPI/subscribe?timeOut=60& apiKey=f863246a-973e-11e6-8784-08002718f5b5&lastSequenceNumber=28&instanceId=1&exten=400,410,410 |
...
To answer the first call listed in the sample above use the uniqueCallId and pass it in as the uniqueId to the answer method:
Code Block | ||
---|---|---|
| ||
answer?answerString=...&apiKey=....&exten=101&uniqueId=1403148776.566 |
...
Code Block | ||
---|---|---|
| ||
{"Data":{ "410": [{"CallData":{ "canAnswer":false, "callerId":"400", "uniqueCallId":"1412749510.488", "callStartTime":"2014/10/08 17:25:18", "isQueueCall":false, "isClickToDialCall":false, "inbound":true, "status":"Hungup"},"CallID":2,"Code":0}], "400": [{"CallData":{ "canAnswer":false, "callerId":"410", "uniqueCallId":"1412749517.489", "callStartTime":"2014/10/08 17:25:18", "isQueueCall":false, "isClickToDialCall":false, "inbound":false, "status":"Hungup"},"CallID":1,"Code":0}]},"seq":10,"Code":0} |
Call 2: Extension 400 dials extension 410, 410 is busy.
Code Block | ||
---|---|---|
| ||
http://127.0.0.1:8080/servicemanager/rest/CallManagementAPI/subscribe?timeOut=60& apiKey=f863246a-973e-11e6-8784-08002718f5b5&lastSequenceNumber=10&instanceId=1&exten=400,410,410 |
...