Advertising sustains the DA. Ads are hidden for members. Join today

Making calls

Last updated on
30 April 2025

You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules

VoIP Drupal’s voip.module defines a set of basic functions to manage server configuration as well as to make and cancel calls. In order to make a phone call from inside Drupal, the developer should invoke voip_dial() passing an instance of the VoipCall class as parameter:


  $call = new VoipCall();
  $phone_number = '+13331234567'; // use the phone number of your choice,
                                    // but make sure the number is authorized by
                                    // your VoIP server
  $call->setDestNumber($phone_number);
  $script_name = "voipscript_say_demo";
  $script = VoipScript::loadScript($script_name);
  $call->setScript($script);
  $result = voip_dial($call);
  if ($result) {
     watchdog('mymodule', "call successfully queued for $phone_number");
  }
  else {
     $msg = $call->getErrorMessage();
     $details = array('@msg' => $msg);
     watchdog('mymodule', 'Call failed with the following error: @msg',$details, WATCHDOG_WARNING);
  }

In the example above, voip_dial() places the call in a server queue and returns immediately.

In case the call fails for any reason (invalid number, non-authorized caller id, processing error, etc.), voip_dial() returns FALSE and the $call variable is updated with the failure description.

If the call is placed successfully, the system will then try execute the script defined by the $script variable.

Developers should periodically invoke $call->getCallStatus() to monitor the evolution of the call until it is hangup.

Note about getCallStatus or isHangup and outgoing_calls:
Because the outgoing call will almost certainly occur on a different thread/process you must use the following snippet to get the correct call status or you will be using a stale local copy of the call:

 $call = VoipCall::load($call->getCid());
 $status = $call->getCallStatus();

Other useful VoipCall methods include getStartTime(), getDuration(), and getAnsweredBy(). The latter can be used to determine whether the call has been answered by a human being or an answering machine.

Help improve this page

Page status: Not set

You can: