This package has been deprecated

Author message:

This version is now deprecated and will no longer be supported. The offical Telstra messaging API Node.js SDK has been renamed to telstra-messaging

telstra-sms-messaging

1.1.5 • Public • Published

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.

Parameter Description
oAuthClientId OAuth 2 Client ID
oAuthClientSecret OAuth 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 Name Description
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

Parameter Tags Description
messageId Required Unique 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 Code Error Description
400 Invalid or missing request parameters
401 Invalid or no credentials passed in the request
403 Authorization credentials passed and accepted but account does
not have permission
404 The requested URI does not exist
405 The requested resource does not support the supplied verb
415 API does not support the requested content type
422 The 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 Code Error Description
400 Invalid or missing request parameters
401 Invalid or no credentials passed in the request
403 Authorization credentials passed and accepted but account does
not have permission
404 The requested URI does not exist
405 The requested resource does not support the supplied verb
415 API does not support the requested content type
422 The 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

Parameter Tags Description
payload Required A 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 Code Error Description
400 Invalid or missing request parameters
401 Invalid or no credentials passed in the request
403 Authorization credentials passed and accepted but account does
not have permission
404 The requested URI does not exist
405 The requested resource does not support the supplied verb
415 API does not support the requested content type
422 The 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

Parameter Tags Description
messageid Required Unique 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 Code Error Description
400 Invalid or missing request parameters
401 Invalid or no credentials passed in the request
403 Authorization credentials passed and accepted but account does not have permission
404 The requested URI does not exist
405 The requested resource does not support the supplied verb
415 API does not support the requested content type
422 The 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: createSendMMS

Send MMS

function createSendMMS(body, callback)

Parameters

Parameter Tags Description
body Required A 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 Code Error Description
400 Invalid or missing request parameters
401 Invalid or no credentials passed in the request
403 Authorization credentials passed and accepted but account does not have permission
404 The requested URI does not exist
405 The requested resource does not support the supplied verb
415 API does not support the requested content type
422 The 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

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

Parameter Tags Description
authorization Required Authorization header in Basic auth format
scope Optional Requested scopes as a space-delimited list.
fieldParameters Optional Additional 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 Code Error Description
400 OAuth 2 provider returned an error.
401 OAuth 2 provider says client authentication failed.

Method: createRequestToken1

Tags: Skips Authentication

Create a new OAuth 2 token.

function createRequestToken1(authorization, scope, formParams, callback)

Parameters

Parameter Tags Description
authorization Required Authorization header in Basic auth format
scope Optional Requested scopes as a space-delimited list.
fieldParameters Optional Additional 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 Code Error Description
400 OAuth 2 provider returned an error.
401 OAuth 2 provider says client authentication failed.

Back to List of Controllers

Readme

Keywords

none

Package Sidebar

Install

npm i telstra-sms-messaging

Weekly Downloads

11

Version

1.1.5

License

none

Last publish

Collaborators

  • mjdk1990