directly-api
## Dependencies
Last updated 8 months ago by gguilbert .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install directly-api 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.1.1                                ...           latest (3 months ago)

26 Versions

  • 1.1.1                                ...           3 months ago
  • 1.1.0                                ...           4 months ago
  • 1.0.24                                ...           4 months ago
  • 1.0.23                                ...           6 months ago
  • 1.0.22                                ...           6 months ago
  • 1.0.21                                ...           7 months ago
  • 1.0.20                                ...           8 months ago
  • 1.0.19                                ...           8 months ago
  • 1.0.18                                ...           8 months ago
  • 1.0.17                                ...           8 months ago
  • 1.0.16                                ...           8 months ago
  • 1.0.15                                ...           8 months ago
  • 1.0.14                                ...           8 months ago
  • 1.0.13                                ...           8 months ago
  • 1.0.12                                ...           8 months ago
  • 1.0.11                                ...           8 months ago
  • 1.0.10                                ...           8 months ago
  • 1.0.9                                ...           9 months ago
  • 1.0.8                                ...           9 months ago
  • 1.0.7                                ...           9 months ago
  • 1.0.6                                ...           9 months ago
  • 1.0.5                                ...           9 months ago
  • 1.0.3                                ...           9 months ago
  • 1.0.2                                ...           9 months ago
  • 1.0.1                                ...           9 months ago
  • 1.0.0                                ...           9 months ago
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 2
Dependencies (5)
Dev Dependencies (8)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |