Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

messagemedia-messages-sdk

Package Overview
Dependencies
Maintainers
4
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

messagemedia-messages-sdk

The MessageMedia Messages API provides a number of endpoints for building powerful two-way messaging applications.

  • 2.0.0
  • npm
  • Socket score

Version published
Weekly downloads
538
decreased by-41.65%
Maintainers
4
Weekly downloads
 
Created
Source

MessageMedia Messages NodeJS SDK

Travis Build Status Pull Requests Welcome HitCount npm

The MessageMedia Messages API provides a number of endpoints for building powerful two-way messaging applications.

Isometric

Table of Contents

:closed_lock_with_key: Authentication

Authentication is done via API keys. Sign up at https://developers.messagemedia.com/register/ to get your API keys.

Requests are authenticated using HTTP Basic Auth or HMAC. For Basic Auth, your API key will be basicAuthUserName and API secret will be basicAuthPassword. For HMAC, your API key will be hmacAuthUserName and API secret will be hmacAuthPassword. This is demonstrated in the Send an SMS example below.

:interrobang: Errors

Our API returns standard HTTP success or error status codes. For errors, we will also include extra information about what went wrong encoded in the response as JSON. The most common status codes are listed below.

HTTP Status Codes
CodeTitleDescription
400Invalid RequestThe request was invalid
401UnauthorizedYour API credentials are invalid
403Disabled featureFeature not enabled
404Not FoundThe resource does not exist
50XInternal Server ErrorAn error occurred with our API

:newspaper: Information

Slack and Mailing List

If you have any questions, comments, or concerns, please join our Slack channel: https://developers.messagemedia.com/collaborate/slack/

Alternatively you can email us at: developers@messagemedia.com

Bug reports

If you discover a problem with the SDK, we would like to know about it. You can raise an issue or send an email to: developers@messagemedia.com

Contributing

We welcome your thoughts on how we could best provide you with SDKs that would simplify how you consume our services in your application. You can fork and create pull requests for any features you would like to see or raise an issue. Please be aware that a large share of the files are auto-generated by our backend tool.

:star: Installation

Now install messagemedia-messages-sdk via npm by using:

npm install messagemedia-messages-sdk

Alternatively, add the following to the dependencies section of your package.json:

"messagemedia-messages-sdk": "^1.0.0"

:clapper: Get Started

It's easy to get started. Simply enter the API Key and secret you obtained from the MessageMedia Developers Portal into the code snippet below and a mobile number you wish to send to.

Send an SMS

Destination (destinationNumber) and source number (sourceNumber) should be in the E.164 format. For example, +61491570156 NOT 0491570156. The code snippet below comprises of only the bare minimum parameters required to send a message. You can view the full list of parameters over here. Alternatively, you can refer this code snippet with all the parameters in use.

const lib = require('messagemedia-messages-sdk');

/* Basic Auth */
lib.Configuration.basicAuthUserName = "YOUR_BASIC_API_KEY";
lib.Configuration.basicAuthPassword = "YOUR_BASIC_SECRET_KEY";

/* HMAC
lib.Configuration.hmacAuthUserName = "YOUR_HMAC_API_KEY";
lib.Configuration.hmacAuthPassword = "YOUR_HMAC_SECRET_KEY";
*/

var controller = lib.MessagesController;

let body = new lib.SendMessagesRequest();

body.messages = [];

body.messages[0] = new lib.Message();

body.messages[0].content = 'Hello world!';
body.messages[0].destinationNumber = '+61491570156';

controller.sendMessages(body, function(error, response, context) {
  if (error) {
    console.log(error);
  } else {
    console.log(response);
  }
});

Send an MMS

Destination (destinationNumber) and source number (sourceNumber) should be in the E.164 format. For example, +61491570156 NOT 0491570156. The code snippet below comprises of only the bare minimum parameters required to send a message. You can view the full list of parameters over here. Alternatively, you can refer this code snippet with all the parameters in use.

const lib = require('messagemedia-messages-sdk');

