Point API's js-sdk provides an easy server-side and client-side interface for Point API.
npm install @point-api/js-sdk
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;
Your client can start using the Point API once it has a valid auth code.
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}, ...]}
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}, ...]}
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?"
}
]
}
]};
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");
Point Websockets Api Instance
new PointApi(emailAddress: string
, apiKey: string
, searchType?: boolean
): PointApi
Parameters:
Param | Type | Description |
---|---|---|
emailAddress | string |
Email address of Point user |
apiKey | string |
API key of Point client |
Default value searchType |
boolean |
false |
Returns: PointApi
● apiKey: string
Api key of Point client
● emailAddress: string
Email address of Point user
▸ autocomplete(seedText: string
): Promise
< AutocompleteResponse | null
>
Query PointApi with seed text to get predicted suggestions
Parameters:
Param | Type | Description |
---|---|---|
seedText | string |
The text to base suggestion predictions off of |
Optional currentContext |
undefined | string |
Returns: Promise
< AutocompleteResponse | null
>
▸ feedback(responseId: string
, suggestion: _ string
| string
[], type: _ "positive" | "negative"): Promise
<void
>
Give feedback on Point Api's suggestions
Parameters:
Param | Type |
---|---|
responseId | string |
suggestion | string | string [] |
type | "positive" | "negative" |
Returns: Promise
<void
>
▸ setContext(previousMessage: string
, contextType: string
): Promise
<string
>
Set the context of the autocomplete session
Parameters:
Param | Type |
---|---|
previousMessage | string |
contextType | string |
Returns: Promise
<string
>
▸ reply(previousMessage: string
, contextType: string
): Promise
< ReplyResponse | null
>
Get reply suggestions given some recieved text
Parameters:
Param | Type | Default value |
---|---|---|
previousMessage | string |
- |
Default value contextType |
ContextType | "text" |
Returns: Promise
< ReplyResponse | null
>
Reply
● confidence: number
● text: string
ReplyMeta
● prompt: string
● suggestions: Reply[]
● type: string
ReplyResponse
● replies: ReplyMeta[]
● responseId: string
SuggestionMeta
● suggestion: string
● type: string
● userAdded: boolean
AutocompleteResponse
● responseId: string
● seedText: string
● suggestions: SuggestionMeta[]
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.
- 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.
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