1.1.39 • Published 5 years ago

@point-api/js-sdk v1.1.39

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

✍ Point API Javascript SDK

Point API's js-sdk provides an easy server-side and client-side interface for Point API.

npm Build Status forthebadge

Getting Started

Installation

npm install @point-api/js-sdk

Usage

Server-side

To use the Point API, you must first use your API key to retrieve an auth code. An auth code is a JWT that authenticates your client with the Point API. To keep your API key private, make a server-side request to retrieve an auth code, which you can then pass to your client for connecting to our API. Each auth code expires in 6 hours, so be sure to obtain a new auth code for your client after expiration.

The following is a code sample for requesting a Point API auth code. Make sure to substitute your API_KEY and your client's EMAIL_ADDRESS

// Request an auth code (JWT) from the Point API /auth endpoint
const response = await fetch(
  "https://v1.pointapi.com/auth?emailAddress=<EMAIL_ADDRESS>",
  {
    headers: {
      Authorization: "Bearer <API_KEY>"
    },
    method: "POST"
  }
);
// returns {"jwt":"<AUTH_CODE>"}

// Parse the json response and extract the JWT into a variable
const authCode = (await response.json()).jwt;

Client-side

Your client can start using the Point API once it has a valid auth code.

autocomplete

Use the autocomplete function to get a list of Autocomplete suggestions. You can pass in seed text to filter for suggestions that include specific words:

const api = new PointApi("<EMAIL_ADDRESS>", "<AUTH_CODE>");
// A websockets connection is automatically established on api init

// Get Autocomplete suggestions with the seed text "I can"
api.autocomplete("I can");
// { responseId: "12345", suggestions: [{suggestion: "I can call you later today.", "type": "suggestion", "userAdded": false}, ...]}

setContext

You can also set the context to refine Autocomplete suggestions. The context refers to a message that you're responding to, such as an email that you have received. Once the context has been set, searchSuggestions may return an entirely different list of suggestions:

// Set context
api.setContext("Hey Alex, when can you send me the slide deck?");
api.autocomplete("I can");
// { responseId: "12345", suggestions: [{suggestion: "I can get it to you this afternoon.", "type": "suggestion", "userAdded": false}, ...]}

reply

Point API also provides Reply suggestions for responding to entire messages (currently in beta). Use the getReplies function to receive Reply suggestions. You can play around with this feature here.
Note: this function will also set the previousMessage for the whole session

// Get replies just as you would set the previousMessage:
api.reply("How are you?");

Point finds "prompts" in your context and suggest up to 3 replies for each prompt. It also includes a "confidence" field in each reply suggestion, ranging from a score of 1 (possibly correct) to 3 (very likely correct). This reveals how certain we are about the accuracy of our suggestions.

Example:

// If multiple prompts are detected, replies will be generated for all of them and returned in a list
{
  responseId: "response_id",
  replies: [
  {
    prompt: "How are you?",
    suggestions: [
      {
        confidence: 3,
        text: "I'm doing okay, what about you?"
      },
      {
        confidence: 3,
        text: "I'm doing fantastic."
      },
      {
        confidence: 3,
        text: "I'm great! How are you?"
      }
    ]
  }
]};

feedback

You can also help us train our models by reporting user feedback such as chosen suggestions

api.feedback("response_id", "I'm doing okay, what about you?", "positive");

Documentation

Class: PointApi

Point Websockets Api Instance

Properties

Methods


constructor

new PointApi(emailAddress: string, apiKey: string, searchType?: boolean): PointApi

Parameters:

ParamTypeDescription
emailAddressstringEmail address of Point user
apiKeystringAPI key of Point client
Default value searchTypebooleanfalse

Returns: PointApi


Properties

apiKey

● apiKey: string

Api key of Point client


emailAddress

● emailAddress: string

Email address of Point user


Methods

autocomplete

autocomplete(seedText: string): Promise< AutocompleteResponse | null>

Query PointApi with seed text to get predicted suggestions

Parameters:

ParamTypeDescription
seedTextstringThe text to base suggestion predictions off of
Optional currentContextundefined | string

Returns: Promise< AutocompleteResponse | null>


feedback

feedback(responseId: string, suggestion: string | string[], type: "positive" | "negative"): Promise<void>

Give feedback on Point Api's suggestions

Parameters:

ParamType
responseIdstring
suggestionstring | string[]
type"positive" | "negative"

Returns: Promise<void>


setContext

setContext(previousMessage: string, contextType: string): Promise<string>

Set the context of the autocomplete session

Parameters:

ParamType
previousMessagestring
contextTypestring

Returns: Promise<string>


reply

reply(previousMessage: string, contextType: string): Promise< ReplyResponse | null>

Get reply suggestions given some recieved text

Parameters:

ParamTypeDefault value
previousMessagestring-
Default value contextTypeContextType"text"

Returns: Promise< ReplyResponse | null>

Types:

Reply

Properties:

● confidence: number
● text: string

ReplyMeta

Properties:

● prompt: string
● suggestions: Reply[]
● type: string

ReplyResponse

Properties:

● replies: ReplyMeta[]
● responseId: string

SuggestionMeta

Properties:

● suggestion: string
● type: string
● userAdded: boolean

AutocompleteResponse

● responseId: string
● seedText: string
● suggestions: SuggestionMeta[]

Deployment

This library is deployed to npmjs.com.

Travis CI pipeline is configured to release any code from master branch. By default the package version is automatically incremented like a patch (e.g. from v0.8.1 to v0.8.2). A git tag for corresponding release is created and can be seen here.

Deployment steps

  • Before merging to master make sure that previous release was merged to master. This means that package.json has the same version as latest in npmjs.com.
  • If versions differ, look for a git tag for the latest release (e.g. v1.1.23) and include it in the PR.
  • Now you can merge to master and a new release should be deployed to npmjs.com.
  • If you forget to include latest version, your release will fail. The easiest fix is to create another PR that only includes skipped version changes from version tag (e.g. v1.1.23). After merging in, a new release should be pushed to npmjs.com including all new changes.

Additional resources

Point API is the engine that powers autocompletion, which means you can customize the frontend implementation to fit your production needs. If you want to include a frontend solution that works out-of-the-box, we have a sample autocomplete dropdown (implemented as a React component) that automatically integrates with the API. You can plug in our autocomplete dropdown to have a fully-functional autocomplete on your platform, app, or website. A sample implementation can be found here

1.1.39

5 years ago

1.1.38

5 years ago

1.1.37

5 years ago

1.1.36

5 years ago

1.1.35

5 years ago

1.1.34

5 years ago

1.1.33

5 years ago

1.1.32

5 years ago

1.1.31

5 years ago

1.1.30

5 years ago

1.1.29

5 years ago

1.1.28

5 years ago

1.1.27

5 years ago

1.1.26

5 years ago

1.1.25

5 years ago

1.1.24

5 years ago

1.1.23

5 years ago

1.1.22

5 years ago

1.1.21

5 years ago

1.1.20

6 years ago

1.1.19

6 years ago

1.1.18

6 years ago

1.1.17

6 years ago

1.1.16

6 years ago

1.1.15

6 years ago

1.1.14

6 years ago

1.1.13

6 years ago

1.1.12

6 years ago

1.1.11

6 years ago

1.1.10

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

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.4

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