@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/lib/index.d.ts CHANGED
@@ -7,19 +7,37 @@ export declare const version: string;
7
7
  */
8
8
  export interface Config {
9
9
  /**
10
- * The URL at which your conversational application is running.
11
- * Fetch this from the application's API channel tab.
10
+ * The URL at which your conversational application is running. Fetch this from the application's API channel tab.
11
+ * Currently, there are a few ways to specify the application URL:
12
+ * - (recommended) leave out `applicationUrl` and specify `protocol`, `host`, `deploymentKey` and `channelKey`.
13
+ * - specify the full `applicationUrl` as well as the `protocol`.
14
+ * - (legacy) specify the `applicationUrl` generated either as an HTTP or websocket URL. Use `experimental.streamHttp` to control streaming.
12
15
  */
13
16
  applicationUrl?: string;
17
+ /**
18
+ * Specify the protocol (http, websocket or httpWithStreaming)
19
+ */
20
+ protocol?: Protocol;
21
+ /**
22
+ * Hostname of the application deployment, without a leading `https://`.
23
+ */
24
+ host?: string;
25
+ /**
26
+ * Deployment key.
27
+ */
28
+ deploymentKey?: string;
29
+ /**
30
+ * Channel key.
31
+ */
32
+ channelKey?: string;
33
+ /**
34
+ * API key.
35
+ */
36
+ apiKey?: string;
14
37
  /**
15
38
  * Headers to forward to the NLX API.
16
39
  */
17
- headers: Record<string, string> & {
18
- /**
19
- * The `nlx-api-key` is required. Fetch this from the application's API channel tab.
20
- */
21
- "nlx-api-key": string;
22
- };
40
+ headers?: Record<string, string>;
23
41
  /**
24
42
  * Set `conversationId` to continue an existing conversation. If not set, a new conversation will be started (and a new conversationId will be generated internally).
25
43
  */
@@ -55,6 +73,11 @@ export interface Config {
55
73
  * @internal
56
74
  */
57
75
  experimental?: {
76
+ /**
77
+ * Check whether HTTP streaming should be enabled. Defaults to `true`.
78
+ * @deprecated use the protocol setting instead.
79
+ */
80
+ streamHttp?: boolean;
58
81
  /**
59
82
  * Simulate alternative channel types
60
83
  */
@@ -145,6 +168,15 @@ export interface ConversationHandler {
145
168
  * @param context - [Context](https://docs.studio.nlx.ai/workspacesettings/documentation-settings/settings-context-attributes) for usage later in the intent.
146
169
  */
147
170
  sendStructured: (request: StructuredRequest, context?: Context) => void;
171
+ /**
172
+ * Submit feedback about a response.
173
+ * @param url - The URL comming from the Application response `metadata.feedbackURL` field.
174
+ * @param feedback - Either a numerical rating or a textual comment.
175
+ */
176
+ submitFeedback: (url: string, feedback: {
177
+ rating?: number;
178
+ comment?: string;
179
+ }) => Promise<void>;
148
180
  /**
149
181
  * Subscribe a callback to the conversation. On subscribe, the subscriber will receive all of the Responses that the conversation has already received.
150
182
  * @param subscriber - The callback to subscribe
@@ -224,6 +256,23 @@ export interface SlotValue {
224
256
  */
225
257
  value: any;
226
258
  }
259
+ /**
260
+ * The protocol used to communicate with the application
261
+ */
262
+ export declare enum Protocol {
263
+ /**
264
+ * Regular encrypted HTTPS, without support for post-escalation message handling, interim messages and other streaming features.
265
+ */
266
+ Https = "https",
267
+ /**
268
+ * Encrypted HTTPS with streaming enabled. This is the default setting and supports interim messages. Does not support post-escalation message handling.
269
+ */
270
+ HttpsWithStreaming = "httpsWithStreaming",
271
+ /**
272
+ * Websocket, with support for post-escalation message handling.
273
+ */
274
+ Websocket = "websocket"
275
+ }
227
276
  /**
228
277
  * Response type
229
278
  */
@@ -351,6 +400,16 @@ export interface ApplicationResponseMetadata {
351
400
  * Knowledge base sources
352
401
  */
353
402
  sources?: KnowledgeBaseResponseSource[];
403
+ /**
404
+ * URL to use for submitting feedback about this response. See `feedbackConfig` for what the expected feedback type is.
405
+ *
406
+ * You can pass this as the first argument to `submitFeedback`.
407
+ */
408
+ feedbackUrl?: string;
409
+ /**
410
+ * If present, the application would like to collect feedback from the user.
411
+ */
412
+ feedbackConfig?: FeedbackConfiguration;
354
413
  }
355
414
  /**
356
415
  * Response for knowlege base sources
@@ -541,6 +600,52 @@ export type Response = ApplicationResponse | UserResponse | FailureMessage;
541
600
  * The time value in milliseconds since midnight, January 1, 1970 UTC.
542
601
  */
543
602
  export type Time = number;
603
+ /**
604
+ * Configuration for feedback collection. You can use this to render an appropriate feedback widget in your application.
605
+ */
606
+ export interface FeedbackConfiguration {
607
+ /** Unique identifier for the feedback collection. */
608
+ feedbackId: string;
609
+ /** Human readable name of this feedback collection. */
610
+ feedbackName: string;
611
+ /**
612
+ * Type of feedback being collected.
613
+ * At the moment only binary feedback is supported, but we plan to introduce more types in the future.
614
+ * Hence your code should make sure to check the `type` attribute to make sure the expected feedback type is handled.
615
+ */
616
+ feedbackType: FeedbackType;
617
+ /** Whether comments are enabled for this feedback collection. */
618
+ commentsEnabled: boolean;
619
+ /** Optional question to show to the user when collecting feedback. */
620
+ question?: string;
621
+ /** Labels for individual feedback UI elements as customised by the builder. */
622
+ labels: {
623
+ /** Label for positive feedback */
624
+ positive?: string;
625
+ /** Label for negative feedback */
626
+ negative?: string;
627
+ /** Label for comment */
628
+ comment?: string;
629
+ };
630
+ }
631
+ /**
632
+ * @inline @hidden
633
+ */
634
+ export type FeedbackType = {
635
+ /** A binary feedback type is a thumbs up/down sort of choice. */
636
+ type: "binary";
637
+ /** Configuration specific to binary feedback. */
638
+ config: BinaryFeedbackConfig;
639
+ };
640
+ /**
641
+ * @inline @hidden
642
+ */
643
+ export interface BinaryFeedbackConfig {
644
+ /** Value to send for positive feedback. Default `1`. */
645
+ positiveValue: number;
646
+ /** Value to send for negative feedback. Default `-1`. */
647
+ negativeValue: number;
648
+ }
544
649
  /**
545
650
  * @hidden
546
651
  */
@@ -709,7 +814,15 @@ export interface VoicePlusMessage {
709
814
  * Handler events
710
815
  * @event voicePlusCommand
711
816
  */
712
- export type ConversationHandlerEvent = "voicePlusCommand";
817
+ export type ConversationHandlerEvent = "voicePlusCommand" | "interimMessage";
818
+ /**
819
+ * Voice+ command listener
820
+ */
821
+ export type VoicePlusCommandListener = (payload: any) => void;
822
+ /**
823
+ * Interim message listener
824
+ */
825
+ export type InterimMessageListener = (message?: string) => void;
713
826
  /**
714
827
  * Dictionary of handler methods per event
715
828
  */
@@ -717,7 +830,11 @@ export interface EventHandlers {
717
830
  /**
718
831
  * Voice+ command event handler
719
832
  */
720
- voicePlusCommand: (payload: any) => void;
833
+ voicePlusCommand: VoicePlusCommandListener;
834
+ /**
835
+ * Interim message event handler
836
+ */
837
+ interimMessage: InterimMessageListener;
721
838
  }
722
839
  /**
723
840
  * The callback function for listening to all responses.
@@ -809,3 +926,71 @@ export declare const getCurrentExpirationTimestamp: (responses: Response[]) => n
809
926
  * @returns A promise-wrapped version of the function. The function, when called, returns a promise that resolves to the Conversation's next response.
810
927
  */
811
928
  export declare function promisify<Params>(fn: (payload: Params) => void, convo: ConversationHandler, timeout?: number): (payload: Params) => Promise<Response | null>;
929
+ /**
930
+ * @inline @hidden
931
+ */
932
+ export interface VoicePlusStepConfig {
933
+ /** * the API key generated for the Voice+ script. Note that this value is different from the API key you would pass to {@link createConversation}. You can control the API key on the Voice+ script settings page. */
934
+ apiKey: string;
935
+ /** The ID of the Voice+ script. */
936
+ scriptId?: string;
937
+ /** Your workspace ID. */
938
+ workspaceId: string;
939
+ /**
940
+ * The active conversation ID, passed from the active NLX voice application. This is what ties the script exectution to the specific Voice application.
941
+ *
942
+ * _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.
943
+ * @example
944
+ * ```typescript
945
+ * const conversationId = new URLSearchParams(window.location.search).get("cid");
946
+ * ```
947
+ */
948
+ conversationId: string;
949
+ /**
950
+ * The user's language code, consistent with the language codes defined on the Voice+ script.
951
+ */
952
+ languageCode: string;
953
+ /** Which step to send. */
954
+ step: StepInfo;
955
+ /** Any context. */
956
+ context: Context;
957
+ /** Set to `true` to help debug issues or errors. Defaults to `false`. */
958
+ debug?: boolean;
959
+ /** Used for library testing @internal @hidden */
960
+ dev?: boolean;
961
+ }
962
+ /**
963
+ * Step information, either a step ID as a single string or an object
964
+ */
965
+ export type StepInfo = string | {
966
+ /**
967
+ * Step ID
968
+ */
969
+ stepId: string;
970
+ /**
971
+ * Step trigger description
972
+ */
973
+ stepTriggerDescription?: string;
974
+ };
975
+ /**
976
+ * Use this function when using **Voice+ scripts** to advance the conversation to the step specified.
977
+ *
978
+ * 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.
979
+ * @example
980
+ * ```typescript
981
+ * import { sendVoicePlusStep } from "@nlxai/core";
982
+ *
983
+ * await sendVoicePlusStep({
984
+ * // hard-coded params
985
+ * apiKey: "REPLACE_WITH_API_KEY",
986
+ * workspaceId: "REPLACE_WITH_WORKSPACE_ID",
987
+ * scriptId: "REPLACE_WITH_SCRIPT_ID",
988
+ * step: "REPLACE_WITH_STEP_ID",
989
+ * // dynamic params
990
+ * conversationId: "REPLACE_WITH_CONVERSATION_ID",
991
+ * languageCode: "en-US",
992
+ * });
993
+ * ```
994
+ * @param configuration - Configuration for sending the step. Many of the values can be found on the deployment modal of the Voice+ script.
995
+ */
996
+ export declare const sendVoicePlusStep: ({ apiKey, workspaceId, conversationId, scriptId, languageCode, step, context, debug, dev, }: VoicePlusStepConfig) => Promise<void>;