Learn how companies like Phone2Action are using npm in their front-end developmentJoin the conversation »

directly-api

1.1.1 • Public • Published

directly-api-node-client

Currently published on npm as directly-api

Add to package.json: npm add directly-api --save

In your file:

import { directlyApi } from "directly-api";

Configuration

directlyApi.init({
    apiAccessToken: "<directly-api OAuth access token>",
    apiBaseUri: "https://api.directly.com",
    universalAccessToken: "<token from universal connector>",
    requestTimeout: <milliseconds to wait before hangup>
});

Question

// within async...
 
const questionParams = {
  userEmail: "<email>",
  userName: "<userName",
  text: "<question text>",
  subject: "<subject>",
  originalSystemId: "<system of origin reference id>"
};
 
directlyApi.askQuestion(questionParams)
  .then((directlyQuestion) => {
      ...
  })
  .catch((error) => {
      ...
  });

Message

// within async...
 
const messageParams = {
  questionUuid: "<questionUuid from question response>",
  responseUuid: "<from question if it already exists>",
  userEmail: "<email>",
  text: "<message text>",
  originalSystemId: "<system of origin reference id>",
  rating: <rating value>
};
 
directlyApi.appendMessage(demoMessage)
  .then((message: Message) => {
      ...
  })
  .catch((error) => {
      ...
  });

Process responses from Universal Connector (webhook)

Example Universal Connector config for when there is a new answer or reply

{
  "eventType": "{{event_type}}",
  "authorName": "{{answer.comment.author.name}}",
  "messageCreated": "{{answer.comment.date_created.iso8601}}",
  "messageIsAutoAnswer": {{answer.comment.is_auto_answer}},
  "message": "{{answer.comment.text}}",
  "messageAuthorIsPoster": {{answer.comment.author.is_poster}},
  "messageAuthorIsChatbot": {{answer.comment.author.is_chatbot}},
  "externalId": "{{question.external_id}}",
  "questionUuid": "{{question.uuid}}",
  "responseUuid": "{{answer.uuid}}",
  "messageUuid": "{{answer.comment.uuid}}",
  "expertName": "{{answer.expert.name}}"
}

Example Universal Connector config for when questions are rerouted to the company by an expert

{
  "eventType": "{{event_type}}",
  "externalId": "{{question.external_id}}",
  "questionUuid": "{{question.uuid}}"
}

Configure an endpoint to listen for Directly events from Universal Connector

server.post("/directly", async (req, res) => {
  const expertMessage = {};
 
  try {
    Object.assign(expertMessage, req.body);
    await directlyApi.processExpertResponse(expertMessage);
    res.status(200).json({ "success": true });
  } catch(error) {
    res.status(err.status).json(err).end()
  }
}

Subscribe to processed expert messages

directlyApi.subscribeToResponseMessage((expertMessage) => {
    const expertMessageJson = JSON.stringify(expertMessage);
    console.log(`Emitted response ${expertMessageJson}`);
});

Keywords

none

Install

npm i directly-api

DownloadsWeekly Downloads

28

Version

1.1.1

License

MIT

Unpacked Size

157 kB

Total Files

232

Last publish

Collaborators

  • avatar
  • avatar
  • avatar
  • avatar