1.1.5 • Published 7 years ago

telstra-sms-messaging v1.1.5

Weekly downloads
69
License
-
Repository
-
Last release
7 years ago

Deprecation warning

This version of the Messaging SDK is now deprecated and will no longer be supported. The newest offical version of the Telstra Messaging API Nodejs SDK can be found here.

Getting started

The Telstra Messaging API allows your applications to send SMS and MMS and receive SMS text messages from Australia's leading network operator. It also allows your application to track the delivery status of both sent and received messages.

Installation

Install with NPM

npm install telstra-sms-messaging --save

Initialization

Authentication

In order to setup authentication in the API client, you need the following information.

ParameterDescription
oAuthClientIdOAuth 2 Client ID
oAuthClientSecretOAuth 2 Client Secret

API client can be initialized as following:

const lib = require('telstra-sms-messaging/lib');

// Configuration parameters and credentials
lib.Configuration.oAuthClientId = "oAuthClientId"; // OAuth 2 Client ID
lib.Configuration.oAuthClientSecret = "oAuthClientSecret"; // OAuth 2 Client Secret

You must now authorize the client.

Authorizing your client

This SDK uses OAuth 2.0 authorization to authorize the client.

The authorize() method will exchange the OAuth client credentials for an access token. The access token is an object containing information for authorizing client requests.

You must pass the scopes for which you need permission to access.

const tokenPromise = oAuthManager.authorize([lib.OAuthScopeEnum.NSMS]);

The Node.js SDK supports both callbacks and promises. So, the authorize call returns a promise and also returns response back in the callback (if one is provided)

The client can now make authorized endpoint calls.

Scopes

Scopes enable your application to only request access to the resources it needs while enabling users to control the amount of access they grant to your application. Available scopes are defined in the lib/Models/OAuthScopeEnum enumeration.

Scope NameDescription
NSMS

Authorization example

In this example, app.js will check if the access token has been set in the SDK. If it has been, API calls can be made. Otherwise, client has to be authorized first before making API calls.

app.js

const express = require('express');
const app = express();

const PORT = 1800;

const lib = require('telstra-sms-messaging/lib');
const oAuthManager = lib.OAuthManager;

lib.Configuration.oAuthClientId = 'oAuthClientId'; // OAuth 2 Client ID
lib.Configuration.oAuthClientSecret = 'oAuthClientSecret'; // OAuth 2 Client Secret

lib.Configuration.oAuthTokenUpdateCallback = function(token) {
    // 'token' holds the new access token
    console.log(token);
};

app.listen(PORT, () => {
    console.log('Listening on port ' + PORT);
});

app.get('/', (req, res, next) => {
  if (oAuthManager.isTokenSet()) {
    // token is already stored in the client
    // make API calls as required
    next();
  } else {
    const scopes = [lib.OAuthScopeEnum.NSMS];
    const promise = oAuthManager.authorize(scopes);
    promise.then((success) => {
      // client authorized. API calls can be made
      next();
    }, (exception) => {
      return res.status(exception.errorCode).json({
        // error occurred, exception will be of type lib/Exceptions/OAuthProviderException
        code: exception.errorCode,
        message: exception.errorMessage
      });
    });
  }
});

Class Reference

List of Controllers

Class: MessagingController

Get singleton instance

The singleton instance of the MessagingController class can be accessed from the API Client.

var controller = lib.MessagingController;

Method: getSMSStatus

Get Message Status

function getSMSStatus(messageId, callback)

Parameters

ParameterTagsDescription
messageIdRequiredUnique identifier of a message - it is the value returned from
a previous POST call to https://tapi.telstra.com/v2/messages/sms

Example Usage

    var messageId = 'messageId';

    controller.getSMSStatus(messageId, function(error, response, context) {

    
    });

Errors

Error CodeError Description
400Invalid or missing request parameters
401Invalid or no credentials passed in the request
403Authorization credentials passed and accepted but account does
not have permission
404The requested URI does not exist
405The requested resource does not support the supplied verb
415API does not support the requested content type
422The request is formed correctly, but due to some condition

the request cannot be processed e.g. email is required and it is not provided in the request | | 501 | The HTTP method being used has not yet been implemented for the requested resource | | 503 | The service requested is currently unavailable | | 0 | An internal error occurred when processing the request |

Method: retrieveSMSResponses

Retrieve Messages

function retrieveSMSResponses(callback)

Example Usage

    controller.retrieveSMSResponses(function(error, response, context) {

    
    });

Errors

Error CodeError Description
400Invalid or missing request parameters
401Invalid or no credentials passed in the request
403Authorization credentials passed and accepted but account does
not have permission
404The requested URI does not exist
405The requested resource does not support the supplied verb
415API does not support the requested content type
422The request is formed correctly, but due to some condition

