@ondewo/ondewo-nlu-client-js
v6.14.0
Published
ONDEWO Natural Language Understanding (NLU) Client library for Js
Downloads
431
Readme
Overview
@ondewo/nlu-client-js is a compiled version of the ONDEWO NLU API using the ONDEWO PROTO COMPILER. Here you can find the NLU API documentation.
ONDEWO APIs use Protocol Buffers version 3 (proto3) as their Interface Definition Language (IDL) to define the API interface and the structure of the payload messages. The same interface definition is used for gRPC versions of the API in all languages.
Setup
Using NPM:
npm i --save @ondewo/ondewo-nlu-client-jsUsing GitHub:
git clone https://github.com/ondewo/ondewo-nlu-client-js.git ## Clone repository
cd ondewo-nlu-client-js ## Change into repo-directoy
make setup_developer_environment_locally ## Install dependenciesPackage structure
npm
├── api
│ ├── ondewo_nlu_api.js
│ ├── ondewo_nlu_api.min.js
│ └── ondewo_nlu_api.min.js.map
├── auth
│ └── offlineTokenProvider.js
├── LICENSE
├── package.json
└── README.mdAuthentication (Keycloak bearer)
Auth is bearer-only. Every gRPC-web call must carry a short-lived Keycloak bearer access token in the Authorization metadata header.
Obtain and auto-refresh a token with the offline-token helper shipped in auth/offlineTokenProvider.js. Its login() performs a one-time ROPC login (grant_type=password, scope=offline_access) against the public SDK client ondewo-nlu-cai-sdk-public (no client secret) and refreshes the access token in the background until it lapses.
const { login } = require('@ondewo/ondewo-nlu-client-js/auth/offlineTokenProvider');
const provider = await login({
keycloakUrl: 'https://localhost:8443/auth',
realm: 'ondewo-ccai-platform',
clientId: 'ondewo-nlu-cai-sdk-public',
username: '[email protected]',
password: 'super-secret'
});
const client = new AgentsPromiseClient('https://localhost:8443', null, null);
const metadata = { Authorization: provider.getAuthorizationHeader() };
const response = await client.listAgents(request, metadata);
provider.stop(); // stop the background refresh loop when doneSee example/listAgents.js for a complete, unit-tested example.
