Introduction
We are using Plivo PHP Server-side SDK (legacy version) to manage inbound calls. Recently I had to implement call blocking. Idea is simple - If inbound call in our system does not match certain rules, we hang up. For that hangup_call
function from RestAPI is used.
Piece of Code
When our system receives request with Event: StartApp
from Plivo, call controller calls StartCall
class function handle
. This function contains all logic for starting call(checking rules, saving call in data base, start recording, etc):
public function handle($data) {
// Finding caller from DB by callerNumber ...
// Finding campaign from DB by targetNumber ...
// Checking if caller already called in certain time interval (isDuplicate) ...
// Starting call - call MUST be saved in DB !
$call = Call::start($data["CallUUID"], $campaign, $caller, $isDuplicate);
$call->save();
try {
// Checking call rules, throwing exceptions and changing call status accordingly
$call->guardCall();
} catch (CountryNotAllowedException $e) {
// Hanging up if caller country not allowed
return $this->callsApi->hangUp($call);
}
// If everything went good waiting(Plivo addWait) for our systems waiting call service to find call consumer and execute transfer...
}
Note: hangUp
is function that contains hangup_call
alongside with some logging.
Testing
At the moment, for call testing we use skype with purchased US numbers since we are located in Europe.
For testing purposes, every call in this test does not pass rules - is blocked.
When testing this code everything seemed to work, but there is one issue - skype(caller) keeps connecting although Plivo ended call. In result, after our system receives Hangup
from Plivo a new call starts. And this is repeating in cycle until I manually end call in skype as caller.
Using addSpeak
or addWait
instead of hangup_call
works - speak or wait is executed and after that call ends.
I also tried use addHangup
with parameter reason: "rejected", but there was no difference.
Question
Why after hangup_call
is executed skype keeps connecting? (Call is not ended in caller side)
Could it be skype's peculiarity?
Maybe it is because we use legacy version SDK? Is there a big difference between latest and legacy Server-side SDK?