the request cannot be processed e.g. email is required and it is not provided in the request | | 501 | The HTTP method being used has not yet been implemented for the requested resource | | 503 | The service requested is currently unavailable | | 0 | An internal error occurred when processing the request |

Method: createSendSMS

Send Message

function createSendSMS(payload, callback)

Parameters

ParameterTagsDescription
payloadRequiredA JSON or XML payload containing the recipient's phone number and text message.

The recipient number should be in the format '04xxxxxxxx' where x is a digit |

Example Usage

    var payload = new SendSMSRequest({"key":"value"});

    controller.createSendSMS(payload, function(error, response, context) {

    
    });

Errors

Error CodeError Description
400Invalid or missing request parameters
401Invalid or no credentials passed in the request
403Authorization credentials passed and accepted but account does
not have permission
404The requested URI does not exist
405The requested resource does not support the supplied verb
415API does not support the requested content type
422The request is formed correctly, but due to some condition

the request cannot be processed e.g. email is required and it is not provided in the request | | 501 | The HTTP method being used has not yet been implemented for the requested resource | | 503 | The service requested is currently unavailable | | 0 | An internal error occurred when processing the request |

Method: getMMSStatus

Get MMS Status

function getMMSStatus(messageid, callback)

Parameters

ParameterTagsDescription
messageidRequiredUnique identifier of a message - it is the value returned from a previous POST call to https://tapi.telstra.com/v2/messages/mms

Example Usage

    var messageid = 'messageid';

    controller.getMMSStatus(messageid, function(error, response, context) {

    
    });

Errors

Error CodeError Description
400Invalid or missing request parameters
401Invalid or no credentials passed in the request
403Authorization credentials passed and accepted but account does not have permission
404The requested URI does not exist
405The requested resource does not support the supplied verb
415API does not support the requested content type
422The request is formed correctly, but due to some condition the request cannot be processed e.g. email is required and it is not provided in the request
501The HTTP method being used has not yet been implemented for the requested resource
503The service requested is currently unavailable
0An internal error occurred when processing the request

Method: createSendMMS

Send MMS

function createSendMMS(body, callback)

Parameters

ParameterTagsDescription
bodyRequiredA JSON or XML payload containing the recipient's phone number and MMS message.The recipient number should be in the format '04xxxxxxxx' where x is a digit

Example Usage

    var body = new SendMMSRequest({"key":"value"});

    controller.createSendMMS(body, function(error, response, context) {

    
    });

Errors

Error CodeError Description
400Invalid or missing request parameters
401Invalid or no credentials passed in the request
403Authorization credentials passed and accepted but account does not have permission
404The requested URI does not exist
405The requested resource does not support the supplied verb
415API does not support the requested content type
422The request is formed correctly, but due to some condition the request cannot be processed e.g. email is required and it is not provided in the request
501The HTTP method being used has not yet been implemented for the requested resource
503The service requested is currently unavailable
0An internal error occurred when processing the request

Back to List of Controllers

Class: OAuthAuthorizationController

Get singleton instance

The singleton instance of the OAuthAuthorizationController class can be accessed from the API Client.

var controller = lib.OAuthAuthorizationController;

Method: createRequestToken

Tags: Skips Authentication

Create a new OAuth 2 token.

function createRequestToken(authorization, scope, formParams, callback)

Parameters

ParameterTagsDescription
authorizationRequiredAuthorization header in Basic auth format
scopeOptionalRequested scopes as a space-delimited list.
fieldParametersOptionalAdditional optional form parameters are supported by this method

Example Usage

    var authorization = 'Authorization';
    var scope = 'scope';
    // key-value map for optional form parameters
    var formParams = [];

    controller.createRequestToken(authorization, scope, formParams, function(error, response, context) {

    
    });

Errors

Error CodeError Description
400OAuth 2 provider returned an error.
401OAuth 2 provider says client authentication failed.

Method: createRequestToken1

Tags: Skips Authentication

Create a new OAuth 2 token.

function createRequestToken1(authorization, scope, formParams, callback)

Parameters

ParameterTagsDescription
authorizationRequiredAuthorization header in Basic auth format
scopeOptionalRequested scopes as a space-delimited list.
fieldParametersOptionalAdditional optional form parameters are supported by this method

Example Usage

    var authorization = 'Authorization';
    var scope = 'scope';
    // key-value map for optional form parameters
    var formParams = [];

    controller.createRequestToken1(authorization, scope, formParams, function(error, response, context) {

    
    });

Errors

Error CodeError Description
400OAuth 2 provider returned an error.
401OAuth 2 provider says client authentication failed.

Back to List of Controllers

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.1.0

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago