TODO: Add a description
The generated SDK relies on Node Package Manager (NPM) being available to resolve dependencies. If you don't already have NPM installed, please go ahead and follow instructions to install NPM from here. The SDK also requires Node to be installed. If Node isn't already installed, please install it from here
NPM is installed by default when Node is installed
To check if node and npm have been successfully installed, write the following commands in command prompt:
node --version
npm -version
Now use npm to resolve all dependencies by running the following command in the root directory (of the SDK folder):
npm install
This will install all dependencies in the node_modules
folder.
Once dependencies are resolved, you will need to move the folder AazarKhanTelstraSMSAPILib
in to your node_modules
folder.
The following section explains how to use the library in a new project.
Open an IDE/Text Editor for JavaScript like Sublime Text. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.
Click on File
and select Open Folder
.
Select the folder of your SDK and click on Select Folder
to open it up in Sublime Text. The folder will become visible in the bar on the left.
Now right click on the folder name and select the New File
option to create a new test file. Save it as index.js
Now import the generated NodeJS library using the following lines of code:
var lib = require('lib');
Save changes.
To run the index.js
file, open up the command prompt and navigate to the Path where the SDK folder resides. Type the following command to run the file:
node index.js
These tests use Mocha framework for testing, coupled with Chai for assertions. These dependencies need to be installed for tests to run. Tests can be run in a number of ways:
- Navigate to the root directory of the SDK folder from command prompt.
- Type
mocha --recursive
to run all the tests.
- Navigate to the
../test/Controllers/
directory from command prompt. - Type
mocha *
to run all the tests.
- Navigate to the
../test/Controllers/
directory from command prompt. - Type
mocha Aazar Khan Telstra SMS APIController
to run all the tests in that controller file.
To increase mocha's default timeout, you can change the
TEST_TIMEOUT
parameter's value inTestBootstrap.js
.
In order to setup authentication in the API client, you need the following information.
Parameter | Description |
---|---|
oAuthAccessToken | OAuth 2.0 Access Token |
API client can be initialized as following:
const lib = require('lib');
// Configuration parameters and credentials
lib.Configuration.oAuthAccessToken = "oAuthAccessToken"; // OAuth 2.0 Access Token
The singleton instance of the APIController
class can be accessed from the API Client.
var controller = lib.APIController;
The Send SMS method sends an SMS message to a single Australian mobile phone number. A unique identifier (messageId) returned in the response, which may be used to query for the delivery status of the message.
function createSendSMS(body, callback)
Parameter | Tags | Description |
---|---|---|
body | Required |
TODO: Add a parameter description |
var body = new SendSMSToBodyObject({ "to": "", "body": ""});
controller.createSendSMS(body, function(error, response, context) {
});
To get an OAuth 2.0 Authentication token, pass through your Consumer Key and Consumer Secret that you received when you registered for the SMS API key. The grant_type should be left as ?client_credentials? and the scope as ?SMS?. The token will expire in one hour.
function getAuthentication(clientId, clientSecret, grantType, scope, callback)
Parameter | Tags | Description |
---|---|---|
clientId | Required |
client's id |
clientSecret | Required |
client's secret |
grantType | Optional |
value set by default |
scope | Optional |
value set by default |
var clientId = client_id;
var clientSecret = client_secret;
var grantType = grant_type;
var scope = 'scope';
controller.getAuthentication(clientId, clientSecret, grantType, scope, function(error, response, context) {
});
The recipients of your SMS messages can send a reply which you can retrieve using the Get Message Response method. Pass through the unique identifier (messageId) returned as returned in the response from the Send SMS method and you will receive the reply and the timestamp.
function getMessageResponse(mESSAGEID, callback)
Parameter | Tags | Description |
---|---|---|
mESSAGEID | Required |
TODO: Add a parameter description |
var mESSAGEID = MESSAGE_ID;
controller.getMessageResponse(mESSAGEID, function(error, response, context) {
});
Use the unique identifier (messageId) returned as returned in the response from the Send SMS method to get the status.
function getMessageStatus(callback)
controller.getMessageStatus(function(error, response, context) {
});