@nlxai/core 1.2.3-alpha.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1877 -34
- package/lib/index.cjs +90 -55
- package/lib/index.d.ts +255 -213
- package/lib/index.esm.js +90 -55
- package/lib/index.umd.js +1 -1
- package/package.json +12 -12
- package/typedoc.cjs +9 -2
package/README.md
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
The core package of our official JavaScript SDK to communicate with NLX conversational applications.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
# Getting started
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i --save @nlxai/core
|
|
9
|
+
```
|
|
6
10
|
|
|
7
11
|
```js
|
|
8
12
|
import { createConversation } from "@nlxai/core";
|
|
@@ -16,7 +20,6 @@ const config = {
|
|
|
16
20
|
userId: "abcd-1234", // optional property to identify the user
|
|
17
21
|
conversationId: "", // start with a specific conversation ID - useful if you want to resume a previous conversation
|
|
18
22
|
languageCode: "es-US", // optional language code for standard applications that do not run on US English
|
|
19
|
-
environment: "production", // optional environment name for multi-environment applications to control which data request environment should be used. "production" or "development" are the only supported values.
|
|
20
23
|
};
|
|
21
24
|
|
|
22
25
|
// Start the conversation
|
|
@@ -31,65 +34,402 @@ convo.subscribe((responses, newResponse) => {
|
|
|
31
34
|
convo.sendText("hello");
|
|
32
35
|
```
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
# Usecases
|
|
38
|
+
|
|
39
|
+
## Implementing a custom chat widget
|
|
40
|
+
|
|
41
|
+
Generally we recommend using [Touchpoint](../touchpoint-ui/README.md) for integrating with an application, but if this is unsuitable for some reason, it is not difficult to build a custom widget. Here is a very simple example to get started:
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import React, { StrictMode, type FC, useState, useEffect } from "react";
|
|
45
|
+
import * as ReactDOMClient from "react-dom/client";
|
|
46
|
+
import {
|
|
47
|
+
type ConversationHandler,
|
|
48
|
+
createConversation,
|
|
49
|
+
type Response,
|
|
50
|
+
ResponseType,
|
|
51
|
+
} from "@nlxai/core";
|
|
52
|
+
|
|
53
|
+
const App: FC<{ conversation: ConversationHandler }> = ({ conversation }) => {
|
|
54
|
+
const [messages, setMessages] = useState<Response[]>([]);
|
|
55
|
+
const [input, setInput] = useState<string>("");
|
|
56
|
+
|
|
57
|
+
// This effect synchronizes component state with the ConversationHandler state
|
|
58
|
+
useEffect(
|
|
59
|
+
() =>
|
|
60
|
+
conversation.subscribe((responses) => {
|
|
61
|
+
setMessages(responses);
|
|
62
|
+
}),
|
|
63
|
+
[conversation],
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<div className="chat">
|
|
68
|
+
<div className="history">
|
|
69
|
+
{messages.map((msg, idx) => {
|
|
70
|
+
if (msg.type === ResponseType.Application) {
|
|
71
|
+
return (
|
|
72
|
+
<div key={idx}>
|
|
73
|
+
{msg.payload.messages.map((m, i) => (
|
|
74
|
+
<div key={i} className="app-msg">
|
|
75
|
+
{m.text}
|
|
76
|
+
</div>
|
|
77
|
+
))}
|
|
78
|
+
</div>
|
|
79
|
+
);
|
|
80
|
+
} else if (
|
|
81
|
+
msg.type === ResponseType.User &&
|
|
82
|
+
msg.payload.type === "text"
|
|
83
|
+
) {
|
|
84
|
+
return (
|
|
85
|
+
<div key={idx} className="user-msg">
|
|
86
|
+
{msg.payload.text}
|
|
87
|
+
</div>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
})}
|
|
91
|
+
</div>
|
|
92
|
+
<form
|
|
93
|
+
onSubmit={(e) => {
|
|
94
|
+
e.preventDefault();
|
|
95
|
+
conversation.sendText(input);
|
|
96
|
+
setInput("");
|
|
97
|
+
}}
|
|
98
|
+
>
|
|
99
|
+
<input
|
|
100
|
+
type="text"
|
|
101
|
+
value={input}
|
|
102
|
+
onChange={(e) => setInput(e.target.value)}
|
|
103
|
+
/>
|
|
104
|
+
</form>
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
const rootElement = document.getElementById("root");
|
|
109
|
+
const root = ReactDOMClient.createRoot(rootElement!);
|
|
110
|
+
|
|
111
|
+
const conversation = createConversation({
|
|
112
|
+
applicationUrl:
|
|
113
|
+
"https://apps.nlx.ai/c/Xq3kT5uVOCGipRW8kW9pB/BajtUGSLN5hoqiSmgTA7B",
|
|
114
|
+
headers: {
|
|
115
|
+
"nlx-api-key": "VkvGvxQ-iQQ/EgpgyJQxkDL-OhmhVwzV",
|
|
116
|
+
},
|
|
117
|
+
languageCode: "en-US",
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
conversation.sendWelcomeFlow();
|
|
121
|
+
|
|
122
|
+
root.render(
|
|
123
|
+
<StrictMode>
|
|
124
|
+
<App conversation={conversation} />
|
|
125
|
+
</StrictMode>,
|
|
126
|
+
);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
[Play with it live](https://playcode.io/react-typescript-playground-hooks--019aca7a-bb1a-76be-adbc-158d25c32b99).
|
|
130
|
+
|
|
131
|
+
Obviously there are many more features that you could implement, but the advantage of a custom implementation is that you only need to implement the features you will actually be using.
|
|
132
|
+
|
|
133
|
+
## Implementing a custom channel
|
|
134
|
+
|
|
135
|
+
If you want your application to communicate through a custom channel, then all you need to do is to deploy a custom NodeJS endpoint (such as AWS Lambda or similar) that uses @nlxai/core to translate the various requests and responses into whatever format your custom channel expects. As an example, here is a way to allow your application to use GitHub Issues as a channel to communicate over (as a Deno app - [explore the implemtentation](https://www.val.town/x/jakubnlx/github-as-an-nlx-channel/code/README.md)):
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import { Octokit } from "npm:@octokit/core";
|
|
139
|
+
import { createConversation, promisify, ResponseType } from "npm:@nlxai/core";
|
|
140
|
+
|
|
141
|
+
const octokit = new Octokit({
|
|
142
|
+
auth: Deno.env.get("GITHUB_TOKEN"),
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
async function run(user: string, issueNumber: number, body?: string) {
|
|
146
|
+
const conversation = createConversation({
|
|
147
|
+
applicationUrl: Deno.env.get("NLX_APPLICATION_URL"),
|
|
148
|
+
headers: {
|
|
149
|
+
"nlx-api-key": Deno.env.get("NLX_API_KEY"),
|
|
150
|
+
},
|
|
151
|
+
languageCode: "en-US",
|
|
152
|
+
conversationId: `issue-${issueNumber}`,
|
|
153
|
+
userId: user,
|
|
154
|
+
});
|
|
155
|
+
const sendWelcomeFlow = promisify(conversation.sendWelcomeFlow, conversation);
|
|
156
|
+
const sendText = promisify(conversation.sendText, conversation);
|
|
157
|
+
let response;
|
|
158
|
+
if (!body) {
|
|
159
|
+
response = await sendWelcomeFlow();
|
|
160
|
+
} else {
|
|
161
|
+
response = await sendText(body);
|
|
162
|
+
}
|
|
163
|
+
if (response.type === ResponseType.Application) {
|
|
164
|
+
for (const message of response.payload.messages) {
|
|
165
|
+
await postComment(issueNumber, message.text);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async function postComment(issueNumber: number, body: string) {
|
|
171
|
+
await octokit.request(
|
|
172
|
+
"POST /repos/{owner}/{repo}/issues/{issue_number}/comments",
|
|
173
|
+
{
|
|
174
|
+
owner: Deno.env.get("GITHUB_OWNER"),
|
|
175
|
+
repo: Deno.env.get("GITHUB_REPO"),
|
|
176
|
+
issue_number: issueNumber,
|
|
177
|
+
body: body,
|
|
178
|
+
},
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export default async function (req: Request): Promise<Response> {
|
|
183
|
+
try {
|
|
184
|
+
const event = req.headers.get("X-GitHub-Event") || "unknown";
|
|
185
|
+
const body = await req.text();
|
|
186
|
+
const payload = JSON.parse(body);
|
|
187
|
+
|
|
188
|
+
console.log(`GitHub webhook: ${event} event received`);
|
|
189
|
+
if (event === "issues" && payload.action === "opened") {
|
|
190
|
+
await run(payload.issue.user.login, payload.issue.number);
|
|
191
|
+
}
|
|
192
|
+
if (
|
|
193
|
+
event === "issue_comment" &&
|
|
194
|
+
payload.action === "created" &&
|
|
195
|
+
payload.comment.user.login !== Deno.env.get("GITHUB_OWNER")
|
|
196
|
+
) {
|
|
197
|
+
console.log("user", payload.comment.user.login);
|
|
198
|
+
await run(
|
|
199
|
+
payload.comment.user.login,
|
|
200
|
+
payload.issue.number,
|
|
201
|
+
payload.comment.body,
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Handle other events
|
|
206
|
+
return Response.json({
|
|
207
|
+
status: "received",
|
|
208
|
+
event,
|
|
209
|
+
action: payload.action || null,
|
|
210
|
+
});
|
|
211
|
+
} catch (error) {
|
|
212
|
+
console.error("Webhook error:", error);
|
|
213
|
+
return Response.json(
|
|
214
|
+
{
|
|
215
|
+
error: "Processing failed",
|
|
216
|
+
message: error.message,
|
|
217
|
+
},
|
|
218
|
+
{ status: 500 },
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
# API reference
|
|
225
|
+
|
|
226
|
+
<!-- include docs/README.md -->
|
|
227
|
+
|
|
228
|
+
## Functions
|
|
229
|
+
|
|
230
|
+
### createConversation()
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
function createConversation(configuration): ConversationHandler;
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Call this to create a conversation handler.
|
|
237
|
+
|
|
238
|
+
#### Parameters
|
|
239
|
+
|
|
240
|
+
##### configuration
|
|
241
|
+
|
|
242
|
+
[`Config`](#config)
|
|
243
|
+
|
|
244
|
+
The necessary configuration to create the conversation.
|
|
245
|
+
|
|
246
|
+
#### Returns
|
|
247
|
+
|
|
248
|
+
[`ConversationHandler`](#conversationhandler)
|
|
249
|
+
|
|
250
|
+
The [ConversationHandler](#conversationhandler) is a bundle of functions to interact with the conversation.
|
|
251
|
+
|
|
252
|
+
#### Example
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
import { createConversation } from "@nlx/core";
|
|
256
|
+
|
|
257
|
+
const conversation = createConversation({
|
|
258
|
+
applicationUrl: "https://apps.nlx.ai/c/cfab3-243ad-232dc",
|
|
259
|
+
headers: {
|
|
260
|
+
"nlx-api-key": "4393029032-dwsd",
|
|
261
|
+
},
|
|
262
|
+
userId: "abcd-1234",
|
|
263
|
+
languageCode: "en-US",
|
|
264
|
+
});
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
### isConfigValid()
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
function isConfigValid(configuration): boolean;
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Check whether a configuration is valid.
|
|
276
|
+
|
|
277
|
+
#### Parameters
|
|
278
|
+
|
|
279
|
+
##### configuration
|
|
280
|
+
|
|
281
|
+
[`Config`](#config)
|
|
282
|
+
|
|
283
|
+
Conversation configuration
|
|
284
|
+
|
|
285
|
+
#### Returns
|
|
286
|
+
|
|
287
|
+
`boolean`
|
|
288
|
+
|
|
289
|
+
Whether the configuration is valid?
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
### shouldReinitialize()
|
|
294
|
+
|
|
295
|
+
```ts
|
|
296
|
+
function shouldReinitialize(config1, config2): boolean;
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
Helper method to decide when a new [Config](#config) requires creating a new [ConversationHandler](#conversationhandler) or whether the old `Config`'s
|
|
300
|
+
`ConversationHandler` can be used.
|
|
301
|
+
|
|
302
|
+
The order of configs doesn't matter.
|
|
303
|
+
|
|
304
|
+
#### Parameters
|
|
35
305
|
|
|
36
|
-
|
|
306
|
+
##### config1
|
|
37
307
|
|
|
38
|
-
|
|
308
|
+
[`Config`](#config)
|
|
39
309
|
|
|
40
|
-
|
|
310
|
+
##### config2
|
|
41
311
|
|
|
42
|
-
|
|
312
|
+
[`Config`](#config)
|
|
43
313
|
|
|
44
|
-
####
|
|
314
|
+
#### Returns
|
|
45
315
|
|
|
46
|
-
|
|
316
|
+
`boolean`
|
|
47
317
|
|
|
48
|
-
|
|
318
|
+
true if `createConversation` should be called again
|
|
49
319
|
|
|
50
|
-
|
|
320
|
+
---
|
|
51
321
|
|
|
52
|
-
|
|
322
|
+
### getCurrentExpirationTimestamp()
|
|
53
323
|
|
|
54
|
-
|
|
324
|
+
```ts
|
|
325
|
+
function getCurrentExpirationTimestamp(responses): number | null;
|
|
326
|
+
```
|
|
55
327
|
|
|
56
|
-
|
|
328
|
+
Get current expiration timestamp from a list of responses. Can be used to determine if a conversation has timed out.
|
|
57
329
|
|
|
58
|
-
|
|
330
|
+
#### Parameters
|
|
59
331
|
|
|
60
|
-
|
|
332
|
+
##### responses
|
|
61
333
|
|
|
62
|
-
|
|
334
|
+
[`Response`](#response)[]
|
|
63
335
|
|
|
64
|
-
|
|
336
|
+
The current list of user and application responses (first argument in the subscribe callback)
|
|
65
337
|
|
|
66
|
-
|
|
338
|
+
#### Returns
|
|
67
339
|
|
|
68
|
-
|
|
340
|
+
`number` \| `null`
|
|
69
341
|
|
|
70
|
-
|
|
342
|
+
An expiration timestamp in Unix Epoch (`new Date().getTime()`), or `null` if this is not known (typically occurs if the application has not responded yet)
|
|
71
343
|
|
|
72
|
-
####
|
|
344
|
+
#### Example
|
|
73
345
|
|
|
74
|
-
|
|
346
|
+
```typescript
|
|
347
|
+
import { useState } from "react";
|
|
348
|
+
import { getCurrentExpirationTimestamp } from "@nlxai/core";
|
|
75
349
|
|
|
76
|
-
|
|
350
|
+
const [isTimedOut, setIsTimedOut] = useState(false);
|
|
77
351
|
|
|
78
|
-
|
|
352
|
+
conversation.subscribe((responses) => {
|
|
353
|
+
const expirationTimestamp = getCurrentExpirationTimestamp(responses);
|
|
354
|
+
if (expirationTimestamp != null && expirationTimestamp < new Date().getTime()) {
|
|
355
|
+
setIsTimedOut(true);
|
|
356
|
+
}
|
|
357
|
+
});
|
|
79
358
|
|
|
80
|
-
|
|
359
|
+
return (<div>
|
|
360
|
+
{isTimedOut ? (
|
|
361
|
+
<p>Your session has timed out. Please start a new conversation.</p>
|
|
362
|
+
) : (
|
|
363
|
+
<p>Your session is active.</p>
|
|
364
|
+
)}
|
|
365
|
+
</div>
|
|
366
|
+
```
|
|
81
367
|
|
|
82
|
-
|
|
368
|
+
---
|
|
83
369
|
|
|
84
|
-
|
|
370
|
+
### promisify()
|
|
85
371
|
|
|
86
|
-
|
|
372
|
+
```ts
|
|
373
|
+
function promisify<Params>(
|
|
374
|
+
fn,
|
|
375
|
+
convo,
|
|
376
|
+
timeout,
|
|
377
|
+
): (payload) => Promise<Response | null>;
|
|
378
|
+
```
|
|
87
379
|
|
|
88
380
|
This package is intentionally designed with a subscription-based API as opposed to a promise-based one where each message corresponds to a single application response, available asynchronously.
|
|
89
381
|
|
|
90
382
|
If you need a promise-based wrapper, you can use the `promisify` helper available in the package:
|
|
91
383
|
|
|
384
|
+
#### Type Parameters
|
|
385
|
+
|
|
386
|
+
##### Params
|
|
387
|
+
|
|
388
|
+
`Params`
|
|
389
|
+
|
|
390
|
+
the type of the function's params, e.g. for `sendText` it's `text: string, context?: Context`
|
|
391
|
+
|
|
392
|
+
#### Parameters
|
|
393
|
+
|
|
394
|
+
##### fn
|
|
395
|
+
|
|
396
|
+
(`payload`) => `void`
|
|
397
|
+
|
|
398
|
+
the function to wrap (e.g. `convo.sendText`, `convo.sendChoice`, etc.)
|
|
399
|
+
|
|
400
|
+
##### convo
|
|
401
|
+
|
|
402
|
+
[`ConversationHandler`](#conversationhandler)
|
|
403
|
+
|
|
404
|
+
the `ConversationHandler` (from [createConversation](#createconversation))
|
|
405
|
+
|
|
406
|
+
##### timeout
|
|
407
|
+
|
|
408
|
+
`number` = `10000`
|
|
409
|
+
|
|
410
|
+
the timeout in milliseconds
|
|
411
|
+
|
|
412
|
+
#### Returns
|
|
413
|
+
|
|
414
|
+
A promise-wrapped version of the function. The function, when called, returns a promise that resolves to the Conversation's next response.
|
|
415
|
+
|
|
92
416
|
```ts
|
|
417
|
+
(payload): Promise<Response | null>;
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
##### Parameters
|
|
421
|
+
|
|
422
|
+
###### payload
|
|
423
|
+
|
|
424
|
+
`Params`
|
|
425
|
+
|
|
426
|
+
##### Returns
|
|
427
|
+
|
|
428
|
+
`Promise`\<[`Response`](#response) \| `null`\>
|
|
429
|
+
|
|
430
|
+
#### Example
|
|
431
|
+
|
|
432
|
+
```typescript
|
|
93
433
|
import { createConversation, promisify } from "@nlxai/core";
|
|
94
434
|
|
|
95
435
|
const convo = createConversation(config);
|
|
@@ -101,12 +441,1515 @@ sendTextWrapped("Hello").then((response) => {
|
|
|
101
441
|
});
|
|
102
442
|
```
|
|
103
443
|
|
|
104
|
-
|
|
444
|
+
## Variables
|
|
445
|
+
|
|
446
|
+
### version
|
|
447
|
+
|
|
448
|
+
```ts
|
|
449
|
+
const version: string = packageJson.version;
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
Package version
|
|
453
|
+
|
|
454
|
+
## Interfaces
|
|
455
|
+
|
|
456
|
+
### Config
|
|
457
|
+
|
|
458
|
+
The configuration necessary to create a conversation.
|
|
459
|
+
|
|
460
|
+
#### Properties
|
|
461
|
+
|
|
462
|
+
##### applicationUrl?
|
|
463
|
+
|
|
464
|
+
```ts
|
|
465
|
+
optional applicationUrl: string;
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
The URL at which your conversational application is running.
|
|
469
|
+
Fetch this from the application's API channel tab.
|
|
470
|
+
|
|
471
|
+
##### headers
|
|
472
|
+
|
|
473
|
+
```ts
|
|
474
|
+
headers: Record<string, string> & object;
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
Headers to forward to the NLX API.
|
|
478
|
+
|
|
479
|
+
###### Type Declaration
|
|
480
|
+
|
|
481
|
+
###### nlx-api-key
|
|
482
|
+
|
|
483
|
+
```ts
|
|
484
|
+
nlx-api-key: string;
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
The `nlx-api-key` is required. Fetch this from the application's API channel tab.
|
|
488
|
+
|
|
489
|
+
##### conversationId?
|
|
490
|
+
|
|
491
|
+
```ts
|
|
492
|
+
optional conversationId: string;
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
Set `conversationId` to continue an existing conversation. If not set, a new conversation will be started (and a new conversationId will be generated internally).
|
|
496
|
+
|
|
497
|
+
##### userId?
|
|
498
|
+
|
|
499
|
+
```ts
|
|
500
|
+
optional userId: string;
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
Setting the `userID` allows it to be searchable in application history, as well as usable via `{System.userId}` in the flow.
|
|
504
|
+
|
|
505
|
+
##### responses?
|
|
506
|
+
|
|
507
|
+
```ts
|
|
508
|
+
optional responses: Response[];
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
When `responses` is set, initialize the chatHandler with historical messages. This is useful when restoring a previous conversation, that perhaps started on a different page.
|
|
512
|
+
|
|
513
|
+
##### failureMessage?
|
|
514
|
+
|
|
515
|
+
```ts
|
|
516
|
+
optional failureMessage: string;
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
When set, this overrides the default failure message ("We encountered an issue. Please try again soon.").
|
|
520
|
+
|
|
521
|
+
##### languageCode
|
|
522
|
+
|
|
523
|
+
```ts
|
|
524
|
+
languageCode: string;
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
The language code to use for the application. In the browser this can be fetched with `navigator.language`.
|
|
528
|
+
If you don't have translations, hard-code this to the language code you support.
|
|
529
|
+
|
|
530
|
+
##### bidirectional?
|
|
531
|
+
|
|
532
|
+
```ts
|
|
533
|
+
optional bidirectional: boolean;
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
Specifies whether the conversation is using bidirectional Voice+ (if so, an additional command socket will be opened).
|
|
537
|
+
|
|
538
|
+
---
|
|
539
|
+
|
|
540
|
+
### ConversationHandler
|
|
541
|
+
|
|
542
|
+
A bundle of functions to interact with a conversation, created by [createConversation](#createconversation).
|
|
543
|
+
|
|
544
|
+
#### Properties
|
|
545
|
+
|
|
546
|
+
##### sendText()
|
|
547
|
+
|
|
548
|
+
```ts
|
|
549
|
+
sendText: (text, context?) => void;
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
Send user's message
|
|
553
|
+
|
|
554
|
+
###### Parameters
|
|
555
|
+
|
|
556
|
+
###### text
|
|
557
|
+
|
|
558
|
+
`string`
|
|
559
|
+
|
|
560
|
+
the user's message
|
|
561
|
+
|
|
562
|
+
###### context?
|
|
563
|
+
|
|
564
|
+
[`Context`](#context)
|
|
565
|
+
|
|
566
|
+
[Context](https://docs.nlx.ai/platform/nlx-platform-guide/build-with-nlx/flows/context-variables#what-are-context-variables) for usage later in the flow.
|
|
567
|
+
|
|
568
|
+
###### Returns
|
|
569
|
+
|
|
570
|
+
`void`
|
|
571
|
+
|
|
572
|
+
##### sendSlots()
|
|
573
|
+
|
|
574
|
+
```ts
|
|
575
|
+
sendSlots: (slots, context?) => void;
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
Send [slots](https://docs.nlx.ai/platform/nlx-platform-guide/build-with-nlx/flows/slots-custom#slot-settings) to the application.
|
|
579
|
+
|
|
580
|
+
###### Parameters
|
|
581
|
+
|
|
582
|
+
###### slots
|
|
583
|
+
|
|
584
|
+
[`SlotsRecordOrArray`](#slotsrecordorarray)
|
|
585
|
+
|
|
586
|
+
The slots to populate
|
|
587
|
+
|
|
588
|
+
###### context?
|
|
589
|
+
|
|
590
|
+
[`Context`](#context)
|
|
591
|
+
|
|
592
|
+
[Context](https://docs.nlx.ai/platform/nlx-platform-guide/build-with-nlx/flows/context-variables#what-are-context-variables) for usage later in the flow.
|
|
593
|
+
|
|
594
|
+
###### Returns
|
|
595
|
+
|
|
596
|
+
`void`
|
|
597
|
+
|
|
598
|
+
##### sendChoice()
|
|
599
|
+
|
|
600
|
+
```ts
|
|
601
|
+
sendChoice: (choiceId, context?, metadata?) => void;
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
Respond to [a choice](https://docs.studio.nlx.ai/intentflows/documentation-flows/flows-build-mode/nodes#user-choice) from the application.
|
|
605
|
+
|
|
606
|
+
###### Parameters
|
|
607
|
+
|
|
608
|
+
###### choiceId
|
|
609
|
+
|
|
610
|
+
`string`
|
|
611
|
+
|
|
612
|
+
The `choiceId` is in the [ApplicationResponse](#applicationresponse)'s `.payload.messages[].choices[].choiceId` fields
|
|
613
|
+
|
|
614
|
+
###### context?
|
|
615
|
+
|
|
616
|
+
[`Context`](#context)
|
|
617
|
+
|
|
618
|
+
[Context](https://docs.nlx.ai/platform/nlx-platform-guide/build-with-nlx/flows/context-variables#what-are-context-variables) for usage later in the flow.
|
|
619
|
+
|
|
620
|
+
###### metadata?
|
|
621
|
+
|
|
622
|
+
[`ChoiceRequestMetadata`](#choicerequestmetadata)
|
|
623
|
+
|
|
624
|
+
links the choice to the specific message and node in the conversation.
|
|
625
|
+
|
|
626
|
+
###### Returns
|
|
627
|
+
|
|
628
|
+
`void`
|
|
629
|
+
|
|
630
|
+
##### sendWelcomeFlow()
|
|
631
|
+
|
|
632
|
+
```ts
|
|
633
|
+
sendWelcomeFlow: (context?) => void;
|
|
634
|
+
```
|
|
635
|
+
|
|
636
|
+
Trigger the welcome flow. This should be done when the user starts interacting with the conversation.
|
|
637
|
+
|
|
638
|
+
###### Parameters
|
|
639
|
+
|
|
640
|
+
###### context?
|
|
641
|
+
|
|
642
|
+
[`Context`](#context)
|
|
643
|
+
|
|
644
|
+
[Context](https://docs.nlx.ai/platform/nlx-platform-guide/build-with-nlx/flows/context-variables#what-are-context-variables) for usage later in the flow.
|
|
645
|
+
|
|
646
|
+
###### Returns
|
|
647
|
+
|
|
648
|
+
`void`
|
|
649
|
+
|
|
650
|
+
##### sendFlow()
|
|
651
|
+
|
|
652
|
+
```ts
|
|
653
|
+
sendFlow: (flowId, context?) => void;
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
Trigger a specific flow.
|
|
657
|
+
|
|
658
|
+
###### Parameters
|
|
659
|
+
|
|
660
|
+
###### flowId
|
|
661
|
+
|
|
662
|
+
`string`
|
|
663
|
+
|
|
664
|
+
the flow to trigger. The id is the name under the application's _Intents_.
|
|
665
|
+
|
|
666
|
+
###### context?
|
|
667
|
+
|
|
668
|
+
[`Context`](#context)
|
|
669
|
+
|
|
670
|
+
[Context](https://docs.nlx.ai/platform/nlx-platform-guide/build-with-nlx/flows/context-variables#what-are-context-variables) for usage later in the intent.
|
|
671
|
+
|
|
672
|
+
###### Returns
|
|
673
|
+
|
|
674
|
+
`void`
|
|
675
|
+
|
|
676
|
+
##### sendContext()
|
|
677
|
+
|
|
678
|
+
```ts
|
|
679
|
+
sendContext: (context) => Promise<void>;
|
|
680
|
+
```
|
|
681
|
+
|
|
682
|
+
Send context without sending a message
|
|
683
|
+
|
|
684
|
+
###### Parameters
|
|
685
|
+
|
|
686
|
+
###### context
|
|
687
|
+
|
|
688
|
+
[`Context`](#context)
|
|
689
|
+
|
|
690
|
+
[Context](https://docs.nlx.ai/platform/nlx-platform-guide/build-with-nlx/flows/context-variables#what-are-context-variables) for usage later in the intent.
|
|
691
|
+
|
|
692
|
+
###### Returns
|
|
693
|
+
|
|
694
|
+
`Promise`\<`void`\>
|
|
695
|
+
|
|
696
|
+
##### appendMessageToTranscript()
|
|
697
|
+
|
|
698
|
+
```ts
|
|
699
|
+
appendMessageToTranscript: (response) => void;
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
Append messages manually to the transcript. This is an advanced feature that allows routing and aggregation of different chat message
|
|
703
|
+
sources.
|
|
704
|
+
|
|
705
|
+
###### Parameters
|
|
706
|
+
|
|
707
|
+
###### response
|
|
708
|
+
|
|
709
|
+
the response with optional timestamps.
|
|
710
|
+
|
|
711
|
+
`Omit`\<[`ApplicationResponse`](#applicationresponse), `"receivedAt"`\> & `object` | `Omit`\<[`UserResponse`](#userresponse), `"receivedAt"`\> & `object` | `Omit`\<[`FailureMessage`](#failuremessage-1), `"receivedAt"`\> & `object`
|
|
712
|
+
|
|
713
|
+
###### Returns
|
|
714
|
+
|
|
715
|
+
`void`
|
|
716
|
+
|
|
717
|
+
##### sendStructured()
|
|
718
|
+
|
|
719
|
+
```ts
|
|
720
|
+
sendStructured: (request, context?) => void;
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
Send a combination of choice, slots, and intent in one request.
|
|
724
|
+
|
|
725
|
+
###### Parameters
|
|
726
|
+
|
|
727
|
+
###### request
|
|
728
|
+
|
|
729
|
+
[`StructuredRequest`](#structuredrequest)
|
|
730
|
+
|
|
731
|
+
###### context?
|
|
732
|
+
|
|
733
|
+
[`Context`](#context)
|
|
734
|
+
|
|
735
|
+
[Context](https://docs.studio.nlx.ai/workspacesettings/documentation-settings/settings-context-attributes) for usage later in the intent.
|
|
736
|
+
|
|
737
|
+
###### Returns
|
|
738
|
+
|
|
739
|
+
`void`
|
|
740
|
+
|
|
741
|
+
##### subscribe()
|
|
742
|
+
|
|
743
|
+
```ts
|
|
744
|
+
subscribe: (subscriber) => () => void;
|
|
745
|
+
```
|
|
746
|
+
|
|
747
|
+
Subscribe a callback to the conversation. On subscribe, the subscriber will receive all of the Responses that the conversation has already received.
|
|
748
|
+
|
|
749
|
+
###### Parameters
|
|
750
|
+
|
|
751
|
+
###### subscriber
|
|
752
|
+
|
|
753
|
+
[`Subscriber`](#subscriber)
|
|
754
|
+
|
|
755
|
+
The callback to subscribe
|
|
756
|
+
|
|
757
|
+
###### Returns
|
|
758
|
+
|
|
759
|
+
A function to unsubscribe the callback.
|
|
760
|
+
|
|
761
|
+
```ts
|
|
762
|
+
(): void;
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
###### Returns
|
|
766
|
+
|
|
767
|
+
`void`
|
|
768
|
+
|
|
769
|
+
##### unsubscribe()
|
|
770
|
+
|
|
771
|
+
```ts
|
|
772
|
+
unsubscribe: (subscriber) => void;
|
|
773
|
+
```
|
|
774
|
+
|
|
775
|
+
Unsubscribe a callback from the conversation.
|
|
776
|
+
|
|
777
|
+
###### Parameters
|
|
778
|
+
|
|
779
|
+
###### subscriber
|
|
780
|
+
|
|
781
|
+
[`Subscriber`](#subscriber)
|
|
782
|
+
|
|
783
|
+
The callback to unsubscribe
|
|
784
|
+
|
|
785
|
+
###### Returns
|
|
786
|
+
|
|
787
|
+
`void`
|
|
788
|
+
|
|
789
|
+
##### unsubscribeAll()
|
|
790
|
+
|
|
791
|
+
```ts
|
|
792
|
+
unsubscribeAll: () => void;
|
|
793
|
+
```
|
|
794
|
+
|
|
795
|
+
Unsubscribe all callback from the conversation.
|
|
796
|
+
|
|
797
|
+
###### Returns
|
|
798
|
+
|
|
799
|
+
`void`
|
|
800
|
+
|
|
801
|
+
##### currentConversationId()
|
|
802
|
+
|
|
803
|
+
```ts
|
|
804
|
+
currentConversationId: () => string | undefined;
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
Get the current conversation ID if it's set, or undefined if there is no conversation.
|
|
808
|
+
|
|
809
|
+
###### Returns
|
|
810
|
+
|
|
811
|
+
`string` \| `undefined`
|
|
812
|
+
|
|
813
|
+
##### currentLanguageCode()
|
|
814
|
+
|
|
815
|
+
```ts
|
|
816
|
+
currentLanguageCode: () => string;
|
|
817
|
+
```
|
|
818
|
+
|
|
819
|
+
Get the current language code
|
|
820
|
+
|
|
821
|
+
###### Returns
|
|
822
|
+
|
|
823
|
+
`string`
|
|
824
|
+
|
|
825
|
+
##### setLanguageCode()
|
|
826
|
+
|
|
827
|
+
```ts
|
|
828
|
+
setLanguageCode: (languageCode) => void;
|
|
829
|
+
```
|
|
830
|
+
|
|
831
|
+
Set the language code
|
|
832
|
+
|
|
833
|
+
###### Parameters
|
|
834
|
+
|
|
835
|
+
###### languageCode
|
|
836
|
+
|
|
837
|
+
`string`
|
|
838
|
+
|
|
839
|
+
###### Returns
|
|
840
|
+
|
|
841
|
+
`void`
|
|
842
|
+
|
|
843
|
+
##### reset()
|
|
844
|
+
|
|
845
|
+
```ts
|
|
846
|
+
reset: (options?) => void;
|
|
847
|
+
```
|
|
848
|
+
|
|
849
|
+
Forces a new conversation. If `clearResponses` is set to true, will also clear historical responses passed to subscribers.
|
|
850
|
+
Retains all existing subscribers.
|
|
851
|
+
|
|
852
|
+
###### Parameters
|
|
853
|
+
|
|
854
|
+
###### options?
|
|
855
|
+
|
|
856
|
+
###### clearResponses?
|
|
857
|
+
|
|
858
|
+
`boolean`
|
|
859
|
+
|
|
860
|
+
If set to true, will clear historical responses passed to subscribers.
|
|
861
|
+
|
|
862
|
+
###### Returns
|
|
863
|
+
|
|
864
|
+
`void`
|
|
865
|
+
|
|
866
|
+
##### destroy()
|
|
867
|
+
|
|
868
|
+
```ts
|
|
869
|
+
destroy: () => void;
|
|
870
|
+
```
|
|
871
|
+
|
|
872
|
+
Removes all subscribers and, if using websockets, closes the connection.
|
|
873
|
+
|
|
874
|
+
###### Returns
|
|
875
|
+
|
|
876
|
+
`void`
|
|
877
|
+
|
|
878
|
+
##### setRequestOverride()
|
|
879
|
+
|
|
880
|
+
```ts
|
|
881
|
+
setRequestOverride: (override) => void;
|
|
882
|
+
```
|
|
883
|
+
|
|
884
|
+
Optional [RequestOverride](#requestoverride) function used to bypass the application request and handle them in a custom fashion
|
|
885
|
+
|
|
886
|
+
###### Parameters
|
|
887
|
+
|
|
888
|
+
###### override
|
|
889
|
+
|
|
890
|
+
[`RequestOverride`](#requestoverride) | `undefined`
|
|
891
|
+
|
|
892
|
+
###### Returns
|
|
893
|
+
|
|
894
|
+
`void`
|
|
895
|
+
|
|
896
|
+
##### addEventListener()
|
|
897
|
+
|
|
898
|
+
```ts
|
|
899
|
+
addEventListener: (event, handler) => void;
|
|
900
|
+
```
|
|
901
|
+
|
|
902
|
+
Add a listener to one of the handler's custom events
|
|
903
|
+
|
|
904
|
+
###### Parameters
|
|
905
|
+
|
|
906
|
+
###### event
|
|
907
|
+
|
|
908
|
+
`"voicePlusCommand"`
|
|
909
|
+
|
|
910
|
+
###### handler
|
|
911
|
+
|
|
912
|
+
(`payload`) => `void`
|
|
913
|
+
|
|
914
|
+
###### Returns
|
|
915
|
+
|
|
916
|
+
`void`
|
|
917
|
+
|
|
918
|
+
##### removeEventListener()
|
|
919
|
+
|
|
920
|
+
```ts
|
|
921
|
+
removeEventListener: (event, handler) => void;
|
|
922
|
+
```
|
|
923
|
+
|
|
924
|
+
Remove a listener to one of the handler's custom events
|
|
925
|
+
|
|
926
|
+
###### Parameters
|
|
927
|
+
|
|
928
|
+
###### event
|
|
929
|
+
|
|
930
|
+
`"voicePlusCommand"`
|
|
931
|
+
|
|
932
|
+
###### handler
|
|
933
|
+
|
|
934
|
+
(`payload`) => `void`
|
|
935
|
+
|
|
936
|
+
###### Returns
|
|
937
|
+
|
|
938
|
+
`void`
|
|
939
|
+
|
|
940
|
+
---
|
|
941
|
+
|
|
942
|
+
### SlotValue
|
|
943
|
+
|
|
944
|
+
Values to fill an intent's [attached slots](https://docs.studio.nlx.ai/intents/documentation-intents/intents-attached-slots).
|
|
945
|
+
|
|
946
|
+
An array of `SlotValue` objects is equivalent to a [SlotsRecord](#slotsrecord).
|
|
947
|
+
|
|
948
|
+
#### Properties
|
|
949
|
+
|
|
950
|
+
##### slotId
|
|
951
|
+
|
|
952
|
+
```ts
|
|
953
|
+
slotId: string;
|
|
954
|
+
```
|
|
955
|
+
|
|
956
|
+
The attached slot's name
|
|
957
|
+
|
|
958
|
+
##### value
|
|
959
|
+
|
|
960
|
+
```ts
|
|
961
|
+
value: any;
|
|
962
|
+
```
|
|
963
|
+
|
|
964
|
+
Usually this will be a discrete value matching the slots's [type](https://docs.studio.nlx.ai/slots/documentation-slots/slots-values#system-slots).
|
|
965
|
+
for custom slots, this can optionally be the value's ID.
|
|
966
|
+
|
|
967
|
+
---
|
|
968
|
+
|
|
969
|
+
### ApplicationResponse
|
|
970
|
+
|
|
971
|
+
A message from the application
|
|
972
|
+
|
|
973
|
+
See also:
|
|
974
|
+
|
|
975
|
+
- [UserResponse](#userresponse)
|
|
976
|
+
- [FailureMessage](#failuremessage-1)
|
|
977
|
+
- [Response](#response)
|
|
978
|
+
|
|
979
|
+
#### Properties
|
|
980
|
+
|
|
981
|
+
##### type
|
|
982
|
+
|
|
983
|
+
```ts
|
|
984
|
+
type: Application;
|
|
985
|
+
```
|
|
986
|
+
|
|
987
|
+
The application response type
|
|
988
|
+
|
|
989
|
+
##### receivedAt
|
|
990
|
+
|
|
991
|
+
```ts
|
|
992
|
+
receivedAt: number;
|
|
993
|
+
```
|
|
994
|
+
|
|
995
|
+
When the response was received
|
|
996
|
+
|
|
997
|
+
##### payload
|
|
998
|
+
|
|
999
|
+
```ts
|
|
1000
|
+
payload: ApplicationResponsePayload;
|
|
1001
|
+
```
|
|
1002
|
+
|
|
1003
|
+
The payload of the response
|
|
1004
|
+
|
|
1005
|
+
---
|
|
1006
|
+
|
|
1007
|
+
### ApplicationResponsePayload
|
|
1008
|
+
|
|
1009
|
+
The payload of the application response
|
|
1010
|
+
|
|
1011
|
+
#### Properties
|
|
1012
|
+
|
|
1013
|
+
##### expirationTimestamp?
|
|
1014
|
+
|
|
1015
|
+
```ts
|
|
1016
|
+
optional expirationTimestamp: number;
|
|
1017
|
+
```
|
|
1018
|
+
|
|
1019
|
+
If there isn't some interaction by this time, the conversation will expire.
|
|
1020
|
+
|
|
1021
|
+
##### conversationId?
|
|
1022
|
+
|
|
1023
|
+
```ts
|
|
1024
|
+
optional conversationId: string;
|
|
1025
|
+
```
|
|
1026
|
+
|
|
1027
|
+
The active conversation ID. If not set, a new conversation will be started.
|
|
1028
|
+
|
|
1029
|
+
##### messages
|
|
1030
|
+
|
|
1031
|
+
```ts
|
|
1032
|
+
messages: ApplicationMessage[];
|
|
1033
|
+
```
|
|
1034
|
+
|
|
1035
|
+
Any messages from the application.
|
|
1036
|
+
|
|
1037
|
+
##### metadata?
|
|
1038
|
+
|
|
1039
|
+
```ts
|
|
1040
|
+
optional metadata: ApplicationResponseMetadata;
|
|
1041
|
+
```
|
|
1042
|
+
|
|
1043
|
+
Global state about the current conversation
|
|
1044
|
+
as well as whether the client should poll for more application responses.
|
|
1045
|
+
|
|
1046
|
+
##### payload?
|
|
1047
|
+
|
|
1048
|
+
```ts
|
|
1049
|
+
optional payload: string;
|
|
1050
|
+
```
|
|
1051
|
+
|
|
1052
|
+
If configured, the [node's payload.](See: https://docs.studio.nlx.ai/intentflows/documentation-flows/flows-build-mode/advanced-messaging-+-functionality#add-functionality)
|
|
1053
|
+
|
|
1054
|
+
##### modalities?
|
|
1055
|
+
|
|
1056
|
+
```ts
|
|
1057
|
+
optional modalities: ModalityPayloads;
|
|
1058
|
+
```
|
|
1059
|
+
|
|
1060
|
+
If configured, the node's modalities and their payloads.
|
|
1061
|
+
|
|
1062
|
+
##### context?
|
|
1063
|
+
|
|
1064
|
+
```ts
|
|
1065
|
+
optional context: Context;
|
|
1066
|
+
```
|
|
1067
|
+
|
|
1068
|
+
If the node is set to send context, the whole context associated with the conversation.
|
|
1069
|
+
|
|
1070
|
+
---
|
|
1071
|
+
|
|
1072
|
+
### ApplicationResponseMetadata
|
|
1073
|
+
|
|
1074
|
+
Global state about the current conversation
|
|
1075
|
+
as well as whether the client should poll for more application responses.
|
|
1076
|
+
|
|
1077
|
+
#### Properties
|
|
1078
|
+
|
|
1079
|
+
##### intentId?
|
|
1080
|
+
|
|
1081
|
+
```ts
|
|
1082
|
+
optional intentId: string;
|
|
1083
|
+
```
|
|
1084
|
+
|
|
1085
|
+
The conversation's intent
|
|
1086
|
+
|
|
1087
|
+
##### escalation?
|
|
1088
|
+
|
|
1089
|
+
```ts
|
|
1090
|
+
optional escalation: boolean;
|
|
1091
|
+
```
|
|
1092
|
+
|
|
1093
|
+
Whether the current conversation has been marked as incomprehension.
|
|
1094
|
+
|
|
1095
|
+
##### frustration?
|
|
1096
|
+
|
|
1097
|
+
```ts
|
|
1098
|
+
optional frustration: boolean;
|
|
1099
|
+
```
|
|
1100
|
+
|
|
1101
|
+
Whether the current conversation has been marked frustrated
|
|
1102
|
+
|
|
1103
|
+
##### incomprehension?
|
|
1104
|
+
|
|
1105
|
+
```ts
|
|
1106
|
+
optional incomprehension: boolean;
|
|
1107
|
+
```
|
|
1108
|
+
|
|
1109
|
+
Whether the current conversation has been marked as incomprehension.
|
|
1110
|
+
|
|
1111
|
+
##### uploadUrls
|
|
1112
|
+
|
|
1113
|
+
```ts
|
|
1114
|
+
uploadUrls: UploadUrl[];
|
|
1115
|
+
```
|
|
1116
|
+
|
|
1117
|
+
Upload URL's
|
|
1118
|
+
|
|
1119
|
+
##### hasPendingDataRequest?
|
|
1120
|
+
|
|
1121
|
+
```ts
|
|
1122
|
+
optional hasPendingDataRequest: boolean;
|
|
1123
|
+
```
|
|
1124
|
+
|
|
1125
|
+
Whether the client should poll for more application responses.
|
|
1126
|
+
|
|
1127
|
+
##### sources?
|
|
1128
|
+
|
|
1129
|
+
```ts
|
|
1130
|
+
optional sources: KnowledgeBaseResponseSource[];
|
|
1131
|
+
```
|
|
1132
|
+
|
|
1133
|
+
Knowledge base sources
|
|
1134
|
+
|
|
1135
|
+
---
|
|
1136
|
+
|
|
1137
|
+
### KnowledgeBaseResponseSource
|
|
1138
|
+
|
|
1139
|
+
Response for knowlege base sources
|
|
1140
|
+
|
|
1141
|
+
#### Properties
|
|
1142
|
+
|
|
1143
|
+
##### fileName?
|
|
1144
|
+
|
|
1145
|
+
```ts
|
|
1146
|
+
optional fileName: string;
|
|
1147
|
+
```
|
|
1148
|
+
|
|
1149
|
+
File name
|
|
1150
|
+
|
|
1151
|
+
##### pageNumber?
|
|
1152
|
+
|
|
1153
|
+
```ts
|
|
1154
|
+
optional pageNumber: number;
|
|
1155
|
+
```
|
|
1156
|
+
|
|
1157
|
+
Page number
|
|
1158
|
+
|
|
1159
|
+
##### content?
|
|
1160
|
+
|
|
1161
|
+
```ts
|
|
1162
|
+
optional content: string;
|
|
1163
|
+
```
|
|
1164
|
+
|
|
1165
|
+
Content
|
|
1166
|
+
|
|
1167
|
+
##### metadata?
|
|
1168
|
+
|
|
1169
|
+
```ts
|
|
1170
|
+
optional metadata: Record<string, unknown>;
|
|
1171
|
+
```
|
|
1172
|
+
|
|
1173
|
+
Metadata
|
|
1174
|
+
|
|
1175
|
+
##### presignedUrl?
|
|
1176
|
+
|
|
1177
|
+
```ts
|
|
1178
|
+
optional presignedUrl: string;
|
|
1179
|
+
```
|
|
1180
|
+
|
|
1181
|
+
Presigned URL for direct retrieval
|
|
1182
|
+
|
|
1183
|
+
---
|
|
1184
|
+
|
|
1185
|
+
### ApplicationMessageMetadata
|
|
1186
|
+
|
|
1187
|
+
Metadata for the individual application message
|
|
1188
|
+
as well as whether the client should poll for more application responses.
|
|
1189
|
+
|
|
1190
|
+
#### Properties
|
|
1191
|
+
|
|
1192
|
+
##### intentId?
|
|
1193
|
+
|
|
1194
|
+
```ts
|
|
1195
|
+
optional intentId: string;
|
|
1196
|
+
```
|
|
1197
|
+
|
|
1198
|
+
The message node's intent
|
|
1199
|
+
|
|
1200
|
+
---
|
|
1201
|
+
|
|
1202
|
+
### ApplicationMessage
|
|
1203
|
+
|
|
1204
|
+
A message from the application, as well as any choices the user can make.
|
|
1205
|
+
|
|
1206
|
+
#### Properties
|
|
1207
|
+
|
|
1208
|
+
##### messageId?
|
|
1209
|
+
|
|
1210
|
+
```ts
|
|
1211
|
+
optional messageId: string;
|
|
1212
|
+
```
|
|
1213
|
+
|
|
1214
|
+
A unique identifier for the message.
|
|
1215
|
+
|
|
1216
|
+
##### nodeId?
|
|
1217
|
+
|
|
1218
|
+
```ts
|
|
1219
|
+
optional nodeId: string;
|
|
1220
|
+
```
|
|
1221
|
+
|
|
1222
|
+
The node id that this message is associated with.
|
|
1223
|
+
This is must be sent with a choice when the user is changing a previously sent choice.
|
|
1224
|
+
|
|
1225
|
+
##### text
|
|
1226
|
+
|
|
1227
|
+
```ts
|
|
1228
|
+
text: string;
|
|
1229
|
+
```
|
|
1230
|
+
|
|
1231
|
+
The body of the message. Show this to the user.
|
|
1232
|
+
|
|
1233
|
+
##### choices
|
|
1234
|
+
|
|
1235
|
+
```ts
|
|
1236
|
+
choices: Choice[];
|
|
1237
|
+
```
|
|
1238
|
+
|
|
1239
|
+
A selection of choices to show to the user. They may choose one of them.
|
|
1240
|
+
|
|
1241
|
+
##### metadata?
|
|
1242
|
+
|
|
1243
|
+
```ts
|
|
1244
|
+
optional metadata: ApplicationMessageMetadata;
|
|
1245
|
+
```
|
|
1246
|
+
|
|
1247
|
+
Metadata
|
|
1248
|
+
|
|
1249
|
+
##### selectedChoiceId?
|
|
1250
|
+
|
|
1251
|
+
```ts
|
|
1252
|
+
optional selectedChoiceId: string;
|
|
1253
|
+
```
|
|
1254
|
+
|
|
1255
|
+
After a choice has been made by the user, this will be updated locally to the selected choice id.
|
|
1256
|
+
This field is set locally and does not come from the application.
|
|
1257
|
+
|
|
1258
|
+
---
|
|
1259
|
+
|
|
1260
|
+
### UploadUrl
|
|
1261
|
+
|
|
1262
|
+
The upload destination for handling conversing with files
|
|
1263
|
+
|
|
1264
|
+
#### Properties
|
|
1265
|
+
|
|
1266
|
+
##### url
|
|
1267
|
+
|
|
1268
|
+
```ts
|
|
1269
|
+
url: string;
|
|
1270
|
+
```
|
|
1271
|
+
|
|
1272
|
+
The URL of the upload
|
|
1273
|
+
|
|
1274
|
+
##### uploadId
|
|
1275
|
+
|
|
1276
|
+
```ts
|
|
1277
|
+
uploadId: string;
|
|
1278
|
+
```
|
|
1279
|
+
|
|
1280
|
+
The ID of the upload
|
|
1281
|
+
|
|
1282
|
+
---
|
|
1283
|
+
|
|
1284
|
+
### Choice
|
|
1285
|
+
|
|
1286
|
+
A choices to show to the user.
|
|
1287
|
+
|
|
1288
|
+
#### Properties
|
|
1289
|
+
|
|
1290
|
+
##### choiceId
|
|
1291
|
+
|
|
1292
|
+
```ts
|
|
1293
|
+
choiceId: string;
|
|
1294
|
+
```
|
|
1295
|
+
|
|
1296
|
+
`choiceId` is used by `sendChoice` to let the user choose this choice.
|
|
1297
|
+
|
|
1298
|
+
##### choiceText
|
|
1299
|
+
|
|
1300
|
+
```ts
|
|
1301
|
+
choiceText: string;
|
|
1302
|
+
```
|
|
1303
|
+
|
|
1304
|
+
The text of the choice
|
|
1305
|
+
|
|
1306
|
+
##### choicePayload?
|
|
1307
|
+
|
|
1308
|
+
```ts
|
|
1309
|
+
optional choicePayload: any;
|
|
1310
|
+
```
|
|
1311
|
+
|
|
1312
|
+
An optional, schemaless payload for the choice.
|
|
1313
|
+
|
|
1314
|
+
---
|
|
1315
|
+
|
|
1316
|
+
### UserResponse
|
|
1317
|
+
|
|
1318
|
+
A message from the user
|
|
1319
|
+
|
|
1320
|
+
See also:
|
|
1321
|
+
|
|
1322
|
+
- [ApplicationResponse](#applicationresponse)
|
|
1323
|
+
- [FailureMessage](#failuremessage-1)
|
|
1324
|
+
- [Response](#response)
|
|
1325
|
+
|
|
1326
|
+
#### Properties
|
|
1327
|
+
|
|
1328
|
+
##### type
|
|
1329
|
+
|
|
1330
|
+
```ts
|
|
1331
|
+
type: User;
|
|
1332
|
+
```
|
|
1333
|
+
|
|
1334
|
+
The user response type
|
|
1335
|
+
|
|
1336
|
+
##### receivedAt
|
|
1337
|
+
|
|
1338
|
+
```ts
|
|
1339
|
+
receivedAt: number;
|
|
1340
|
+
```
|
|
1341
|
+
|
|
1342
|
+
When the response was received
|
|
1343
|
+
|
|
1344
|
+
##### payload
|
|
1345
|
+
|
|
1346
|
+
```ts
|
|
1347
|
+
payload: UserResponsePayload;
|
|
1348
|
+
```
|
|
1349
|
+
|
|
1350
|
+
The payload of the response
|
|
1351
|
+
|
|
1352
|
+
---
|
|
1353
|
+
|
|
1354
|
+
### FailureMessage
|
|
1355
|
+
|
|
1356
|
+
A failure message is received when the NLX api is unreachable, or sends an unparsable response.
|
|
1357
|
+
|
|
1358
|
+
#### Properties
|
|
1359
|
+
|
|
1360
|
+
##### type
|
|
1361
|
+
|
|
1362
|
+
```ts
|
|
1363
|
+
type: Failure;
|
|
1364
|
+
```
|
|
1365
|
+
|
|
1366
|
+
The failure response type
|
|
1367
|
+
|
|
1368
|
+
##### payload
|
|
1369
|
+
|
|
1370
|
+
```ts
|
|
1371
|
+
payload: object;
|
|
1372
|
+
```
|
|
1373
|
+
|
|
1374
|
+
The payload only includes an error message.
|
|
1375
|
+
|
|
1376
|
+
###### text
|
|
1377
|
+
|
|
1378
|
+
```ts
|
|
1379
|
+
text: string;
|
|
1380
|
+
```
|
|
1381
|
+
|
|
1382
|
+
The error message is either the default, or the `failureMessage` set in the [Config](#config).
|
|
1383
|
+
|
|
1384
|
+
##### receivedAt
|
|
1385
|
+
|
|
1386
|
+
```ts
|
|
1387
|
+
receivedAt: number;
|
|
1388
|
+
```
|
|
1389
|
+
|
|
1390
|
+
When the failure occurred.
|
|
1391
|
+
|
|
1392
|
+
---
|
|
1393
|
+
|
|
1394
|
+
### StructuredRequest
|
|
1395
|
+
|
|
1396
|
+
The body of `sendStructured`
|
|
1397
|
+
Includes a combination of choice, slots, and intent in one request.
|
|
1398
|
+
|
|
1399
|
+
#### Properties
|
|
1400
|
+
|
|
1401
|
+
##### choiceId?
|
|
1402
|
+
|
|
1403
|
+
```ts
|
|
1404
|
+
optional choiceId: string;
|
|
1405
|
+
```
|
|
1406
|
+
|
|
1407
|
+
The `choiceId` is in the [ApplicationResponse](#applicationresponse)'s `.payload.messages[].choices[].choiceId` fields
|
|
1408
|
+
|
|
1409
|
+
##### nodeId?
|
|
1410
|
+
|
|
1411
|
+
```ts
|
|
1412
|
+
optional nodeId: string;
|
|
1413
|
+
```
|
|
1414
|
+
|
|
1415
|
+
Required if you want to change a choice that's already been sent.
|
|
1416
|
+
The `nodeId` can be found in the corresponding [ApplicationMessage](#applicationmessage).
|
|
1417
|
+
|
|
1418
|
+
##### ~~intentId?~~
|
|
1419
|
+
|
|
1420
|
+
```ts
|
|
1421
|
+
optional intentId: string;
|
|
1422
|
+
```
|
|
1423
|
+
|
|
1424
|
+
The intent to trigger. The `intentId` is the name under the application's _Intents_.
|
|
1425
|
+
|
|
1426
|
+
###### Deprecated
|
|
1427
|
+
|
|
1428
|
+
use `flowId` instead.
|
|
1429
|
+
|
|
1430
|
+
##### flowId?
|
|
1431
|
+
|
|
1432
|
+
```ts
|
|
1433
|
+
optional flowId: string;
|
|
1434
|
+
```
|
|
1435
|
+
|
|
1436
|
+
The flow to trigger. The `flowId` is the name under the application's _Flows_.
|
|
1437
|
+
|
|
1438
|
+
##### slots?
|
|
1439
|
+
|
|
1440
|
+
```ts
|
|
1441
|
+
optional slots: SlotsRecordOrArray;
|
|
1442
|
+
```
|
|
1443
|
+
|
|
1444
|
+
The slots to populate
|
|
1445
|
+
|
|
1446
|
+
##### uploadIds?
|
|
1447
|
+
|
|
1448
|
+
```ts
|
|
1449
|
+
optional uploadIds: string[];
|
|
1450
|
+
```
|
|
1451
|
+
|
|
1452
|
+
Upload ID
|
|
1453
|
+
|
|
1454
|
+
##### utterance?
|
|
1455
|
+
|
|
1456
|
+
```ts
|
|
1457
|
+
optional utterance: string;
|
|
1458
|
+
```
|
|
1459
|
+
|
|
1460
|
+
Upload utterance
|
|
1461
|
+
|
|
1462
|
+
---
|
|
1463
|
+
|
|
1464
|
+
### ApplicationRequest
|
|
1465
|
+
|
|
1466
|
+
The request data actually sent to the application, slightly different from [UserResponsePayload](#userresponsepayload-1), which includes some UI-specific information
|
|
1467
|
+
|
|
1468
|
+
#### Properties
|
|
1469
|
+
|
|
1470
|
+
##### conversationId?
|
|
1471
|
+
|
|
1472
|
+
```ts
|
|
1473
|
+
optional conversationId: string;
|
|
1474
|
+
```
|
|
1475
|
+
|
|
1476
|
+
The current conversation ID
|
|
1477
|
+
|
|
1478
|
+
##### userId?
|
|
1479
|
+
|
|
1480
|
+
```ts
|
|
1481
|
+
optional userId: string;
|
|
1482
|
+
```
|
|
1483
|
+
|
|
1484
|
+
The current user ID
|
|
1485
|
+
|
|
1486
|
+
##### context?
|
|
1487
|
+
|
|
1488
|
+
```ts
|
|
1489
|
+
optional context: Context;
|
|
1490
|
+
```
|
|
1491
|
+
|
|
1492
|
+
Request context, if applicable
|
|
1493
|
+
|
|
1494
|
+
##### request
|
|
1495
|
+
|
|
1496
|
+
```ts
|
|
1497
|
+
request: object;
|
|
1498
|
+
```
|
|
1499
|
+
|
|
1500
|
+
Main request
|
|
1501
|
+
|
|
1502
|
+
###### unstructured?
|
|
1503
|
+
|
|
1504
|
+
```ts
|
|
1505
|
+
optional unstructured: object;
|
|
1506
|
+
```
|
|
1507
|
+
|
|
1508
|
+
Unstructured request
|
|
1509
|
+
|
|
1510
|
+
###### unstructured.text
|
|
1511
|
+
|
|
1512
|
+
```ts
|
|
1513
|
+
text: string;
|
|
1514
|
+
```
|
|
1515
|
+
|
|
1516
|
+
Request body text
|
|
1517
|
+
|
|
1518
|
+
###### structured?
|
|
1519
|
+
|
|
1520
|
+
```ts
|
|
1521
|
+
optional structured: StructuredRequest & object;
|
|
1522
|
+
```
|
|
1523
|
+
|
|
1524
|
+
Structured request
|
|
1525
|
+
|
|
1526
|
+
###### Type Declaration
|
|
1527
|
+
|
|
1528
|
+
###### slots?
|
|
1529
|
+
|
|
1530
|
+
```ts
|
|
1531
|
+
optional slots: SlotValue[];
|
|
1532
|
+
```
|
|
1533
|
+
|
|
1534
|
+
Only array-form slots are allowed for the purposes of sending to the backend
|
|
1535
|
+
|
|
1536
|
+
---
|
|
1537
|
+
|
|
1538
|
+
### VoiceCredentials
|
|
1539
|
+
|
|
1540
|
+
Credentials to connect to a Voice channel
|
|
1541
|
+
|
|
1542
|
+
#### Properties
|
|
1543
|
+
|
|
1544
|
+
##### url
|
|
1545
|
+
|
|
1546
|
+
```ts
|
|
1547
|
+
url: string;
|
|
1548
|
+
```
|
|
1549
|
+
|
|
1550
|
+
Voice Connection URL
|
|
1551
|
+
|
|
1552
|
+
##### roomName
|
|
1553
|
+
|
|
1554
|
+
```ts
|
|
1555
|
+
roomName: string;
|
|
1556
|
+
```
|
|
1557
|
+
|
|
1558
|
+
Voice room name
|
|
1559
|
+
|
|
1560
|
+
##### token
|
|
1561
|
+
|
|
1562
|
+
```ts
|
|
1563
|
+
token: string;
|
|
1564
|
+
```
|
|
1565
|
+
|
|
1566
|
+
Voice token
|
|
1567
|
+
|
|
1568
|
+
##### participantName
|
|
1569
|
+
|
|
1570
|
+
```ts
|
|
1571
|
+
participantName: string;
|
|
1572
|
+
```
|
|
1573
|
+
|
|
1574
|
+
Voice participant name
|
|
1575
|
+
|
|
1576
|
+
---
|
|
1577
|
+
|
|
1578
|
+
### ChoiceRequestMetadata
|
|
1579
|
+
|
|
1580
|
+
Helps link the choice to the specific message in the conversation.
|
|
1581
|
+
|
|
1582
|
+
#### Properties
|
|
1583
|
+
|
|
1584
|
+
##### responseIndex?
|
|
1585
|
+
|
|
1586
|
+
```ts
|
|
1587
|
+
optional responseIndex: number;
|
|
1588
|
+
```
|
|
1589
|
+
|
|
1590
|
+
The index of the [Response](#response) associated with this choice.
|
|
1591
|
+
Setting this ensures that local state's `selectedChoiceId` on the corresponding [ApplicationResponse](#applicationresponse) is set.
|
|
1592
|
+
It is not sent to the application.
|
|
1593
|
+
|
|
1594
|
+
##### messageIndex?
|
|
1595
|
+
|
|
1596
|
+
```ts
|
|
1597
|
+
optional messageIndex: number;
|
|
1598
|
+
```
|
|
1599
|
+
|
|
1600
|
+
The index of the [ApplicationMessage](#applicationmessage) associated with this choice.
|
|
1601
|
+
Setting this ensures that local state's `selectedChoiceId` on the corresponding [ApplicationResponse](#applicationresponse) is set.
|
|
1602
|
+
It is not sent to the application.
|
|
1603
|
+
|
|
1604
|
+
##### nodeId?
|
|
1605
|
+
|
|
1606
|
+
```ts
|
|
1607
|
+
optional nodeId: string;
|
|
1608
|
+
```
|
|
1609
|
+
|
|
1610
|
+
Required if you want to change a choice that's already been sent.
|
|
1611
|
+
The `nodeId` can be found in the corresponding [ApplicationMessage](#applicationmessage).
|
|
1612
|
+
|
|
1613
|
+
##### intentId?
|
|
1614
|
+
|
|
1615
|
+
```ts
|
|
1616
|
+
optional intentId: string;
|
|
1617
|
+
```
|
|
1618
|
+
|
|
1619
|
+
Intent ID, used for sending to the NLU to allow it to double-check
|
|
1620
|
+
|
|
1621
|
+
---
|
|
1622
|
+
|
|
1623
|
+
### VoicePlusMessage
|
|
1624
|
+
|
|
1625
|
+
Messages sent to the Voice+ socket
|
|
1626
|
+
|
|
1627
|
+
#### Properties
|
|
1628
|
+
|
|
1629
|
+
##### context
|
|
1630
|
+
|
|
1631
|
+
```ts
|
|
1632
|
+
context: any;
|
|
1633
|
+
```
|
|
1634
|
+
|
|
1635
|
+
Voice+ context
|
|
1636
|
+
|
|
1637
|
+
---
|
|
1638
|
+
|
|
1639
|
+
### EventHandlers
|
|
1640
|
+
|
|
1641
|
+
Dictionary of handler methods per event
|
|
1642
|
+
|
|
1643
|
+
#### Properties
|
|
1644
|
+
|
|
1645
|
+
##### voicePlusCommand()
|
|
1646
|
+
|
|
1647
|
+
```ts
|
|
1648
|
+
voicePlusCommand: (payload) => void;
|
|
1649
|
+
```
|
|
1650
|
+
|
|
1651
|
+
Voice+ command event handler
|
|
1652
|
+
|
|
1653
|
+
###### Parameters
|
|
1654
|
+
|
|
1655
|
+
###### payload
|
|
1656
|
+
|
|
1657
|
+
`any`
|
|
1658
|
+
|
|
1659
|
+
###### Returns
|
|
1660
|
+
|
|
1661
|
+
`void`
|
|
1662
|
+
|
|
1663
|
+
## Enumerations
|
|
1664
|
+
|
|
1665
|
+
### ResponseType
|
|
1666
|
+
|
|
1667
|
+
Response type
|
|
1668
|
+
|
|
1669
|
+
#### Enumeration Members
|
|
1670
|
+
|
|
1671
|
+
##### Application
|
|
1672
|
+
|
|
1673
|
+
```ts
|
|
1674
|
+
Application: "bot";
|
|
1675
|
+
```
|
|
1676
|
+
|
|
1677
|
+
Response from the application
|
|
1678
|
+
|
|
1679
|
+
##### User
|
|
1680
|
+
|
|
1681
|
+
```ts
|
|
1682
|
+
User: "user";
|
|
1683
|
+
```
|
|
1684
|
+
|
|
1685
|
+
Response from the user
|
|
1686
|
+
|
|
1687
|
+
##### Failure
|
|
1688
|
+
|
|
1689
|
+
```ts
|
|
1690
|
+
Failure: "failure";
|
|
1691
|
+
```
|
|
1692
|
+
|
|
1693
|
+
Generic failure (cannot be attributed to the application)
|
|
1694
|
+
|
|
1695
|
+
## Events
|
|
1696
|
+
|
|
1697
|
+
### ConversationHandlerEvent
|
|
1698
|
+
|
|
1699
|
+
```ts
|
|
1700
|
+
type ConversationHandlerEvent = "voicePlusCommand";
|
|
1701
|
+
```
|
|
1702
|
+
|
|
1703
|
+
Handler events
|
|
1704
|
+
voicePlusCommand
|
|
1705
|
+
|
|
1706
|
+
## Type Aliases
|
|
1707
|
+
|
|
1708
|
+
### Context
|
|
1709
|
+
|
|
1710
|
+
```ts
|
|
1711
|
+
type Context = Record<string, any>;
|
|
1712
|
+
```
|
|
1713
|
+
|
|
1714
|
+
[Context](https://docs.studio.nlx.ai/workspacesettings/documentation-settings/settings-context-attributes) for usage later in the intent.
|
|
1715
|
+
|
|
1716
|
+
---
|
|
1717
|
+
|
|
1718
|
+
### SlotsRecord
|
|
1719
|
+
|
|
1720
|
+
```ts
|
|
1721
|
+
type SlotsRecord = Record<string, any>;
|
|
1722
|
+
```
|
|
1723
|
+
|
|
1724
|
+
Values to fill an intent's [attached slots](https://docs.studio.nlx.ai/intents/documentation-intents/intents-attached-slots).
|
|
1725
|
+
|
|
1726
|
+
`SlotRecord` Keys are the attached slot's name
|
|
1727
|
+
|
|
1728
|
+
`SlotRecord` Values are usually a discrete value matching the slots's [type](https://docs.studio.nlx.ai/slots/documentation-slots/slots-values#system-slots).
|
|
1729
|
+
for custom slots, this can optionally be the value's ID.
|
|
1730
|
+
|
|
1731
|
+
A `SlotsRecord` is equivalent to an array of [SlotValue](#slotvalue) objects.
|
|
1732
|
+
|
|
1733
|
+
---
|
|
1734
|
+
|
|
1735
|
+
### SlotsRecordOrArray
|
|
1736
|
+
|
|
1737
|
+
```ts
|
|
1738
|
+
type SlotsRecordOrArray = SlotsRecord | SlotValue[];
|
|
1739
|
+
```
|
|
1740
|
+
|
|
1741
|
+
Values to fill an intent's [attached slots](https://docs.studio.nlx.ai/intents/documentation-intents/intents-attached-slots).
|
|
1742
|
+
|
|
1743
|
+
Supports either a [SlotsRecord](#slotsrecord) or an array of [SlotValue](#slotvalue) objects
|
|
1744
|
+
|
|
1745
|
+
---
|
|
1746
|
+
|
|
1747
|
+
### ModalityPayloads
|
|
1748
|
+
|
|
1749
|
+
```ts
|
|
1750
|
+
type ModalityPayloads = Record<string, any>;
|
|
1751
|
+
```
|
|
1752
|
+
|
|
1753
|
+
Payloads for modalities as a key-value pair by modality name
|
|
1754
|
+
|
|
1755
|
+
---
|
|
1756
|
+
|
|
1757
|
+
### UserResponsePayload
|
|
1758
|
+
|
|
1759
|
+
```ts
|
|
1760
|
+
type UserResponsePayload =
|
|
1761
|
+
| {
|
|
1762
|
+
type: "text";
|
|
1763
|
+
text: string;
|
|
1764
|
+
context?: Context;
|
|
1765
|
+
}
|
|
1766
|
+
| {
|
|
1767
|
+
type: "choice";
|
|
1768
|
+
choiceId: string;
|
|
1769
|
+
context?: Context;
|
|
1770
|
+
}
|
|
1771
|
+
| (object & StructuredRequest);
|
|
1772
|
+
```
|
|
1773
|
+
|
|
1774
|
+
The payload of the user response
|
|
1775
|
+
|
|
1776
|
+
#### Type Declaration
|
|
1777
|
+
|
|
1778
|
+
```ts
|
|
1779
|
+
{
|
|
1780
|
+
type: "text";
|
|
1781
|
+
text: string;
|
|
1782
|
+
context?: Context;
|
|
1783
|
+
}
|
|
1784
|
+
```
|
|
1785
|
+
|
|
1786
|
+
##### type
|
|
1787
|
+
|
|
1788
|
+
```ts
|
|
1789
|
+
type: "text";
|
|
1790
|
+
```
|
|
1791
|
+
|
|
1792
|
+
Set when `sendText` is called.
|
|
1793
|
+
|
|
1794
|
+
##### text
|
|
1795
|
+
|
|
1796
|
+
```ts
|
|
1797
|
+
text: string;
|
|
1798
|
+
```
|
|
1799
|
+
|
|
1800
|
+
The user's message
|
|
1801
|
+
|
|
1802
|
+
##### context?
|
|
1803
|
+
|
|
1804
|
+
```ts
|
|
1805
|
+
optional context: Context;
|
|
1806
|
+
```
|
|
1807
|
+
|
|
1808
|
+
[Context](https://docs.studio.nlx.ai/workspacesettings/documentation-settings/settings-context-attributes) for usage later in the intent.
|
|
1809
|
+
|
|
1810
|
+
```ts
|
|
1811
|
+
{
|
|
1812
|
+
type: "choice";
|
|
1813
|
+
choiceId: string;
|
|
1814
|
+
context?: Context;
|
|
1815
|
+
}
|
|
1816
|
+
```
|
|
1817
|
+
|
|
1818
|
+
##### type
|
|
1819
|
+
|
|
1820
|
+
```ts
|
|
1821
|
+
type: "choice";
|
|
1822
|
+
```
|
|
1823
|
+
|
|
1824
|
+
Set when `sendChoice` is called.
|
|
1825
|
+
|
|
1826
|
+
##### choiceId
|
|
1827
|
+
|
|
1828
|
+
```ts
|
|
1829
|
+
choiceId: string;
|
|
1830
|
+
```
|
|
1831
|
+
|
|
1832
|
+
The `choiceId` passed to `sendChoice`
|
|
1833
|
+
Correlates to a `choiceId` in the [ApplicationResponse](#applicationresponse)'s `.payload.messages[].choices[].choiceId` fields
|
|
1834
|
+
|
|
1835
|
+
##### context?
|
|
1836
|
+
|
|
1837
|
+
```ts
|
|
1838
|
+
optional context: Context;
|
|
1839
|
+
```
|
|
1840
|
+
|
|
1841
|
+
[Context](https://docs.studio.nlx.ai/workspacesettings/documentation-settings/settings-context-attributes) for usage later in the intent.
|
|
1842
|
+
|
|
1843
|
+
`object` & [`StructuredRequest`](#structuredrequest)
|
|
1844
|
+
|
|
1845
|
+
---
|
|
1846
|
+
|
|
1847
|
+
### Response
|
|
1848
|
+
|
|
1849
|
+
```ts
|
|
1850
|
+
type Response = ApplicationResponse | UserResponse | FailureMessage;
|
|
1851
|
+
```
|
|
1852
|
+
|
|
1853
|
+
A response from the application or the user.
|
|
1854
|
+
|
|
1855
|
+
---
|
|
1856
|
+
|
|
1857
|
+
### Time
|
|
1858
|
+
|
|
1859
|
+
```ts
|
|
1860
|
+
type Time = number;
|
|
1861
|
+
```
|
|
1862
|
+
|
|
1863
|
+
The time value in milliseconds since midnight, January 1, 1970 UTC.
|
|
1864
|
+
|
|
1865
|
+
---
|
|
1866
|
+
|
|
1867
|
+
### NormalizedStructuredRequest
|
|
1868
|
+
|
|
1869
|
+
```ts
|
|
1870
|
+
type NormalizedStructuredRequest = StructuredRequest & object;
|
|
1871
|
+
```
|
|
1872
|
+
|
|
1873
|
+
Normalized structured request with a single way to represent slots
|
|
1874
|
+
|
|
1875
|
+
#### Type Declaration
|
|
1876
|
+
|
|
1877
|
+
##### slots?
|
|
1878
|
+
|
|
1879
|
+
```ts
|
|
1880
|
+
optional slots: SlotValue[];
|
|
1881
|
+
```
|
|
1882
|
+
|
|
1883
|
+
Only array-form slots are allowed for the purposes of sending to the backend
|
|
1884
|
+
|
|
1885
|
+
---
|
|
1886
|
+
|
|
1887
|
+
### LanguageCode
|
|
1888
|
+
|
|
1889
|
+
```ts
|
|
1890
|
+
type LanguageCode = string;
|
|
1891
|
+
```
|
|
1892
|
+
|
|
1893
|
+
Language code named for clarity, may restrict it to a finite list
|
|
1894
|
+
|
|
1895
|
+
---
|
|
1896
|
+
|
|
1897
|
+
### RequestOverride()
|
|
1898
|
+
|
|
1899
|
+
```ts
|
|
1900
|
+
type RequestOverride = (applicationRequest, appendResponse) => void;
|
|
1901
|
+
```
|
|
1902
|
+
|
|
1903
|
+
Instead of sending a request to the application, handle it in a custom fashion
|
|
1904
|
+
|
|
1905
|
+
#### Parameters
|
|
1906
|
+
|
|
1907
|
+
##### applicationRequest
|
|
1908
|
+
|
|
1909
|
+
[`ApplicationRequest`](#applicationrequest)
|
|
1910
|
+
|
|
1911
|
+
The [ApplicationRequest](#applicationrequest) that is being overridden
|
|
1912
|
+
|
|
1913
|
+
##### appendResponse
|
|
1914
|
+
|
|
1915
|
+
(`res`) => `void`
|
|
1916
|
+
|
|
1917
|
+
A method to append the [ApplicationResponsePayload](#applicationresponsepayload-1) to the message history
|
|
1918
|
+
|
|
1919
|
+
#### Returns
|
|
1920
|
+
|
|
1921
|
+
`void`
|
|
1922
|
+
|
|
1923
|
+
---
|
|
1924
|
+
|
|
1925
|
+
### VoicePlusContext
|
|
1926
|
+
|
|
1927
|
+
```ts
|
|
1928
|
+
type VoicePlusContext = any;
|
|
1929
|
+
```
|
|
1930
|
+
|
|
1931
|
+
Voice+ context, type to be defined
|
|
1932
|
+
|
|
1933
|
+
---
|
|
1934
|
+
|
|
1935
|
+
### Subscriber()
|
|
1936
|
+
|
|
1937
|
+
```ts
|
|
1938
|
+
type Subscriber = (response, newResponse?) => void;
|
|
1939
|
+
```
|
|
1940
|
+
|
|
1941
|
+
The callback function for listening to all responses.
|
|
1942
|
+
|
|
1943
|
+
#### Parameters
|
|
1944
|
+
|
|
1945
|
+
##### response
|
|
1946
|
+
|
|
1947
|
+
[`Response`](#response)[]
|
|
105
1948
|
|
|
106
|
-
|
|
1949
|
+
##### newResponse?
|
|
107
1950
|
|
|
108
|
-
|
|
1951
|
+
[`Response`](#response)
|
|
109
1952
|
|
|
110
|
-
|
|
1953
|
+
#### Returns
|
|
111
1954
|
|
|
112
|
-
|
|
1955
|
+
`void`
|