Node module to send SMS via the Swisscom SMS API.
- Register on the Swisscom Developer Portal.
- Generate your API key here.
#
# example.coffee
#
SMSApi = require 'swisscom-sms-api'
config =
smsApi:
sender: '+41791234567'
clientId: 'YOUR-CONSUMER-KEY-HERE'
sms =
recipient: '+41791234567'
messageText: 'hello world'
gateway = new SMSApi config.smsApi
gateway.on 'sent', ()->
console.log 'all messages sent'
gateway.on 'error', (error) ->
console.log 'an error occurred: ', error
gateway.on 'deliveryStatus', (status) ->
consoloe log 'this is a status for each recipient', status
gateway.send sms.recipient, sms.messageText
Run coffee example.coffee
from your command line.
//
// example.js
//
var SMSApi, config, gateway, sms;
SMSApi = require('swisscom-sms-api');
config = {
smsApi: {
sender: '+41791234567',
clientId: 'YOUR-CONSUMER-KEY-HERE'
}
};
sms = {
recipient: '+41791234567',
messageText: 'hello world'
};
gateway = new SMSApi(config.smsApi);
gateway.on('sent', function() {
return console.log('all messages sent');
});
gateway.on('error', function(error) {
return console.log('an error occurred: ', error);
});
gateway.on('deliveryStatus', function(status) {
return console.log('deliveryStatus: ', status);
});
gateway.send(sms.recipient, sms.messageText);
Run node example.js
from your command line.
#Delivery Status Please refer to the API Documentation. There are two known delivery status which the service returns:
- DeliveredToNetwork - means the sms is deliverd to the mobile network and will be delivered to the recipient as soon as possible.
- DeliveryImpossible - means the delivery to the mobile network is not possible. An unknown recipient number can be a reason.
npm install swisscom-sms-api
The Swisscom SMS API uses debug for logging. Just set the DEBUG
environment variable to swisscom-*
- Example using CoffeeScript:
DEBUG=swisscom-* coffee example.coffee
- Example using Javascript:
DEBUG=swisscom-* node example.js
- Sender number is displayed incorrectly - This is an API issue and not the fault of the node module.