@nlxai/core 1.2.3-alpha.2 → 1.2.4-alpha.1

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