Skip to content
balnagy edited this page Mar 8, 2012 · 5 revisions

Welcome to the creatary-node.js-sdk wiki!

#Initialization

creatary.init(consumer_key, consumer_secret, [parameters])

consumer_key (string): Your application's client id (also called consumer key)

consumer_secret (string): Your application's client secret (also called consumer secret)

parameters (object) [optional]: Configuration object

  • server (object) [optional]: Pass your Express instance, Creatary module will reuse it for OAuth and listening for SMS.
  • receiveSms (object) [optional]: Parameters for receiving SMS.
  • url (string): SMS callback url
  • callBack (function): Callback function for incoming SMS
  • oAuth (object) [optional]: Optional if you use OAuth 1.0 mode.
  • connectUrl (string): Relative URL, used to initiate the OAuth authorization for your app
  • url (string): Absolute URL, used redirect back the user after authorization
  • callback (function): Callback function after successful oAuth flow
  • oAuth2 (boolean): true if you use OAuth2

Example

// Creatary configuration object
var creataryConfig = {
    server: srv,
    receiveSms : {
        url: 'http://localhost/creatary/sms',
        callBack: onSms
    },
    oAuth : {
        url: 'http://localhost/callback',
        callback: onAuthed
    }
};
// Init Creatary module with the application consumer key and secret
var creatary = require('../../lib/creatary').init('consumer_key', 'consumer_secret', creataryConfig);

SMS

creatary.Sms.send(toToken, msg);

toToken (string): OAuth token which you obtained for the subscriber you address

msg (string): Text of the SMS

Example

creatary.Sms.send(from, "Hello World");

creatary.Sms.receive(callback, [params]);

callback (function(data)): Upon sms received, this callback function is called by providing the details of the sms in parameter

  • data (object):
  • to (string): destination MSISDN
  • body (string): the message
  • access_token (string): token which identifies the sender, it can be used for response
  • transaction_id (string): transaction id of the SMS, use it in order to keep the SMS sesssion

Example

creatary.Sms.receive(function(params) {
    creatary.Sms.send(params.access_token, "Hello back!");
}

parameter (object): Optional parameter container:

  • url (object): it's used to open the server port and bind the path

Location

creatary.Location.getCoordinates(userToken, callback);

userToken (string): OAuth token which you obtained for the subscriber you address

callback (function(data)): Callback when the location received

  • data (object):
  • latitude (string): Latitude
  • longitude (string): Longitude
  • accuracy (string): Accuracy
  • timestamp (string): Timestamp

Example

creatary.Location.getCoordinates(from, function(data) {
    creatary.Sms.send(from, "Your coordinates are " + data.latitude + "/" + data.longitude );
});