npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dms-client-channel

v2.0.2

Published

This package will interface with the Pega DMS client channel and provides callback methods for messages recieved from the DMS and send api methods to transmit messages and data to the DMS api

Downloads

83

Readme

Pega Digital Messaging Service client channel

This package will interface with the Pega Digital Messaging Service(DMS) client channel and provides callback methods for messages & events received from the Pega Digital Messaging Service. Once configured the dms-client-channel allow you to:

  • Validate request tokens from the DMS
  • Detect message types and run appropriate callbacks when a message or event is received from the DMS
  • Send messages and events to the DMS messaging API using built-in methods

Installation

$ npm install dms-client-channel

Setup

In order for the Digital Messaging Service (and client channel) to communicate with your application, it will need to accessible through a public URL. For local testing and development you may use a reverse proxy service such as ngrok to make your localhost publicly accessible.

In your server.js file, add the following. See examples folder for express_endpoints_example.js implementation example using express.js.

//import the dmsClientChannel module
const dmsClientChannel = require("dms-client-channel");

//Add your channel credentials (found in the digital messaging manager portal).
const DMS_CONFIG = {
  JWT_SECRET: "your jwt secret here",
  CHANNEL_ID: "your channel id here",
  API_URL: "your messaging api URL",
};

//Create an instance of the dmsClientChannel and pass in the config set.
let dms = dmsClientChannel(DMS_CONFIG);

Please note that In a production environment the DMS_CONFIG variables should be retrieved from process environment variables, or some other secure resource.

Usage

onRequest

in your server, call the onRequest method every time your endpoint receives a request from the DMS. This method validates the request token and calls the appropriate onMessage callbacks. the returned values can be used for your server's DMS endpoint response.

  • req should be the request object received from the DMS
  • status http status code
  • statusText http response text (success, forbidden etc.)

Please note that this method must be implemented in order for the dmsClientChannel onMessage callbacks to work correctly

/**
 * /dms endpoint to receive messages from the DMS layer using express.js to configure our server endpoints.
 */
app.post("/dms", async (req, res) => {
  try {
    //call the DMS on request method every time a request is received and pass in the request object
    dms.onRequest(req, async (status, message) => {
      res.status(status).send(message);
    });
  } catch (err) {
    return res.status(401).send(err);
  }
});

onMessage* callback methods

There are callback methods provided for each type of message or event received from the DMS. When a message is received, the appropriate callback is called. The developer should leverage these callbacks within their application to implement the client-channel specific logic for each event type received.

onTextMessage(message) {}
onMenuMessage(message) {}
onCarouselMessage(message) {}
onUrlLinkMessage(message) {}
onTypingIndicator(customer_id) {}
onCsrEndSession(customer_id) {}

onTextMessage callback method

called when your server receives text message(s) from the DMS

  • message the message received from the DMS is passed to the callback
//Text Message object
{
	"type": "text",
	"customer_id": "string",
	"message_id": "string",
	"csr_name": "string",
	"text": ["string"],
	"attachments": [{
		"url": "string",
		"content_type": "string",
		"file_name": "string",
		"size": numeric
	}]
}

Example usage:

//Called when a text message is received from the DMS
dms.onTextMessage = async (message) => {
  console.log("onTextMessage callback. message:" + message.text);

  //translate message json from DMS-format to client channel format...

  //call send message api on client channel to send the message...
};

onMenuMessage callback method

called when your server receives a menu message from the DMS

  • message the message received from the DMS is passed to the callback

Example usage:

//Called when a menu message is received from the DMS
dms.onMenuMessage = async (message) => {
  console.log("onMenuMessage callback. message:" + message.title);

  //translate message json from DMS-format to client channel format...

  //call send message api on client channel to send the message...
};

Menu message callback argument:

//Menu Message object
{
  "type": "menu",
  "customer_id": "string",
  "message_id": "string",
  "csr_name": "string",
  "title": "string",
  "items": [
    {
      "text": "string",
      "payload": "string",
      "image_url": "string"
    }
  ]
}

onCarouselMessage callback method

called when your server receives a carousel message from the DMS

  • message the message received from the DMS is passed to the callback

Example usage:

//Called when a carousel message is received from the DMS
dms.onCarouselMessage = async (message) => {
  console.log("onCarouselMessage callback. message:" + message.items[0].title);

  //translate message json from DMS-format to client channel format...

  //call send message api on client channel to send the message...
};

message callback argument:

//Carousel Message object
{
  "type": "carousel",
  "customer_id": "string",
  "message_id": "string",
  "csr_name": "string",
  "items": [
    {
      "title": "string",
      "sub_title": "string",
      "title_image_url": "string",
      "items": [
        {
          "text": "string",
          "payload": "string",
          "description": "string",
          "image_url": "string"
        }
      ]
    }
  ]
}

onUrlLinkMessage callback method

called when your server receives a URL link message from the DMS

  • message the message received from the DMS is passed to the callback

Example usage:

//Called when a url link message is received from the DMS
dms.onUrlLinkMessage = async (message) => {
  console.log("onUrlLinkMessage callback. message:" + message.items[0].title);

  //translate message json from DMS-format to client channel format...

  //call send message api on client channel to send the message...
};

URL link message callback argument:

//Link Message object
{
  "type": "link_button",
  "customer_id": "string",
  "message_id": "string",
  "csr_name": "string",
  "title": "string",
  "label": "string",
  "url": "string"
}

onTypingIndicator callback method

called when your server receives text message(s) from the DMS

  • customer_id String - the customer_id of the person who should receive the typing indicator.

Example usage:

//Called when a typing indicator is received from the DMS
dms.onTypingIndicator = async (customer_id) => {
  console.log("onTypingIndicator callback. customer_id: " + customer_id);
  //call client api to send typing indicator...
};

onCsrEndSession callback method

called when a CSR ends the session

  • customer_id String - the customer_id of the session that's been ended

Example usage:

//Called when the CSR ends the chat session
dms.onCsrEndSession = async (customer_id) => {
  console.log("onCsrEndSession callback. customer_id: " + customer_id);
  //call client api to notify of CSR end session event.
};

sendTextMessage callback method

Sends a text message to DMS/Pega args:

  • CustomerID String - the customer_id of the person who's agent
  • MessageID Unique id of the message returns:
  • response.status the http status of the DMS api request
  • response.statusText the text string status of the DMS api request. Example usage:
//Send a text message to DMS
dms.sendTextMessage(
  "CustomerID", //
  "MessageID", //Unique id of the message
  "Hello there!",
  "Customer Name",
  function (response) {
    //Return status from DMS
    return res.status(response.status).send(response.statusText);
  }
);

sendMessage callback method

Sends a message to DMS/Pega args:

  • dms_message any valid DMS message object returns:
  • response.status the http status of the DMS api request
  • response.statusText the text string status of the DMS api request. Example usage:
//Send a text message to DMS
dms.sendMessage(dms_message, function (response) {
  //Return status from DMS
  return res.status(response.status).send(response.statusText);
});

TODO

  • add license, author.

Issue Reporting

Author

License