From 050df4378971a384fc525917301644eb3dd8d2c9 Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Mon, 18 Oct 2021 18:39:04 +0530 Subject: [PATCH] feat: Adds sound alert notification for new messages on the widget (#3181) * feat: Adds sound alert notification for new messages on the widget * Review fixes * uses absolute path * Minor fixes Co-authored-by: Muhsin Keloth --- app/javascript/packs/widget.js | 2 ++ app/javascript/shared/helpers/AudioNotificationHelper.js | 4 ++++ app/javascript/widget/helpers/actionCable.js | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/app/javascript/packs/widget.js b/app/javascript/packs/widget.js index e4aa8cfd1..7aeaf4545 100644 --- a/app/javascript/packs/widget.js +++ b/app/javascript/packs/widget.js @@ -4,6 +4,7 @@ import VueI18n from 'vue-i18n'; import store from '../widget/store'; import App from '../widget/App.vue'; import ActionCableConnector from '../widget/helpers/actionCable'; +import { getAlertAudio } from 'shared/helpers/AudioNotificationHelper'; import i18n from '../widget/i18n'; Vue.use(VueI18n); @@ -30,4 +31,5 @@ window.onload = () => { window.WOOT_WIDGET, window.chatwootPubsubToken ); + getAlertAudio(); }; diff --git a/app/javascript/shared/helpers/AudioNotificationHelper.js b/app/javascript/shared/helpers/AudioNotificationHelper.js index 07d4bafb0..9896d6b8e 100644 --- a/app/javascript/shared/helpers/AudioNotificationHelper.js +++ b/app/javascript/shared/helpers/AudioNotificationHelper.js @@ -94,3 +94,7 @@ export const newMessageNotification = data => { showBadgeOnFavicon(); } }; + +export const playNewMessageNotificationInWidget = () => { + window.playAudioAlert(); +}; diff --git a/app/javascript/widget/helpers/actionCable.js b/app/javascript/widget/helpers/actionCable.js index c4cf483c6..1bdbba850 100644 --- a/app/javascript/widget/helpers/actionCable.js +++ b/app/javascript/widget/helpers/actionCable.js @@ -1,4 +1,5 @@ import BaseActionCableConnector from '../../shared/helpers/BaseActionCableConnector'; +import { playNewMessageNotificationInWidget } from 'shared/helpers/AudioNotificationHelper'; class ActionCableConnector extends BaseActionCableConnector { constructor(app, pubsubToken) { @@ -36,6 +37,9 @@ class ActionCableConnector extends BaseActionCableConnector { .then(() => { window.bus.$emit('on-agent-message-received'); }); + if (data.sender_type === 'User') { + playNewMessageNotificationInWidget(); + } }; onMessageUpdated = data => {