Skip to content

Commit

Permalink
adjust event data on message middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio Colajanni committed Jul 3, 2024
1 parent a3ee95c commit bc58676
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/common/interfaces/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export interface ILiveAgentEvent {
type: "liveAgentEvent";
data: {
text?: string;
action: string;
agentName: string;
action?: string;
agentName?: string;
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/webchat/store/messages/message-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ export const createOutputHandler = (store: Store) => output => {
if (isQueueUpdate(output?.data)) {
store.dispatch(updateQueueData(payload));
}
// else {
// TODO: implement events logic on middlewares
// store.dispatch(receiveEvent(output));
// }
} else {
store.dispatch(receiveMessage(output));
}
Expand Down
19 changes: 8 additions & 11 deletions src/webchat/store/messages/message-middleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Middleware } from "redux";
import { StoreState } from "../store";
import { IMessage, IBotMessage } from "../../../common/interfaces/message";
import { IMessage, IBotMessage, IAgentMessage } from "../../../common/interfaces/message";
import { addMessage, addMessageEvent } from "./message-reducer";
import { Omit } from "react-redux";
import { setFullscreenMessage } from "../ui/ui-reducer";
Expand Down Expand Up @@ -60,12 +60,9 @@ export const getAvatarNameForMessage = (message: IMessage, state: StoreState) =>
}
}

export const getAvatarNameForMessageEvent = (state: StoreState) => {
return (state.config.settings.layout.useOtherAgentLogo && state.config.settings.layout.agentAvatarName) || state.config.settings.layout.title || "Agent";
}

export const getTextForMessageEvent = (state: StoreState, action: string) => {
return `${getAvatarNameForMessageEvent(state)} ${action}`;
const agentName = (state.config.settings.layout.useOtherAgentLogo && state.config.settings.layout.agentAvatarName) || state.config.settings.layout.title || "Agent";
return `${agentName} ${action}`;
}

// forwards messages to the socket
Expand Down Expand Up @@ -125,26 +122,26 @@ export const createMessageMiddleware = (client: SocketClient): Middleware<object
const isUnseen = !isWebchatActive && !isMessageEmpty;

// temporary solution: conditionally inject a event message type
// TODO: we should get this kind of status updates from socket output event
if (message.source === "agent" && state.queueUpdates.isQueueActive) {
const mockEventMessage: IMessageEvent = {
const eventMessage: IMessageEvent = {
text: "",
data: {
_cognigy: {
_webchat3Event: {
type: 'liveAgentEvent',
data: {
agentName: getAvatarNameForMessageEvent(state),
action: "joined",
text: getTextForMessageEvent(state, "joined")
}
}
}
}
}
bellSound.play();

next(addMessageEvent({
...mockEventMessage
...eventMessage
} as IMessageEvent));
bellSound.play();
}

next(addMessage({
Expand Down

0 comments on commit bc58676

Please sign in to comment.