I'm trying to extend the functionality of a Drupal website to include Tropo service. I absolutely need to be able to access my Drupal database and the API that Drupal provides me for its own workings. I am fairly new at writing Drupal modules, but what seems to be happening right now is that Tropo cannot recognize my .module file as PHP, so it does not receive the JSON calls necessary.
I need either a) a way of getting Tropo to read from my .module file or b) a way of adding a regular .php file to my module such that I can still make all normal Drupal function calls AND Tropo can access my script.
Thoughts?
In Drupal, you cannot run the .module files directly from the web. Each module should implement hook_menu and that hook creates the URLs you'd use. So you'd give Tropo the URL that's created by yourmodule_menu, and not the path to yourmodule.module.
For example, here's a hook_menu from an example module for Tropo.
<?php
function demo_menu() {
$items = array();
// Set up a route for the incoming call
$items['demo/answer'] = array(
'page callback' => 'demo_answer',
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function demo_answer() {
module_load_include('php', 'tropo', 'lib/tropo/tropo.class');
$tropo = new Tropo();
$tropo->say('Hello. And Goodbye.');
print $tropo;
}
?>
The demo_menu function defines demo/answer as a URL on your site. If your site was at example.com you'd give Tropo your URL as http://example.com/demo/answer. Then when someone calls your Tropo phone number, the demo_answer() function would run, which speaks "Hello. And Goodbye." and then hangs up.
There's a simple demo module that I've used in a talk on using Drupal as a application framework that might help - I use Tropo extensively in the demo. https://github.com/akalsey/drupal-framework-demo
The Phone poll module would also be a good example. It uses Tropo to add voice and SMS to Drupal 6's built-in poll module. http://drupal.org/project/phonepoll
You might also want to have a look at VoipDrupal. This allows you to build scripts directly in Drupal that interact with services like Tropo. http://drupal.org/project/voipdrupal