<?php /* * This example script implements the EnvayaSMS API. * * It sends an auto-reply to each incoming message, and sends outgoing SMS * that were previously queued by example/send_sms.php . * * To use this file, set the URL to this file as as the the Server URL in the EnvayaSMS app. * The password in the EnvayaSMS app settings must be the same as $PASSWORD in config.php. */ require_once dirname(__DIR__) . "/config.php"; require_once dirname(dirname(__DIR__)) . "/EnvayaSMS.php"; $request = EnvayaSMS::get_request(); header("Content-Type: {$request->get_response_type()}"); if (!$request->is_validated($PASSWORD)) { header("HTTP/1.1 403 Forbidden"); error_log("Invalid password"); echo $request->render_error_response("Invalid password"); return; } $action = $request->get_action(); switch ($action->type) { case EnvayaSMS::ACTION_INCOMING: // Send an auto-reply for each incoming message. $type = strtoupper($action->message_type); error_log("Received {$type} from {$action->from}"); error_log(" message: {$action->message}"); if ($action->message_type == EnvayaSMS::MESSAGE_TYPE_MMS) { foreach ($action->mms_parts as $mms_part) { $ext_map = array('image/jpeg' => 'jpg', 'image/gif' => 'gif', 'text/plain' => 'txt', 'application/smil' => 'smil');