@onedeskpro/chatbot-core 0.3.1 → 0.5.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/dist/index.d.cts CHANGED
@@ -33,6 +33,14 @@ export declare class ApiClient {
33
33
  uploadAttachment(file: File, visitorToken: string): Promise<UploadAttachmentResponseData>;
34
34
  fetchConfig(): Promise<SdkConfigResponse>;
35
35
  requestHuman(visitorToken: string): Promise<TicketStatusData>;
36
+ /** Withdraws a pending human request; answers with the ticket's state afterwards. */
37
+ cancelHumanRequest(visitorToken: string): Promise<TicketStatusData>;
38
+ /**
39
+ * Ends the visitor's conversation so the next message starts a new one. Answers with the
40
+ * ended conversation (`closed`), or `ai` when there was none.
41
+ */
42
+ closeConversation(visitorToken: string): Promise<TicketStatusData>;
43
+ private postTicketAction;
36
44
  fetchTicketStatus(visitorToken: string): Promise<TicketStatusData>;
37
45
  }
38
46
 
@@ -72,6 +80,13 @@ export declare class ChatbotCore {
72
80
  private retryTimer;
73
81
  /** Server id of the last `message:receive` push rendered as an agent bubble. */
74
82
  private lastPushId;
83
+ /**
84
+ * The conversation `startNewConversation` just ended. Its `closed` status — the
85
+ * socket push the close triggers, or a restore on reconnect — would put the
86
+ * fresh chat back into closed mode, so it is ignored until the next message
87
+ * starts a new ticket on that conversation.
88
+ */
89
+ private endedConversationId;
75
90
  /**
76
91
  * Bumped by every init() and by destroy(). An async init compares the token it
77
92
  * started with against this before touching anything, so a superseded run — a
@@ -90,6 +105,8 @@ export declare class ChatbotCore {
90
105
  /** Derive ticket existence from status restore / socket pushes. */
91
106
  private syncHasActiveTicket;
92
107
  private syncWidgetMode;
108
+ /** True for the stale `closed` status of the conversation the visitor just ended. */
109
+ private isEndedConversation;
93
110
  init(options: ChatbotInitOptions): Promise<void>;
94
111
  /**
95
112
  * Asks `/sdk/config` whether the server is up and the agent can reply, and
@@ -130,6 +147,21 @@ export declare class ChatbotCore {
130
147
  * Escalate the open AI ticket to Unassigned. No-op unless the widget is in `ai` mode.
131
148
  */
132
149
  requestHuman(): Promise<void>;
150
+ /**
151
+ * Withdraws a pending human-agent request so the AI answers again. No-op unless the
152
+ * widget is in `waiting` mode. When an agent accepted the ticket in the meantime, the
153
+ * mode moves to `human` instead. Emits `human-request-cancelled` once the AI is back.
154
+ */
155
+ cancelHumanRequest(): Promise<void>;
156
+ /**
157
+ * Ends the current conversation and starts a fresh one: the API closes the open ticket
158
+ * and gives the AI a new memory, then the chat is cleared and returns to `ai` mode.
159
+ * Emits `session-reset`. No-op until the visitor has identified, or while a request is
160
+ * in flight. Unlike `resetSession`, it works in every mode.
161
+ */
162
+ startNewConversation(): Promise<void>;
163
+ /** Records a failed header/banner action: `state.error`, a visible notice, and `error`. */
164
+ private rejectAction;
133
165
  /** The visitor token every send needs; throws when the visitor has not identified. */
134
166
  private requireVisitorToken;
135
167
  /** Adds the visitor's own message optimistically and marks a send in flight. */
package/dist/index.d.ts CHANGED
@@ -33,6 +33,14 @@ export declare class ApiClient {
33
33
  uploadAttachment(file: File, visitorToken: string): Promise<UploadAttachmentResponseData>;
34
34
  fetchConfig(): Promise<SdkConfigResponse>;
35
35
  requestHuman(visitorToken: string): Promise<TicketStatusData>;
36
+ /** Withdraws a pending human request; answers with the ticket's state afterwards. */
37
+ cancelHumanRequest(visitorToken: string): Promise<TicketStatusData>;
38
+ /**
39
+ * Ends the visitor's conversation so the next message starts a new one. Answers with the
40
+ * ended conversation (`closed`), or `ai` when there was none.
41
+ */
42
+ closeConversation(visitorToken: string): Promise<TicketStatusData>;
43
+ private postTicketAction;
36
44
  fetchTicketStatus(visitorToken: string): Promise<TicketStatusData>;
37
45
  }
38
46
 
@@ -72,6 +80,13 @@ export declare class ChatbotCore {
72
80
  private retryTimer;
73
81
  /** Server id of the last `message:receive` push rendered as an agent bubble. */
74
82
  private lastPushId;
83
+ /**
84
+ * The conversation `startNewConversation` just ended. Its `closed` status — the
85
+ * socket push the close triggers, or a restore on reconnect — would put the
86
+ * fresh chat back into closed mode, so it is ignored until the next message
87
+ * starts a new ticket on that conversation.
88
+ */
89
+ private endedConversationId;
75
90
  /**
76
91
  * Bumped by every init() and by destroy(). An async init compares the token it
77
92
  * started with against this before touching anything, so a superseded run — a
@@ -90,6 +105,8 @@ export declare class ChatbotCore {
90
105
  /** Derive ticket existence from status restore / socket pushes. */
91
106
  private syncHasActiveTicket;
92
107
  private syncWidgetMode;
108
+ /** True for the stale `closed` status of the conversation the visitor just ended. */
109
+ private isEndedConversation;
93
110
  init(options: ChatbotInitOptions): Promise<void>;
94
111
  /**
95
112
  * Asks `/sdk/config` whether the server is up and the agent can reply, and
@@ -130,6 +147,21 @@ export declare class ChatbotCore {
130
147
  * Escalate the open AI ticket to Unassigned. No-op unless the widget is in `ai` mode.
131
148
  */
132
149
  requestHuman(): Promise<void>;
150
+ /**
151
+ * Withdraws a pending human-agent request so the AI answers again. No-op unless the
152
+ * widget is in `waiting` mode. When an agent accepted the ticket in the meantime, the
153
+ * mode moves to `human` instead. Emits `human-request-cancelled` once the AI is back.
154
+ */
155
+ cancelHumanRequest(): Promise<void>;
156
+ /**
157
+ * Ends the current conversation and starts a fresh one: the API closes the open ticket
158
+ * and gives the AI a new memory, then the chat is cleared and returns to `ai` mode.
159
+ * Emits `session-reset`. No-op until the visitor has identified, or while a request is
160
+ * in flight. Unlike `resetSession`, it works in every mode.
161
+ */
162
+ startNewConversation(): Promise<void>;
163
+ /** Records a failed header/banner action: `state.error`, a visible notice, and `error`. */
164
+ private rejectAction;
133
165
  /** The visitor token every send needs; throws when the visitor has not identified. */
134
166
  private requireVisitorToken;
135
167
  /** Adds the visitor's own message optimistically and marks a send in flight. */