Data source: Smsmode


1Presentation

smsmode.com is a service for sending text messages to cell phones. Please refer to their website for rates.

This data source allows you to send notification SMS (as opposed to marketing SMS; be careful, sending a commercial message could expose you to blocking).

If you have correctly configured the connection parameters for the smsmode service, Temma will automatically create an object of type \Temma\Datasources\Smsmode. By convention, we'll assume that you've named this connection sms in the etc/temma.php file (see configuration documentation).

In the controllers, the connection to smsmode is then available by writing:

$this->sms

In other objects managed by the dependency injection component, the connection to smsmode is accessible by writing:

$this->_loader->dataSources['sms']

2Configuration

In the etc/temma.php file (see configuration documentation), you declare the DSN (Data Source Name) used to connect to smsmode.

The DSN for connecting to smsmode is written as: smsmode://[SENDER_NAME:]API_KEY

  • SENDER_NAME is an optional string, without spaces or accents, which replaces the sender number.
  • PI_KEY is the API key you can generate on the user interface.

3Unified calls

3.1Array-type access

use \Temma\Datasources\Smsmode as TµSmsmode;

// send a text message
$this->sms['33611223344'] = "Message à envoyer";

// send a text message to many recipients
$this->sms['33611223344,33622334455'] = "Message";

// retrieve message status
// (see send() method below)
$statut = $this->sms[$msgId];
if ($statut == TµSmsmode::STATUS_SENT) {
    // ...
} else if ($statut == TµSmsmode::STATUS_MSG_INTERNAL_ERROR ||
           $statut == TµSmsmode::STATUS_INTERNAL_ERROR) {
    // ...
} else if ($statut == TµSmsmode::STATUS_INVALID_PARAMETERS) {
    // ...
} else if ($statut == TµSmsmode::STATUS_SMS_NOT_FOUND) {
    // ...
} else if ($statut == TµSmsmode::STATUS_TEMPORARY_UNAVAILABLE) {
    // ...
} else if ($statut == TµSmsmode::STATUS_MSG_RECEIVED) {
    // ...
} else if ($statut == TµSmsmode::STATUS_GATEWAY_RECEIVED ||
           $statut == TµSmsmode::STATUS_GATEWAY_DELIVERED) {
    // ...
} else if ($statut == TµSmsmode::STATUS_DELIVERY_ERROR) {
    // ...
}

// delete a programmed message
// (see send() method below)
unset($this->sms[$msgId]);

3.2General methods

// deleting a programmed message
// (see send() method below)
$this->sms->remove($msgId);

// deleting several programmed messages
$this->sms->mRemove([$msgId1, $msgId2, $msgId3]);

3.3Raw data management

use \Temma\Datasources\Smsmode as TµSmsmode;

// send a text message
$this->sms->write('33611223344', "Message");

// send a text message to many recipients
$this->sms->write('33611223344,33622334455,33633445566',
                  "Message");

// send SMS with programming for a future date,
// and definition of an internal reference
$this->sms->write('33611223344', "Message", [
    'sendDate'  => '31122029-12:50', // format 'DDMMYYYY-HH:mm',
    'reference' => 'login_1234',
]);

// retrieve message status
// (see send() method below)
$statut = $this->sms->read($msgId);
if ($statut == TµSmsmode::STATUS_SENT) {
    // ...
} else if ($statut == TµSmsmode::STATUS_MSG_INTERNAL_ERROR ||
           $statut == TµSmsmode::STATUS_INTERNAL_ERROR) {
    // ...
} else if ($statut == TµSmsmode::STATUS_INVALID_PARAMETERS) {
    // ...
} else if ($statut == TµSmsmode::STATUS_SMS_NOT_FOUND) {
    // ...
} else if ($statut == TµSmsmode::STATUS_TEMPORARY_UNAVAILABLE) {
    // ...
} else if ($statut == TµSmsmode::STATUS_MSG_RECEIVED) {
    // ...
} else if ($statut == TµSmsmode::STATUS_GATEWAY_RECEIVED ||
           $statut == TµSmsmode::STATUS_GATEWAY_DELIVERED) {
    // ...
} else if ($statut == TµSmsmode::STATUS_DELIVERY_ERROR) {
    // ...
}

// read multiple message statuses
$statuts = $this->sms->mRead([$msgId1, $msgId2, $msgId3]);

4Specific calls

4.1Sending a message with identifier retrieval

Use of the send() method is recommended when sending an SMS, as it enables you to retrieve the message identifier, which in turn enables you to retrieve the status of the message (i.e. whether it has been delivered or not), or to delete a message scheduled to be sent at a future date.

// send a text message
$msgId = $this->sms->send('33611223344', "Message");

// send SMS with programming for a future date,
// and definition of an internal reference
$msgId = $this->sms->send('33611223344', "Message",
                          '31122029-12:50', 'login_1234');

// identical call, with named parameters
$msgId = $this->sms->send('33611223344', "Message",
                          sendDate: '31122029-12:50',
                          reference: 'login_1234');

// send a text message to many recipients
$msgId = $this->sms->send(['33611223344', '33622334455', '33633445566'],
                          "Message");

4.2Account balance retrieval

To be able to send SMS using the smsmode service, you first need to create an account, then credit it by purchasing credits.

The getBalance() method is used to retrieve the balance available in the account, enabling you to anticipate the need to credit the account again.

// balance retrieval
$sole = $this->sms->getBalance();