Skip to content

Commit

Permalink
misc: trigger call logger event when ai note updated (#954)
Browse files Browse the repository at this point in the history
  • Loading branch information
embbnux authored Jan 6, 2025
1 parent e98a393 commit f01fead
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/components/SideDrawerView/SmartNoteApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function SmartNoteApp({
onAlert,
smartNoteRemoteEntry,
themeType,
onSave,
}) {
const theme = useTheme();
const SmartNotePlugin = useApp({
Expand All @@ -47,6 +48,7 @@ export function SmartNoteApp({
onAlert={onAlert}
theme={theme}
themeType={themeType}
onSave={onSave}
/>
</Container>
);
Expand Down
2 changes: 2 additions & 0 deletions src/components/SideDrawerView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function SideDrawerView({
onClose,
onAlert,
themeType,
onSmartNoteSave,
}) {
const [session, setSession] = useState(null);
useEffect(() => {
Expand Down Expand Up @@ -46,6 +47,7 @@ export function SideDrawerView({
onAlert={onAlert}
smartNoteRemoteEntry={smartNoteRemoteEntry}
themeType={themeType}
onSave={onSmartNoteSave}
/>
</StyledDrawer>
);
Expand Down
15 changes: 14 additions & 1 deletion src/modules/CallLogger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { computed } from '@ringcentral-integration/core';
import { Module } from '@ringcentral-integration/commons/lib/di';
import { CallLogger as CallLoggerBase } from '@ringcentral-integration/commons/modules/CallLogger';
import { isRinging } from '@ringcentral-integration/commons/lib/callLogHelpers';
import { callLoggerTriggerTypes } from '@ringcentral-integration/commons/enums/callLoggerTriggerTypes';

@Module({
name: 'CallLogger',
deps: ['ThirdPartyService', 'CallLog'],
deps: ['ThirdPartyService', 'CallLog', 'SmartNotes'],
})
export class CallLogger extends CallLoggerBase {
private _logFunction: (data: any) => Promise<void>;
Expand All @@ -19,6 +20,7 @@ export class CallLogger extends CallLoggerBase {
};
this._readyCheckFunction = () => this._deps.thirdPartyService.callLoggerRegistered;
this._autoLogHistoryCallsTimer = null;
this._deps.smartNotes.onSmartNoteUpdate(this.onCallNoteUpdated);
}

async _doLog({ item, ...options }) {
Expand Down Expand Up @@ -127,4 +129,15 @@ export class CallLogger extends CallLoggerBase {
get hideEditLogButton() {
return this._deps.thirdPartyService.callLoggerHideEditLogButton;
}

onCallNoteUpdated = (telephonySessionId) => {
if (!this.ready) {
return;
}
const call = this._deps.callHistory.calls.find(call => call.telephonySessionId === telephonySessionId);
if (!call) {
return;
}
this._onCallUpdated(call, callLoggerTriggerTypes.callLogSync);
}
}
7 changes: 6 additions & 1 deletion src/modules/SideDrawerUI/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,15 @@ export class SideDrawerUI extends RcUIModuleV2 {
});
}

onSmartNoteSave = async (data) => {
return this._deps.smartNotes.onSmartNoteSave();
}

getUIFunctions() {
return {
onClose: this.onClose,
onAlert: this.onAlert
onAlert: this.onAlert,
onSmartNoteSave: this.onSmartNoteSave,
};
}
}
21 changes: 21 additions & 0 deletions src/modules/SmartNotes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class SmartNotes extends RcModuleV2 {
protected _smartNoteMFERemoteEntry: string;
protected _smartNoteIframeUri: string;
protected _webphoneHookAdded: boolean;
protected _onSmartNoteUpdate?: (id: string) => void;

constructor(deps) {
super({
Expand All @@ -65,6 +66,7 @@ export class SmartNotes extends RcModuleV2 {
this._smartNoteIframeUri = '';
this._smartNoteMFERemoteEntry = '';
this._webphoneHookAdded = false;
this._onSmartNoteUpdate = undefined;
}

async onInit() {
Expand Down Expand Up @@ -409,6 +411,11 @@ export class SmartNotes extends RcModuleV2 {
this.smartNoteTextStore = newStore;
}

@action
removeSmartNoteTextStore(id) {
this.smartNoteTextStore = this.smartNoteTextStore.filter((item) => item.id !== id);
}

async _fetchNotesUntilFinished(telephonySessionId, retryCount = 0) {
const sdk = this._deps.client.service;
const result = await this.SmartNoteClient.getNotes(sdk, telephonySessionId);
Expand Down Expand Up @@ -509,4 +516,18 @@ export class SmartNotes extends RcModuleV2 {
return map;
}, {});
}

onSmartNoteSave = async () => {
if (!this.session) {
return;
}
this.removeSmartNoteTextStore(this.session.id);
if (this._onSmartNoteUpdate) {
this._onSmartNoteUpdate(this.session.id);
}
}

onSmartNoteUpdate(onSmartNoteUpdate) {
this._onSmartNoteUpdate = onSmartNoteUpdate;
}
}

0 comments on commit f01fead

Please sign in to comment.