@nlxai/core 1.2.3 → 1.2.4-alpha.10
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 +358 -16
- package/docs/README.md +1930 -0
- package/lib/index.cjs +315 -76
- package/lib/index.d.ts +195 -10
- package/lib/index.esm.js +315 -77
- package/lib/index.umd.js +2 -2
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -13,7 +13,10 @@ import { createConversation } from "@nlxai/core";
|
|
|
13
13
|
|
|
14
14
|
// Create some configuration
|
|
15
15
|
const config = {
|
|
16
|
-
|
|
16
|
+
protocol: "httpsWithStreaming", // "httpsWithStreaming", "https" or "websocket"
|
|
17
|
+
host: "", // obtain from NLX deployments page
|
|
18
|
+
deploymentKey: "", // obtain from NLX deployments page
|
|
19
|
+
channelKey: "", // obtain from NLX deployments page
|
|
17
20
|
headers: {
|
|
18
21
|
"nlx-api-key": "", // obtain from NLX deployments page
|
|
19
22
|
},
|
|
@@ -224,7 +227,6 @@ export default async function (req: Request): Promise<Response> {
|
|
|
224
227
|
# API reference
|
|
225
228
|
|
|
226
229
|
<!-- include docs/README.md -->
|
|
227
|
-
|
|
228
230
|
## Functions
|
|
229
231
|
|
|
230
232
|
### createConversation()
|
|
@@ -441,6 +443,101 @@ sendTextWrapped("Hello").then((response) => {
|
|
|
441
443
|
});
|
|
442
444
|
```
|
|
443
445
|
|
|
446
|
+
---
|
|
447
|
+
|
|
448
|
+
### sendVoicePlusStep()
|
|
449
|
+
|
|
450
|
+
```ts
|
|
451
|
+
function sendVoicePlusStep(configuration): Promise<void>;
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
Use this function when using **Voice+ scripts** to advance the conversation to the step specified.
|
|
455
|
+
|
|
456
|
+
This functionality is orthogonal from other usage of the core SDK, as it may be used either using standard SDK communication channels or it can be used to provide a Voice+ script experience with for instance a telephony based channel.
|
|
457
|
+
|
|
458
|
+
#### Parameters
|
|
459
|
+
|
|
460
|
+
##### configuration
|
|
461
|
+
|
|
462
|
+
Configuration for sending the step. Many of the values can be found on the deployment modal of the Voice+ script.
|
|
463
|
+
|
|
464
|
+
###### apiKey
|
|
465
|
+
|
|
466
|
+
`string`
|
|
467
|
+
|
|
468
|
+
- the API key generated for the Voice+ script. Note that this value is different from the API key you would pass to [createConversation](#createconversation). You can control the API key on the Voice+ script settings page.
|
|
469
|
+
|
|
470
|
+
###### scriptId?
|
|
471
|
+
|
|
472
|
+
`string`
|
|
473
|
+
|
|
474
|
+
The ID of the Voice+ script.
|
|
475
|
+
|
|
476
|
+
###### workspaceId
|
|
477
|
+
|
|
478
|
+
`string`
|
|
479
|
+
|
|
480
|
+
Your workspace ID.
|
|
481
|
+
|
|
482
|
+
###### conversationId
|
|
483
|
+
|
|
484
|
+
`string`
|
|
485
|
+
|
|
486
|
+
The active conversation ID, passed from the active NLX voice application. This is what ties the script exectution to the specific Voice application.
|
|
487
|
+
|
|
488
|
+
_Note: This must be dynamically set by the voice application._ Normally, when the voice application directs the user to the webpage running this code, it will include the conversation ID as a URL parameter which you can extract and pass here.
|
|
489
|
+
|
|
490
|
+
**Example**
|
|
491
|
+
|
|
492
|
+
```typescript
|
|
493
|
+
const conversationId = new URLSearchParams(window.location.search).get("cid");
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
###### languageCode
|
|
497
|
+
|
|
498
|
+
`string`
|
|
499
|
+
|
|
500
|
+
The user's language code, consistent with the language codes defined on the Voice+ script.
|
|
501
|
+
|
|
502
|
+
###### step
|
|
503
|
+
|
|
504
|
+
[`StepInfo`](#stepinfo)
|
|
505
|
+
|
|
506
|
+
Which step to send.
|
|
507
|
+
|
|
508
|
+
###### context
|
|
509
|
+
|
|
510
|
+
[`Context`](#context)
|
|
511
|
+
|
|
512
|
+
Any context.
|
|
513
|
+
|
|
514
|
+
###### debug?
|
|
515
|
+
|
|
516
|
+
`boolean` = `false`
|
|
517
|
+
|
|
518
|
+
Set to `true` to help debug issues or errors. Defaults to `false`.
|
|
519
|
+
|
|
520
|
+
#### Returns
|
|
521
|
+
|
|
522
|
+
`Promise`\<`void`\>
|
|
523
|
+
|
|
524
|
+
#### Example
|
|
525
|
+
|
|
526
|
+
```typescript
|
|
527
|
+
import { sendVoicePlusStep } from "@nlxai/core";
|
|
528
|
+
|
|
529
|
+
await sendVoicePlusStep({
|
|
530
|
+
// hard-coded params
|
|
531
|
+
apiKey: "REPLACE_WITH_API_KEY",
|
|
532
|
+
workspaceId: "REPLACE_WITH_WORKSPACE_ID",
|
|
533
|
+
scriptId: "REPLACE_WITH_SCRIPT_ID",
|
|
534
|
+
step: "REPLACE_WITH_STEP_ID",
|
|
535
|
+
// dynamic params
|
|
536
|
+
conversationId: "REPLACE_WITH_CONVERSATION_ID",
|
|
537
|
+
languageCode: "en-US",
|
|
538
|
+
});
|
|
539
|
+
```
|
|
540
|
+
|
|
444
541
|
## Variables
|
|
445
542
|
|
|
446
543
|
### version
|
|
@@ -738,6 +835,38 @@ Send a combination of choice, slots, and intent in one request.
|
|
|
738
835
|
|
|
739
836
|
`void`
|
|
740
837
|
|
|
838
|
+
##### submitFeedback()
|
|
839
|
+
|
|
840
|
+
```ts
|
|
841
|
+
submitFeedback: (url, feedback) => Promise<void>;
|
|
842
|
+
```
|
|
843
|
+
|
|
844
|
+
Submit feedback about a response.
|
|
845
|
+
|
|
846
|
+
###### Parameters
|
|
847
|
+
|
|
848
|
+
###### url
|
|
849
|
+
|
|
850
|
+
`string`
|
|
851
|
+
|
|
852
|
+
The URL comming from the Application response `metadata.feedbackURL` field.
|
|
853
|
+
|
|
854
|
+
###### feedback
|
|
855
|
+
|
|
856
|
+
Either a numerical rating or a textual comment.
|
|
857
|
+
|
|
858
|
+
###### rating?
|
|
859
|
+
|
|
860
|
+
`number`
|
|
861
|
+
|
|
862
|
+
###### comment?
|
|
863
|
+
|
|
864
|
+
`string`
|
|
865
|
+
|
|
866
|
+
###### Returns
|
|
867
|
+
|
|
868
|
+
`Promise`\<`void`\>
|
|
869
|
+
|
|
741
870
|
##### subscribe()
|
|
742
871
|
|
|
743
872
|
```ts
|
|
@@ -905,11 +1034,11 @@ Add a listener to one of the handler's custom events
|
|
|
905
1034
|
|
|
906
1035
|
###### event
|
|
907
1036
|
|
|
908
|
-
`
|
|
1037
|
+
[`ConversationHandlerEvent`](#conversationhandlerevent)
|
|
909
1038
|
|
|
910
1039
|
###### handler
|
|
911
1040
|
|
|
912
|
-
|
|
1041
|
+
[`VoicePlusCommandListener`](#voicepluscommandlistener) | [`InterimMessageListener`](#interimmessagelistener)
|
|
913
1042
|
|
|
914
1043
|
###### Returns
|
|
915
1044
|
|
|
@@ -927,11 +1056,11 @@ Remove a listener to one of the handler's custom events
|
|
|
927
1056
|
|
|
928
1057
|
###### event
|
|
929
1058
|
|
|
930
|
-
`
|
|
1059
|
+
[`ConversationHandlerEvent`](#conversationhandlerevent)
|
|
931
1060
|
|
|
932
1061
|
###### handler
|
|
933
1062
|
|
|
934
|
-
|
|
1063
|
+
[`VoicePlusCommandListener`](#voicepluscommandlistener) | [`InterimMessageListener`](#interimmessagelistener)
|
|
935
1064
|
|
|
936
1065
|
###### Returns
|
|
937
1066
|
|
|
@@ -1132,6 +1261,24 @@ optional sources: KnowledgeBaseResponseSource[];
|
|
|
1132
1261
|
|
|
1133
1262
|
Knowledge base sources
|
|
1134
1263
|
|
|
1264
|
+
##### feedbackUrl?
|
|
1265
|
+
|
|
1266
|
+
```ts
|
|
1267
|
+
optional feedbackUrl: string;
|
|
1268
|
+
```
|
|
1269
|
+
|
|
1270
|
+
URL to use for submitting feedback about this response. See `feedbackConfig` for what the expected feedback type is.
|
|
1271
|
+
|
|
1272
|
+
You can pass this as the first argument to `submitFeedback`.
|
|
1273
|
+
|
|
1274
|
+
##### feedbackConfig?
|
|
1275
|
+
|
|
1276
|
+
```ts
|
|
1277
|
+
optional feedbackConfig: FeedbackConfiguration;
|
|
1278
|
+
```
|
|
1279
|
+
|
|
1280
|
+
If present, the application would like to collect feedback from the user.
|
|
1281
|
+
|
|
1135
1282
|
---
|
|
1136
1283
|
|
|
1137
1284
|
### KnowledgeBaseResponseSource
|
|
@@ -1391,6 +1538,120 @@ When the failure occurred.
|
|
|
1391
1538
|
|
|
1392
1539
|
---
|
|
1393
1540
|
|
|
1541
|
+
### FeedbackConfiguration
|
|
1542
|
+
|
|
1543
|
+
Configuration for feedback collection. You can use this to render an appropriate feedback widget in your application.
|
|
1544
|
+
|
|
1545
|
+
#### Properties
|
|
1546
|
+
|
|
1547
|
+
##### feedbackId
|
|
1548
|
+
|
|
1549
|
+
```ts
|
|
1550
|
+
feedbackId: string;
|
|
1551
|
+
```
|
|
1552
|
+
|
|
1553
|
+
Unique identifier for the feedback collection.
|
|
1554
|
+
|
|
1555
|
+
##### feedbackName
|
|
1556
|
+
|
|
1557
|
+
```ts
|
|
1558
|
+
feedbackName: string;
|
|
1559
|
+
```
|
|
1560
|
+
|
|
1561
|
+
Human readable name of this feedback collection.
|
|
1562
|
+
|
|
1563
|
+
##### feedbackType
|
|
1564
|
+
|
|
1565
|
+
```ts
|
|
1566
|
+
feedbackType: object;
|
|
1567
|
+
```
|
|
1568
|
+
|
|
1569
|
+
Type of feedback being collected.
|
|
1570
|
+
At the moment only binary feedback is supported, but we plan to introduce more types in the future.
|
|
1571
|
+
Hence your code should make sure to check the `type` attribute to make sure the expected feedback type is handled.
|
|
1572
|
+
|
|
1573
|
+
###### type
|
|
1574
|
+
|
|
1575
|
+
```ts
|
|
1576
|
+
type: "binary";
|
|
1577
|
+
```
|
|
1578
|
+
|
|
1579
|
+
A binary feedback type is a thumbs up/down sort of choice.
|
|
1580
|
+
|
|
1581
|
+
###### config
|
|
1582
|
+
|
|
1583
|
+
```ts
|
|
1584
|
+
config: object;
|
|
1585
|
+
```
|
|
1586
|
+
|
|
1587
|
+
Configuration specific to binary feedback.
|
|
1588
|
+
|
|
1589
|
+
###### config.positiveValue
|
|
1590
|
+
|
|
1591
|
+
```ts
|
|
1592
|
+
positiveValue: number;
|
|
1593
|
+
```
|
|
1594
|
+
|
|
1595
|
+
Value to send for positive feedback. Default `1`.
|
|
1596
|
+
|
|
1597
|
+
###### config.negativeValue
|
|
1598
|
+
|
|
1599
|
+
```ts
|
|
1600
|
+
negativeValue: number;
|
|
1601
|
+
```
|
|
1602
|
+
|
|
1603
|
+
Value to send for negative feedback. Default `-1`.
|
|
1604
|
+
|
|
1605
|
+
##### commentsEnabled
|
|
1606
|
+
|
|
1607
|
+
```ts
|
|
1608
|
+
commentsEnabled: boolean;
|
|
1609
|
+
```
|
|
1610
|
+
|
|
1611
|
+
Whether comments are enabled for this feedback collection.
|
|
1612
|
+
|
|
1613
|
+
##### question?
|
|
1614
|
+
|
|
1615
|
+
```ts
|
|
1616
|
+
optional question: string;
|
|
1617
|
+
```
|
|
1618
|
+
|
|
1619
|
+
Optional question to show to the user when collecting feedback.
|
|
1620
|
+
|
|
1621
|
+
##### labels
|
|
1622
|
+
|
|
1623
|
+
```ts
|
|
1624
|
+
labels: object;
|
|
1625
|
+
```
|
|
1626
|
+
|
|
1627
|
+
Labels for individual feedback UI elements as customised by the builder.
|
|
1628
|
+
|
|
1629
|
+
###### positive?
|
|
1630
|
+
|
|
1631
|
+
```ts
|
|
1632
|
+
optional positive: string;
|
|
1633
|
+
```
|
|
1634
|
+
|
|
1635
|
+
Label for positive feedback
|
|
1636
|
+
|
|
1637
|
+
###### negative?
|
|
1638
|
+
|
|
1639
|
+
```ts
|
|
1640
|
+
optional negative: string;
|
|
1641
|
+
```
|
|
1642
|
+
|
|
1643
|
+
Label for negative feedback
|
|
1644
|
+
|
|
1645
|
+
###### comment?
|
|
1646
|
+
|
|
1647
|
+
```ts
|
|
1648
|
+
optional comment: string;
|
|
1649
|
+
```
|
|
1650
|
+
|
|
1651
|
+
Label for comment
|
|
1652
|
+
|
|
1653
|
+
---
|
|
1654
|
+
|
|
1394
1655
|
### StructuredRequest
|
|
1395
1656
|
|
|
1396
1657
|
The body of `sendStructured`
|
|
@@ -1642,23 +1903,21 @@ Dictionary of handler methods per event
|
|
|
1642
1903
|
|
|
1643
1904
|
#### Properties
|
|
1644
1905
|
|
|
1645
|
-
##### voicePlusCommand
|
|
1906
|
+
##### voicePlusCommand
|
|
1646
1907
|
|
|
1647
1908
|
```ts
|
|
1648
|
-
voicePlusCommand:
|
|
1909
|
+
voicePlusCommand: VoicePlusCommandListener;
|
|
1649
1910
|
```
|
|
1650
1911
|
|
|
1651
1912
|
Voice+ command event handler
|
|
1652
1913
|
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
###### payload
|
|
1914
|
+
##### interimMessage
|
|
1656
1915
|
|
|
1657
|
-
|
|
1916
|
+
```ts
|
|
1917
|
+
interimMessage: InterimMessageListener;
|
|
1918
|
+
```
|
|
1658
1919
|
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
`void`
|
|
1920
|
+
Interim message event handler
|
|
1662
1921
|
|
|
1663
1922
|
## Enumerations
|
|
1664
1923
|
|
|
@@ -1697,7 +1956,7 @@ Generic failure (cannot be attributed to the application)
|
|
|
1697
1956
|
### ConversationHandlerEvent
|
|
1698
1957
|
|
|
1699
1958
|
```ts
|
|
1700
|
-
type ConversationHandlerEvent = "voicePlusCommand";
|
|
1959
|
+
type ConversationHandlerEvent = "voicePlusCommand" | "interimMessage";
|
|
1701
1960
|
```
|
|
1702
1961
|
|
|
1703
1962
|
Handler events
|
|
@@ -1932,6 +2191,46 @@ Voice+ context, type to be defined
|
|
|
1932
2191
|
|
|
1933
2192
|
---
|
|
1934
2193
|
|
|
2194
|
+
### VoicePlusCommandListener()
|
|
2195
|
+
|
|
2196
|
+
```ts
|
|
2197
|
+
type VoicePlusCommandListener = (payload) => void;
|
|
2198
|
+
```
|
|
2199
|
+
|
|
2200
|
+
Voice+ command listener
|
|
2201
|
+
|
|
2202
|
+
#### Parameters
|
|
2203
|
+
|
|
2204
|
+
##### payload
|
|
2205
|
+
|
|
2206
|
+
`any`
|
|
2207
|
+
|
|
2208
|
+
#### Returns
|
|
2209
|
+
|
|
2210
|
+
`void`
|
|
2211
|
+
|
|
2212
|
+
---
|
|
2213
|
+
|
|
2214
|
+
### InterimMessageListener()
|
|
2215
|
+
|
|
2216
|
+
```ts
|
|
2217
|
+
type InterimMessageListener = (message?) => void;
|
|
2218
|
+
```
|
|
2219
|
+
|
|
2220
|
+
Interim message listener
|
|
2221
|
+
|
|
2222
|
+
#### Parameters
|
|
2223
|
+
|
|
2224
|
+
##### message?
|
|
2225
|
+
|
|
2226
|
+
`string`
|
|
2227
|
+
|
|
2228
|
+
#### Returns
|
|
2229
|
+
|
|
2230
|
+
`void`
|
|
2231
|
+
|
|
2232
|
+
---
|
|
2233
|
+
|
|
1935
2234
|
### Subscriber()
|
|
1936
2235
|
|
|
1937
2236
|
```ts
|
|
@@ -1953,3 +2252,46 @@ The callback function for listening to all responses.
|
|
|
1953
2252
|
#### Returns
|
|
1954
2253
|
|
|
1955
2254
|
`void`
|
|
2255
|
+
|
|
2256
|
+
---
|
|
2257
|
+
|
|
2258
|
+
### StepInfo
|
|
2259
|
+
|
|
2260
|
+
```ts
|
|
2261
|
+
type StepInfo =
|
|
2262
|
+
| string
|
|
2263
|
+
| {
|
|
2264
|
+
stepId: string;
|
|
2265
|
+
stepTriggerDescription?: string;
|
|
2266
|
+
};
|
|
2267
|
+
```
|
|
2268
|
+
|
|
2269
|
+
Step information, either a step ID as a single string or an object
|
|
2270
|
+
|
|
2271
|
+
#### Type Declaration
|
|
2272
|
+
|
|
2273
|
+
`string`
|
|
2274
|
+
|
|
2275
|
+
```ts
|
|
2276
|
+
{
|
|
2277
|
+
stepId: string;
|
|
2278
|
+
stepTriggerDescription?: string;
|
|
2279
|
+
}
|
|
2280
|
+
```
|
|
2281
|
+
|
|
2282
|
+
##### stepId
|
|
2283
|
+
|
|
2284
|
+
```ts
|
|
2285
|
+
stepId: string;
|
|
2286
|
+
```
|
|
2287
|
+
|
|
2288
|
+
Step ID
|
|
2289
|
+
|
|
2290
|
+
##### stepTriggerDescription?
|
|
2291
|
+
|
|
2292
|
+
```ts
|
|
2293
|
+
optional stepTriggerDescription: string;
|
|
2294
|
+
```
|
|
2295
|
+
|
|
2296
|
+
Step trigger description
|
|
2297
|
+
|