diff --git a/modules/channel-web/src/backend/api.ts b/modules/channel-web/src/backend/api.ts index 6be02a06b73..2e7b7854999 100755 --- a/modules/channel-web/src/backend/api.ts +++ b/modules/channel-web/src/backend/api.ts @@ -153,6 +153,7 @@ export default async (bp: typeof sdk, db: Database) => { details: botInfo.details, languages: botInfo.languages, extraStylesheet: config.extraStylesheet, + disableNotificationSound: config.disableNotificationSound, security, lazySocket: config.lazySocket }) diff --git a/modules/channel-web/src/config.ts b/modules/channel-web/src/config.ts index a8f43af6d8d..922c7adf55d 100644 --- a/modules/channel-web/src/config.ts +++ b/modules/channel-web/src/config.ts @@ -82,4 +82,10 @@ export interface Config { * @default false */ lazySocket: boolean + + /** + * If true, chat will no longer play the notification sound for new messages. + * @default false + */ + disableNotificationSound: boolean } diff --git a/modules/channel-web/src/views/lite/main.tsx b/modules/channel-web/src/views/lite/main.tsx index 2e7e3249c96..973bf3398b1 100644 --- a/modules/channel-web/src/views/lite/main.tsx +++ b/modules/channel-web/src/views/lite/main.tsx @@ -259,7 +259,13 @@ class Web extends React.Component { } async playSound() { - if (this.state.played) { + // Preference for config object + const disableNotificationSound = + this.config.disableNotificationSound === undefined + ? this.props.config.disableNotificationSound + : this.config.disableNotificationSound + + if (this.state.played || disableNotificationSound) { return } diff --git a/modules/channel-web/src/views/lite/store/index.ts b/modules/channel-web/src/views/lite/store/index.ts index fb39ddbe0c7..ced300dc44e 100644 --- a/modules/channel-web/src/views/lite/store/index.ts +++ b/modules/channel-web/src/views/lite/store/index.ts @@ -208,7 +208,10 @@ class RootStore { runInAction('-> setBotInfo', () => { this.botInfo = botInfo }) - this.mergeConfig({ extraStylesheet: botInfo.extraStylesheet }) + this.mergeConfig({ + extraStylesheet: botInfo.extraStylesheet, + disableNotificationSound: botInfo.disableNotificationSound + }) } @action.bound diff --git a/modules/channel-web/src/views/lite/typings.d.ts b/modules/channel-web/src/views/lite/typings.d.ts index 8d6a4348813..e21b1d04724 100644 --- a/modules/channel-web/src/views/lite/typings.d.ts +++ b/modules/channel-web/src/views/lite/typings.d.ts @@ -180,6 +180,8 @@ export interface Config { reference: string /** If true, Websocket is created when the Webchat is opened. Bot cannot be proactive. */ lazySocket?: boolean + /** If true, chat will no longer play the notification sound for new messages. */ + disableNotificationSound?: boolean /** Refers to a specific webchat reference in parent window. Useful when using multiple chat window */ chatId?: string /** CSS class to be applied to iframe */ diff --git a/src/e2e/modules/webchat.test.ts b/src/e2e/modules/webchat.test.ts index d94701aa20e..363dd0353e6 100644 --- a/src/e2e/modules/webchat.test.ts +++ b/src/e2e/modules/webchat.test.ts @@ -64,4 +64,7 @@ describe('Module - Channel Web', () => { await clickOn('#btn-convo-add') await expect(await getMessageCount(page)).toBe(0) }) + + // puppetter doesn`t have a way of testing sound playback from javascript objects + // it('Test disable sound notification', async () => {}) })