Community Documentation

Making calls

Last updated February 17, 2012. Created by leoburd on March 2, 2011.
Edited by Fishboy1669, ben.bunk, Matt V.. Log in to edit this page.

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:

<?php
$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.

Page status

Needs technical review

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Programmers

Site Building Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.