Fork me on GitHub

EnvayaSMS SMS gateway for Android

Upgrading to EnvayaSMS 3.0

In EnvayaSMS version 3.0, the default format of HTTP responses changed to JSON (from XML in version 2).

In version 2, the server was expected to different responses depending on the action -- 'incoming' and 'outgoing' actions returned an XML list of messages, while the response type for other actions was undefined.

In version 3, this behavior has been simplified -- now the server is expected to return a JSON response for all actions. Each JSON response may contain a list of events. Optionally, users may configure AMQP to push events to the phone in real-time, and each message in the AMQP queue represents a single event in the same JSON format.

To support this new API, the PHP server library has been changed. For backwards compatibility, the PHP server library will generate either XML or JSON responses depending on the version of the EnvayaSMS app. However, phones that use EnvayaSMS version 2 with the XML interface will only be able to receive outgoing messages (EnvayaSMS_Event_Send), not other events added in version 3 (such as updating settings or canceling messages).

When you upgrade to the new version of the PHP server library, you will also need to update your PHP code that uses the library.

The following code examples assume you have the following variables:

$request = EnvayaSMS::get_request();
$action = $request->get_action();

Updating your PHP code is straightforward:

Setting HTTP Response Header

Old:
header("Content-Type: text/xml");
New:
header("Content-Type: {$request->get_response_type()}");

Sending Messages

Old:
$action->get_response_xml($messages);
New:
$request->render_response(array(
     new EnvayaSMS_Event_Send($messages)
));

Returning an Error

Old:
EnvayaSMS::get_error_xml($error_message);
New:
$request->render_error_response($error_message);

Returning an Empty Successful Response

Old:
EnvayaSMS::get_success_xml();
New:
$request->render_response();