Feature: Alert widget user when message is received from agent (#571)

This commit is contained in:
Pranav Raj S 2020-02-29 11:27:02 +05:30 committed by GitHub
parent b05f843790
commit e8cf59c661
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 0 deletions

Binary file not shown.

View file

@ -0,0 +1,9 @@
const notificationAudio = require('shared/assets/audio/ding.mp3');
export const playNotificationAudio = () => {
try {
new Audio(notificationAudio).play();
} catch (error) {
console.log(error);
}
};

View file

@ -2,6 +2,7 @@
import Vue from 'vue';
import { sendMessageAPI, getConversationAPI } from 'widget/api/conversation';
import { MESSAGE_TYPE } from 'widget/helpers/constants';
import { playNotificationAudio } from 'shared/helpers/AudioNotificationHelper';
import getUuid from '../../helpers/uuid';
import DateHelper from '../../../shared/helpers/DateHelper';
@ -93,6 +94,10 @@ export const actions = {
},
addMessage({ commit }, data) {
if (data.message_type === MESSAGE_TYPE.OUTGOING) {
playNotificationAudio();
}
commit('pushMessageToConversation', data);
},
};

View file

@ -1,7 +1,11 @@
import { playNotificationAudio } from 'shared/helpers/AudioNotificationHelper';
import { actions } from '../../conversation';
import getUuid from '../../../../helpers/uuid';
jest.mock('../../../../helpers/uuid');
jest.mock('shared/helpers/AudioNotificationHelper', () => ({
playNotificationAudio: jest.fn(),
}));
const commit = jest.fn();
@ -11,6 +15,15 @@ describe('#actions', () => {
actions.addMessage({ commit }, { id: 1 });
expect(commit).toBeCalledWith('pushMessageToConversation', { id: 1 });
});
it('plays audio when agent sends a message', () => {
actions.addMessage({ commit }, { id: 1, message_type: 1 });
expect(playNotificationAudio).toBeCalled();
expect(commit).toBeCalledWith('pushMessageToConversation', {
id: 1,
message_type: 1,
});
});
});
describe('#sendMessage', () => {