views:

56

answers:

3

I'm wanting to insert SMS text messages into Drupal.

The SMS gateway is configured to forward the received message to a PHP script on our server and at the moment it's just inserting the message and the phone number into a database.

For example, the message is forwarded to http://www.example.com/smsupdate.php?phone=123445&text=message_content

How would I go about getting this data into Drupal?

+1  A: 

Depends on how you want to use it in Drupal. The easiest way is to write a module that defines a block (or it could be just a block with the PHP input filter in which you paste the code for the block), where you read the messages from the database and show them.

Wim
Well I just want it displayed as a blog post with the phone number as the title and the message as the actual blog entry.
Ste
+2  A: 

Creating content programmatically is easy in Drupal using node_save().

  $node = new stdClass();
  node_object_prepare($node);
  $node->title = $_GET['title'];
  $node->body = $_GET['text'];
  node_save($node)

You can keep this code in a separated .php file by calling drupal_bootstrap() before creating the node.

  chdir('/path/to/drupal');
  require_once('includes/bootstrap.inc');
  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

Another cleaner solution is to put everything in a small custom module and use hook_menu() to expose you handling code. See http://drupal.org/node/231276 for more information on module creation.

But beware that this let anyone who figured your URL schema create nodes on your website. You will probably need to protect access to your script. A secure solution may be to use the Services module to create node from your SMS gateway.

mongolito404
A: 

Could you schedule a cron job that connects to the database that stores the SMS message, pull it out, and utilize node_save() to save the data?

Kevin