Skip to content

Commit

Permalink
feat: add voiceflow:interact event to differentiate from voiceflow:sa…
Browse files Browse the repository at this point in the history
…ve_session (DX-1078) (#109)
  • Loading branch information
effervescentia committed Feb 21, 2024
1 parent ff084b4 commit d44c713
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const useRuntimeState = ({ assistant, config }: Settings) => {
...context,
});

broadcast({ type: BroadcastType.INTERACT, payload: { session: sessionRef.current, action } });
saveSession(assistant.persistence, config.verify.projectID, sessionRef.current);
};

Expand Down
14 changes: 13 additions & 1 deletion packages/react-chat/src/utils/broadcast.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { BaseRequest } from '@voiceflow/base-types';

import { SessionOptions } from '@/common';

export enum BroadcastType {
SAVE_SESSION = 'voiceflow:save_session',

INTERACT = 'voiceflow:interact',

OPEN = 'voiceflow:open',
CLOSE = 'voiceflow:close',
}
Expand All @@ -17,14 +21,22 @@ export interface SaveSession extends BroadcastMessage {
payload: SessionOptions;
}

export interface Interact extends BroadcastMessage {
type: BroadcastType.INTERACT;
payload: {
session: SessionOptions;
action: BaseRequest.BaseRequest;
};
}

export interface Open extends BroadcastMessage {
type: BroadcastType.OPEN;
}
export interface Close extends BroadcastMessage {
type: BroadcastType.CLOSE;
}

export type AnyMessage = SaveSession | Open | Close;
export type AnyMessage = SaveSession | Interact | Open | Close;

// send messages so that other scripts can listen to them
// https://developer.voiceflow.com/docs/chat-widget#events
Expand Down

0 comments on commit d44c713

Please sign in to comment.