@aiqa/sdk 3.0.0 → 3.1.0

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
@@ -29,6 +29,8 @@ A TypeScript/JavaScript SDK for interacting with the AIQA WebSocket service. Thi
29
29
  - [UpdateConversationInput](#updateconversationinput)
30
30
  - [UpdateConversationResult](#updateconversationresult)
31
31
  - [ConversationWarning](#conversationwarning)
32
+ - [UpsertAdvisorInput](#upsertadvisorinput)
33
+ - [UpsertAdvisorResult](#upsertadvisorresult)
32
34
  - [Examples](#examples)
33
35
  - [Error Handling](#error-handling)
34
36
  - [Version Requirements](#version-requirements)
@@ -281,6 +283,42 @@ for (const warning of result.warnings ?? []) {
281
283
  User-provided application status: `draft`, `pending`, `completed`, `expired`,
282
284
  `closed`.
283
285
 
286
+ #### `upsertAdvisor()`
287
+
288
+ Creates an advisor in your organization, or updates the name of an existing
289
+ advisor with the same email. Then link the call to the advisor with
290
+ `updateConversation({ advisorEmail })`, passing the same email, or with
291
+ `updateConversation({ advisorId })`, passing the returned `advisor_id`.
292
+
293
+ **Parameters:**
294
+
295
+ - `input: UpsertAdvisorInput` - `advisorEmail`, `firstName` and `lastName`, all required
296
+
297
+ **Returns:**
298
+
299
+ - `Promise<UpsertAdvisorResult>`
300
+
301
+ | your organization has | result |
302
+ | ---------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
303
+ | no user with that email | the advisor is created; `created: true` |
304
+ | an advisor with that email | its first and last name are updated; `created: false` |
305
+ | a user with that email who is not an advisor, such as an administrator | the user is not changed and keeps its own first and last name, which can differ from what you sent; `created: false`. You can still link the call to it with `advisorEmail` or `advisorId` |
306
+
307
+ - `advisor_id` is the email in lowercase.
308
+ - The Promise rejects when the advisor cannot be saved: invalid input (for
309
+ example, a malformed email), or, rarely, a different user in your
310
+ organization who already signs in with that email.
311
+
312
+ ```typescript
313
+ const result = await sdk.upsertAdvisor({
314
+ advisorEmail: "advisor@example.com",
315
+ firstName: "Jane",
316
+ lastName: "Doe",
317
+ });
318
+ await sdk.updateConversation({ advisorEmail: "advisor@example.com" });
319
+ // or: await sdk.updateConversation({ advisorId: result.advisor.advisor_id });
320
+ ```
321
+
284
322
  ### Fact Management
285
323
 
286
324
  #### `addFact(fact)`
@@ -883,15 +921,43 @@ type ConversationWarningCode =
883
921
  | (string & {});
884
922
  ```
885
923
 
886
- | `code` | meaning | conversation's advisor | what to do |
887
- | ---------------------------- | ----------------------------------------------------------------- | ---------------------- | -------------------------------------------------- |
888
- | `advisor_not_found` | no AIQA user in your organization has the `advisorEmail` | unchanged | check the email |
889
- | `advisor_lookup_unavailable` | the `advisorEmail` could not be checked at the moment (temporary) | unchanged | retry `updateConversation({ advisorEmail })` later |
890
- | any other | added in a later version | — | log `message` and continue |
924
+ | `code` | meaning | conversation's advisor | what to do |
925
+ | ---------------------------- | ----------------------------------------------------------------- | ---------------------- | ------------------------------------------------------------------------------- |
926
+ | `advisor_not_found` | no AIQA user in your organization has the `advisorEmail` | unchanged | check the email, or create the advisor with [`upsertAdvisor()`](#upsertadvisor) |
927
+ | `advisor_lookup_unavailable` | the `advisorEmail` could not be checked at the moment (temporary) | unchanged | retry `updateConversation({ advisorEmail })` later |
928
+ | any other | added in a later version | — | log `message` and continue |
891
929
 
892
930
  - Use `code` to choose what to do; do not parse `message`. `message` is human-readable, includes the email you sent, and may change.
893
931
  - `success` is `true` and every other field you sent is saved.
894
932
 
933
+ ### UpsertAdvisorInput
934
+
935
+ Accepted by `upsertAdvisor()`.
936
+
937
+ ```typescript
938
+ type UpsertAdvisorInput = {
939
+ advisorEmail: string;
940
+ firstName: string;
941
+ lastName: string;
942
+ };
943
+ ```
944
+
945
+ ### UpsertAdvisorResult
946
+
947
+ Returned by `upsertAdvisor()`.
948
+
949
+ ```typescript
950
+ type UpsertAdvisorResult = {
951
+ success: boolean; // always true when the Promise resolves
952
+ advisor: {
953
+ advisor_id: string; // pass it to updateConversation({ advisorId })
954
+ first_name: string | null; // null only for an existing non-advisor user with no name stored
955
+ last_name: string | null; // same as first_name
956
+ created: boolean; // true when created; false when a user in your organization already had this email
957
+ };
958
+ };
959
+ ```
960
+
895
961
  ## Examples
896
962
 
897
963
  ### Complete Example: Recording Session
@@ -82,7 +82,8 @@ declare enum Methods {
82
82
  FLAG_FACT = "FLAG_FACT",
83
83
  SET_CONVERSATION_PRODUCT = "SET_CONVERSATION_PRODUCT",
84
84
  SET_CONVERSATION_LANGUAGE = "SET_CONVERSATION_LANGUAGE",
85
- UPDATE_CONVERSATION = "UPDATE_CONVERSATION"
85
+ UPDATE_CONVERSATION = "UPDATE_CONVERSATION",
86
+ UPSERT_ADVISOR = "UPSERT_ADVISOR"
86
87
  }
87
88
  type SetConversationProductResult = {
88
89
  success: boolean;
@@ -137,6 +138,28 @@ type UpdateConversationResult = {
137
138
  };
138
139
  warnings?: ConversationWarning[];
139
140
  };
141
+ /** The advisor to create or update with `upsertAdvisor()`. */
142
+ type UpsertAdvisorInput = {
143
+ /** Email of the advisor. Identifies the advisor in your organization. */
144
+ advisorEmail: string;
145
+ firstName: string;
146
+ lastName: string;
147
+ };
148
+ /** Returned by `upsertAdvisor()`. */
149
+ type UpsertAdvisorResult = {
150
+ /** Always `true` when the Promise resolves. */
151
+ success: boolean;
152
+ advisor: {
153
+ /** Pass it to `updateConversation({ advisorId })`. The email in lowercase. */
154
+ advisor_id: string;
155
+ /** The first name stored for this user. `null` only when the email belongs to an existing user who is not an advisor and has no name stored. */
156
+ first_name: string | null;
157
+ /** The last name stored for this user. `null` in the same case as `first_name`. */
158
+ last_name: string | null;
159
+ /** `true` when the advisor was created. `false` when a user in your organization already had this email: an advisor is updated, any other user is left unchanged. */
160
+ created: boolean;
161
+ };
162
+ };
140
163
  declare enum ConversationLanguage {
141
164
  EN = "en",
142
165
  ES = "es",
@@ -351,6 +374,12 @@ declare abstract class IAiqaSdk {
351
374
  abstract setConversationProduct(product: string): Promise<SetConversationProductResult>;
352
375
  abstract setConversationLanguage(language: ConversationLanguage): Promise<SetConversationLanguageResult>;
353
376
  abstract updateConversation(input: UpdateConversationInput): Promise<UpdateConversationResult>;
377
+ /**
378
+ * Creates an advisor in your organization, or updates the name of an existing
379
+ * advisor with the same email. A user with that email who is not an advisor is
380
+ * left unchanged. Rejects on invalid input.
381
+ */
382
+ abstract upsertAdvisor(input: UpsertAdvisorInput): Promise<UpsertAdvisorResult>;
354
383
  }
355
384
 
356
385
  declare class AiQaSdk implements IAiqaSdk {
@@ -375,6 +404,7 @@ declare class AiQaSdk implements IAiqaSdk {
375
404
  setConversationProduct(product: string): Promise<SetConversationProductResult>;
376
405
  setConversationLanguage(language: ConversationLanguage): Promise<SetConversationLanguageResult>;
377
406
  updateConversation(input: UpdateConversationInput): Promise<UpdateConversationResult>;
407
+ upsertAdvisor(input: UpsertAdvisorInput): Promise<UpsertAdvisorResult>;
378
408
  authenticate(): Promise<void>;
379
409
  startRecording(): Promise<boolean>;
380
410
  stopRecording(): Promise<boolean>;
@@ -384,4 +414,4 @@ declare class AiQaSdk implements IAiqaSdk {
384
414
  private isManagerEvent;
385
415
  }
386
416
 
387
- export { type AddFactResult, AiQaSdk, type Application, type ApplicationFact, type ApplicationFactAnswerChoice, type ApplicationFactAnswerFormat, type ApplicationFactInput, type ApplicationVerificationStatus, type ApplicationVerificationSummary, ConversationLanguage, type ConversationWarning, type ConversationWarningCode, type DialogAct, type DialogActConfidence, ExternalStatus, FactAnswerFormatType, type FactVerifiedPayload, type FactWarning, type FactWarningCode, type FlagFactResult, IAiqaSdk, Methods, type QuestionStatus, type SdkError, type SdkEvent, type SetConversationLanguageResult, type SetConversationProductResult, type TranscriptionUpdate, type UpdateConversationInput, type UpdateConversationResult, type Utterance, type VerificationStatus };
417
+ export { type AddFactResult, AiQaSdk, type Application, type ApplicationFact, type ApplicationFactAnswerChoice, type ApplicationFactAnswerFormat, type ApplicationFactInput, type ApplicationVerificationStatus, type ApplicationVerificationSummary, ConversationLanguage, type ConversationWarning, type ConversationWarningCode, type DialogAct, type DialogActConfidence, ExternalStatus, FactAnswerFormatType, type FactVerifiedPayload, type FactWarning, type FactWarningCode, type FlagFactResult, IAiqaSdk, Methods, type QuestionStatus, type SdkError, type SdkEvent, type SetConversationLanguageResult, type SetConversationProductResult, type TranscriptionUpdate, type UpdateConversationInput, type UpdateConversationResult, type UpsertAdvisorInput, type UpsertAdvisorResult, type Utterance, type VerificationStatus };
@@ -3350,6 +3350,7 @@ var Methods = /* @__PURE__ */ ((Methods2) => {
3350
3350
  Methods2["SET_CONVERSATION_PRODUCT"] = "SET_CONVERSATION_PRODUCT";
3351
3351
  Methods2["SET_CONVERSATION_LANGUAGE"] = "SET_CONVERSATION_LANGUAGE";
3352
3352
  Methods2["UPDATE_CONVERSATION"] = "UPDATE_CONVERSATION";
3353
+ Methods2["UPSERT_ADVISOR"] = "UPSERT_ADVISOR";
3353
3354
  return Methods2;
3354
3355
  })(Methods || {});
3355
3356
  var ExternalStatus = /* @__PURE__ */ ((ExternalStatus2) => {
@@ -3406,7 +3407,7 @@ var compareVersions = (left, right) => {
3406
3407
  // package.json
3407
3408
  var package_default = {
3408
3409
  name: "@aiqa/sdk",
3409
- version: "3.0.0-develop.1",
3410
+ version: "3.0.0-develop.2",
3410
3411
  main: "dist/node/node.js",
3411
3412
  module: "dist/node/node.js",
3412
3413
  types: "dist/node/node.d.ts",
@@ -3783,6 +3784,15 @@ var AiQaSdk = class {
3783
3784
  const { agent_id, ...conversation } = data.conversation;
3784
3785
  return { ...data, conversation: { ...conversation, advisor_id: agent_id } };
3785
3786
  }
3787
+ async upsertAdvisor(input) {
3788
+ const { advisorEmail, firstName, lastName } = input;
3789
+ const result = await this.sendMessage("UPSERT_ADVISOR" /* UPSERT_ADVISOR */, {
3790
+ email: advisorEmail,
3791
+ firstName,
3792
+ lastName
3793
+ });
3794
+ return result && result.data !== void 0 ? result.data : result;
3795
+ }
3786
3796
  async authenticate() {
3787
3797
  try {
3788
3798
  const result = await this.sendMessage("AUTHENTICATE" /* AUTHENTICATE */, {