Code Monkey home page Code Monkey logo

movile-messaging's Introduction

movile-messaging 📲

Greenkeeper badge npm version Code Climate Known Vulnerabilities Build Status

Unofficial Node.js wrapper for Movile's SMS Messaging API.

** Read carefully through Movile Messaging's official documentation (link above) before using this module. It will NOT attempt to validate or sanitize your parameters before sending requests, so make sure you're sending what they are expecting to receive. **

You will need your own UserName and AuthenticationToken to make API calls.

Note that most optional parameters are missing in this module, I'm working on it. PR's are welcome as well 😉

Usage example:

const Movile = require('movile-messaging');
const sms = new Movile('YOUR_USER_NAME', 'YOUR_AUTH_TOKEN');

sms.getStatus('9cb87d36-79af-11e5-89f3-1b0591cdf807')
.then(response => console.log(response.data))   // do something with this data
.catch(err => console.error(err));              // your error handling

Methods:

send(destination, messageText)

Send SMS message to a single endpoint.

  • destination: Phone number with country code and area code. Example: '5519998765432'
  • messageText: The message string to be sent. If it's too long, it will be split into multiple messages.

Example:

sms.send('5519998765432', 'Your text here')
.then(response => console.log(response.data))   // do something with this data
.catch(err => console.error(err));              // your error handling

Expected response body:

{
  "id":"9cb87d36-79af-11e5-89f3-1b0591cdf807"
}

sendBulk(numbers, messageText)

Send the same SMS message to many endpoints at once.

  • numbers: Array of phone numbers, just like destination in the send method.
  • messageText: The message string to be sent. If it's too long, it will be split into multiple messages.

Example:

sms.sendBulk(['5519988887777', '5535989890000'], 'Your text here')
.then(response => console.log(response.data))   // do something with this data
.catch(err => console.error(err));              // your error handling

Expected response body:

{
  "id":"317b925a-79b0-11e5-82d3-9fb06ba220b3",
  "messages":[
    {
      "id":"715773da-79b0-11e5-afc8-dfdd0dedf87a"
    },
    {
      "id":"717fb4bc-79b0-11e5-819e-57198aac792e"
    }
  ]
}

getStatus(id)

Check the delivery status of a single message.

  • id: ID of a message, obtained when it is sent.

Example:

sms.getStatus('8f5af680-973e-11e4-ad43-4ee58e9a13a6')
.then(response => console.log(response.data))   // do something with this data
.catch(err => console.error(err));              // your error handling

Expected response body:

{
  "id":"8f5af680-973e-11e4-ad43-4ee58e9a13a6",
  "carrierId":5,
  "carrierName":"TIM",
  "destination":"5519900001111",
  "sentStatusCode":2,
  "sentStatus":"SENT_SUCCESS",
  "sentStatusAt":1420732929252,
  "sentStatusDate":"2015-01-08T16:02:09Z",
  "deliveredStatusCode":4,
  "deliveredStatus":"DELIVERED_SUCCESS",
  "deliveredAt":1420732954000,
  "deliveredDate":"2015-01-08T16:02:34Z",
  "campaignId":1234
}

listReceived()

Retrieve messages sent to your LA's (i. e. a client replied to your SMS).

Example:

sms.listReceived()
.then(response => console.log(response.data))   // do something with this data
.catch(err => console.error(err));              // your error handling

Expected response body:

{
  "total": 1,
  "start": "2016-09-04T11:12:41Z",
  "end": "2016-09-08T11:17:39.113Z",
  "messages": [
    {
      "id": "25950050-7362-11e6-be62-001b7843e7d4",
      "subAccount": "iFoodMarketing",
      "campaignAlias": "iFoodPromo",
      "carrierId": 1,
      "carrierName": "VIVO",
      "source": "5516981562820",
      "shortCode": "28128",
      "messageText": "Eu quero pizza",
      "receivedAt": 1473088405588,
      "receivedDate": "2016-09-05T12:13:25Z",
      "mt": {
        "id": "8be584fd-2554-439b-9ba9-aab507278992",
        "correlationId": "1876",
        "username": "iFoodCS",
        "email": "[email protected]"
      }
    },
    {
      "id": "d3afc42a-1fd9-49ff-8b8b-34299c070ef3",
      "subAccount": "iFoodMarketing",
      "campaignAlias": "iFoodPromo",
      "carrierId": 5,
      "carrierName": "TIM",
      "source": "5519987565020",
      "shortCode": "28128",
      "messageText": "Meu hamburguer está chegando?",
      "receivedAt": 1473088405588,
      "receivedDate": "2016-09-05T12:13:25Z",
      "mt": {
        "id": "302db832-3527-4e3c-b57b-6a481644d88b",
        "correlationId": "1893",
        "username": "iFoodCS",
        "email": "[email protected]"
      }
    }
  ]
}

searchReceived(start, end)

Search for messages received in a time interval (between start and end, as one would expect).

  • start: ISO8601-formatted string. Defaults to 5 days ago from current date.
  • end: ISO8601-formatted string. Defaults to current date.

Example:

sms.listReceived('2016-09-04T11:12:41Z', '2016-09-08T11:17:39.113Z')

Expected response body: same format as listReceived()

  • Note that phone numbers from OI and Sercomtel carriers will not return DELIVERED_SUCCESS status even if the SMS was successfully received.
  • Data is only retained in Movile's end for a few days, so you may want to store this data somewhere else.

Special thanks to @mCodex

movile-messaging's People

Contributors

vspedr avatar greenkeeper[bot] avatar ivan05almeida avatar amadeu01 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.