Node.js Library v2

View Repo

The Flowroute Node.js Library v2 provides methods for interacting with Messages v2 of the Flowroute API.

Requirements


Installation

First, start a command shell session and clone the flowroute-messaging-nodejs Github repository.

git clone https://github.com/flowroute/flowroute-messaging-nodejs.git
            

After cloning the flowroute-messaging-nodejs repository, switch to the newly-created flowroute-messaging-nodejs directory. To check that Node.js is installed, run the following:

node --version
            

This SDK has been tested with Node v6.10.3 for Mac OS X. To install npm's request package for making http calls, run the following:

npm install request

            

Usage

In Flowroute's approach to building the Messaging (v2) API wrapper, HTTP requests are handled by the APIController, which contains the functions used to perform tasks with the Node.js SDK.

APIController

In your Node.js file, import the Messaging SDK and set up your callback function. The callback parameter prints the response out to the screen. It points back to the callback function added to the Node.js file.


var flowroute = require('./flowroutemessaginglib');
//Set up your callback function
var cb =  function(err, response){
  if(err){
   console.log(err);
   }
    console.log(response);
};

            

Credentials

Replace AccessKey and SecretKey with your API credentials from the Flowroute Manager.

flowroute.configuration.username = "AccessKey";
flowroute.configuration.password = "SecretKey";

            

Methods

createMessage()

The method accepts the msg, to, from, body, and callback parameters which you can learn more about in the API reference.

#Create and send the message
var msg = {"to": "12066418000", "from": "12064205780", "content": "That rug really tied the room together."};
flowroute.MessagesController.createMessage(msg, cb);

            
Example Response

{"data": {"id": "mdr1-d858379c1bee4dd3bfe5c556f7cef70f"}}

            
getMessageLookup()

The method accepts the record_id and callback parameters which you can learn more about in the API reference.

#Get the MDR
flowroute.MessagesController.getMessageLookup("d858379c1bee4dd3bfe5c556f7cef70f", cb);

            
Example Response
{
"data": {
 "attributes": {
   "body": "That rug really tied the room together.",
   "direction": "outbound",
   "timestamp": "2016-06-13T20:34:29.095045+00:00",
   "amount_nanodollars": 4000000,
   "from": "12064205780",
   "message_encoding": 0,
   "has_mms": false,
   "to": "12066418000",
   "amount_display": "$0.0040",
   "callback_url": null,
   "message_type": "long-code"
         },
 "type": "message",
 "id": "mdr1-d858379c1bee4dd3bfe5c556f7cef70f"
    }
}

            

©2004 - 2024 BCM One. All right reserved. Legal | Privacy Policy | Blog | News | Contact