lib.Configuration.basicAuthUserName = "YOUR_API_KEY";
lib.Configuration.basicAuthPassword = "YOUR_SECRET_KEY";

var controller = lib.MessagesController;

let body = new lib.SendMessagesRequest();

body.messages = [];

body.messages[0] = new lib.Message();

body.messages[0].content = 'Hello world!';
body.messages[0].destinationNumber = '+61491570156';
body.messages[0].format = lib.FormatEnum.MMS;
body.messages[0].media = ['https://upload.wikimedia.org/wikipedia/commons/6/6a/L80385-flash-superhero-logo-1544.png'];
body.messages[0].subject = 'This is an MMS message';

controller.sendMessages(body, function(error, response, context) {
  if (error) {
    console.log(error);
  } else {
    console.log(response);
  }
});

Get Status of a Message

You can get a messsage ID from a sent message by looking at the message_id from the response of the above example.

const lib = require('messagemedia-messages-sdk');

lib.Configuration.basicAuthUserName = "YOUR_API_KEY";
lib.Configuration.basicAuthPassword = "YOUR_SECRET_KEY";

var controller = lib.MessagesController;

let messageId = '877c19ef-fa2e-4cec-827a-e1df9b5509f7';

controller.getMessageStatus(messageId, function(error, response, context) {
  if (error) {
    console.log(error);
  } else {
    console.log(response);
  }
});

Get replies to a message

You can check for replies that are sent to your messages.

const lib = require('messagemedia-messages-sdk');

lib.Configuration.basicAuthUserName = "YOUR_API_KEY";
lib.Configuration.basicAuthPassword = "YOUR_SECRET_KEY";

var controller = lib.RepliesController;

controller.checkReplies(function(error, response, context) {
  if (error) {
    console.log(error);
  } else {
    console.log(response);
  }
});

Check Delivery Reports

This endpoint allows you to check for delivery reports to inbound and outbound messages.

const lib = require('messagemedia-messages-sdk');

lib.Configuration.basicAuthUserName = "YOUR_API_KEY";
lib.Configuration.basicAuthPassword = "YOUR_SECRET_KEY";

var controller = lib.DeliveryReportsController;

controller.checkDeliveryReports(function(error, response, context) {
  if (error) {
    console.log(error);
  } else {
    console.log(response);
  }
});

Confirm Delivery Reports

This endpoint allows you to mark delivery reports as confirmed so they're no longer returned by the Check Delivery Reports function.

const lib = require('messagemedia-messages-sdk');

lib.Configuration.basicAuthUserName = "YOUR_API_KEY";
lib.Configuration.basicAuthPassword = "YOUR_SECRET_KEY";

var controller = lib.DeliveryReportsController;

let body = new lib.ConfirmDeliveryReportsAsReceivedRequest();

body.deliveryReportIds = ['011dcead-6988-4ad6-a1c7-6b6c68ea628d', '3487b3fa-6586-4979-a233-2d1b095c7718', 'ba28e94b-c83d-4759-98e7-ff9c7edb87a1'];

controller.confirmDeliveryReportsAsReceived(body, function(error, response, context) {
  if (error) {
    console.log(error);
  } else {
    console.log(response);
  }
});

Check credits remaining (Prepaid accounts only)

This endpoint allows you to check for credits remaining on your prepaid account.

const lib = require('messagemedia-messages-sdk');

lib.Configuration.basicAuthUserName = "YOUR_API_KEY";
lib.Configuration.basicAuthPassword = "YOUR_SECRET_KEY";

var controller = lib.MessagesController;

controller.checkCreditsRemaining(function(error, response, context) {
  if (error) {
    console.log(error);
  } else {
    console.log(response);
  }
});

:closed_book: API Reference Documentation

Check out the full API documentation for more detailed information.

:confused: Need help?

Please contact developer support at developers@messagemedia.com or check out the developer portal at developers.messagemedia.com

:page_with_curl: License

Apache License. See the LICENSE file.

FAQs

Package last updated on 10 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc