1.1.2 • Published 5 years ago

directly-api v1.1.2

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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}`);
});

TODO

currently we need to do yarn build npm link

todo - update / fix build process to work with npm run build

1.1.2

5 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.22

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago