Javascript Library for Speechly Config API
With this library you can create and deploy simple Speechly voice-search applications from within a (server-side) Javascript program.
Installation
The gRPC libraries (@grpc/grpc-js
and google-protobuf
) are declared as peer dependencies, meaning that they need to be installed separately in the main package.
npm install --save @grpc/grpc-js google-protobuf
Usage
You must first obtain a Speechly API token by following the instructions at https://docs.speechly.com/dev-tools/command-line-client/#adding-an-api-token.
Then, you can copy-paste the API token to the example script below. Running the script will first create a new application, and then deploy a simple example configuration. The script initiates deployment and returns immediately, please check the Speechly Dashboard to see when deployment is complete. Then, you can try out the application with the Speechly Playground. It supports utterances such as
- show me blue jackets
- can i see shirts by adidas in size large
The resulting application also has the default entity max_price
for setting a maximum price, as well as the intent clear
for re-setting the filters. These can be used as follows:
- show me blue jackets not costing more than two hundred dollars
- maximum price fifty dollars
- clear all filters
- reset
const { setupConnection, createApplication, deployApplication } = require("@speechly/js-config-api");
(async () => {
try {
const token = YOUR_API_TOKEN_HERE;
const conn = setupConnection(token);
const app_id = await createApplication(conn);
const co = {"category": ["jackets", "shirts"],
"brand": ["nike", "adidas"],
"color": ["blue", "red", "green"],
"size": ["small", "medium", "large"]};
await deployApplication(conn, co);
} catch (err) {
console.error(err);
}
})();
Specifying the configuration
The configuration is a simple Javascript object that maps a list of possible values (must be strings) to each entity name as shown in the code example above. There is no upper limit to the number of possible values for each entity type.
The configuration supports five entity types:
- category: the type of the product (e.g. jackets, shirts, shoes, etc)
- brand: product brand
- color: product color
- size: product size
These are all optional, meaning it is possible to use a configuration that only uses a subset of the entity types.