@developer.notchatbot/webchat 1.5.3 → 1.6.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/types.d.ts CHANGED
@@ -142,6 +142,15 @@ export interface ChatWindowProps {
142
142
  isRated?: boolean;
143
143
  onRatingChange?: (isRated: boolean) => void;
144
144
  conversationId?: string;
145
+ /** Configurable auto-survey threshold from the backend; undefined = legacy default (2). */
146
+ surveyAfterUserMessages?: number;
147
+ /** Timestamp of the last manual survey request from Livechat; undefined = never requested. */
148
+ webchatSurveyRequestedAt?: number;
149
+ }
150
+ /** Survey-related conversation state forwarded from the Convex realtime subscription. */
151
+ export interface ConversationSurveyState {
152
+ surveyAfterUserMessages?: number;
153
+ webchatSurveyRequestedAt?: number;
145
154
  }
146
155
  export interface ChatHeaderProps {
147
156
  title: string;
@@ -1,5 +1,5 @@
1
1
  import { ConvexReactClient } from 'convex/react';
2
- import { Message } from '../types';
2
+ import { ConversationSurveyState, Message } from '../types';
3
3
  export interface ConvexConnectionData {
4
4
  client: ConvexReactClient;
5
5
  unsubscribe: (() => void) | null;
@@ -11,9 +11,10 @@ export interface ConvexConnectionData {
11
11
  * @param conversationId Conversation ID
12
12
  * @param onMessage Callback for new messages
13
13
  * @param onChatbotToggle Callback for chatbot activation changes
14
+ * @param onSurveyStateChange Callback for survey state changes (threshold + manual trigger)
14
15
  * @returns Promise that resolves to Convex connection data
15
16
  */
16
- export declare const initializeConvexConnection: (realtimeEndpoint: string, _chatbotUid: string, conversationId: string, onMessage: (message: Message) => void, onChatbotToggle?: (chatbotActivated: boolean) => void) => Promise<ConvexConnectionData>;
17
+ export declare const initializeConvexConnection: (realtimeEndpoint: string, _chatbotUid: string, conversationId: string, onMessage: (message: Message) => void, onChatbotToggle?: (chatbotActivated: boolean) => void, onSurveyStateChange?: (surveyState: ConversationSurveyState) => void) => Promise<ConvexConnectionData>;
17
18
  /**
18
19
  * Fetches initial conversation data with messages from Convex
19
20
  * @param realtimeEndpoint Realtime service deployment URL
@@ -0,0 +1,30 @@
1
+ import { Message } from '../types';
2
+ /** Legacy hardcoded threshold, used when the backend does not send one. */
3
+ export declare const DEFAULT_SURVEY_AFTER_USER_MESSAGES = 2;
4
+ /**
5
+ * Resolves the configured auto-survey threshold.
6
+ * Falls back to the default when the backend does not expose the field yet
7
+ * or sends something unusable (non-number, NaN, zero/negative).
8
+ */
9
+ export declare const resolveSurveyThreshold: (value: unknown) => number;
10
+ /** Counts only messages sent by the end user (bot/employee ones don't count). */
11
+ export declare const countUserMessages: (messages: Message[]) => number;
12
+ /**
13
+ * Whether the survey should auto-open because the user reached the
14
+ * configured message threshold. Never true for already rated conversations.
15
+ */
16
+ export declare const shouldAutoShowSurvey: (messages: Message[], surveyAfterUserMessages: number | undefined, isRated: boolean) => boolean;
17
+ /**
18
+ * Whether a manual survey request (`webchatSurveyRequestedAt`, a timestamp
19
+ * written by an agent from Livechat) is a new, still unhandled trigger.
20
+ * Comparing against the last handled value — not just presence — keeps
21
+ * re-renders and Convex reconnections from re-opening the survey for the
22
+ * same request, while a fresh timestamp triggers it again.
23
+ *
24
+ * Deliberately NOT gated on `isRated`: a manual request fired after a rating
25
+ * re-opens the survey so the agent can re-validate the experience (the new
26
+ * rating overwrites the previous one server-side). Stale requests can't leak
27
+ * across reloads because the backend clears `webchatSurveyRequestedAt` when a
28
+ * rating is submitted — a present timestamp is always a pending ask.
29
+ */
30
+ export declare const isNewSurveyRequest: (requestedAt: number | undefined, lastHandledRequestedAt: number | undefined) => boolean;