4770cd42f8c5b3192d69768940590f0b711fec3b
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.events.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x0bb5=['emit','catch','hasOwnProperty','hook','exports','events','../../mysqldb','WhatsappMessage','setMaxListeners','save','update','remove','then','setDataValue','Users','findAll','length'];(function(_0x229c4c,_0x3a8890){var _0x441127=function(_0x1f2be7){while(--_0x1f2be7){_0x229c4c['push'](_0x229c4c['shift']());}};_0x441127(++_0x3a8890);}(_0x0bb5,0x148));var _0x50bb=function(_0x4e1707,_0x203ab6){_0x4e1707=_0x4e1707-0x0;var _0xd1eec3=_0x0bb5[_0x4e1707];return _0xd1eec3;};'use strict';var EventEmitter=require(_0x50bb('0x0'));var WhatsappInteraction=require(_0x50bb('0x1'))['db']['WhatsappInteraction'];var WhatsappMessage=require('../../mysqldb')['db'][_0x50bb('0x2')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents[_0x50bb('0x3')](0x0);var events={'afterCreate':_0x50bb('0x4'),'afterUpdate':_0x50bb('0x5'),'afterDestroy':_0x50bb('0x6')};function emitEvent(_0xfdc9d4){return function(_0x451b4c,_0x33f2c5,_0x4e6093){_0x451b4c['getUsers']({'attributes':['id'],'raw':!![]})[_0x50bb('0x7')](function(_0x35de5d){_0x451b4c[_0x50bb('0x8')](_0x50bb('0x9'),_0x35de5d['map'](function(_0x4ab8d7){return{'id':_0x4ab8d7['id']};}));return WhatsappMessage[_0x50bb('0xa')]({'where':{'WhatsappInteractionId':_0x451b4c['id'],'direction':'in','read':![]},'raw':!![]});})[_0x50bb('0x7')](function(_0x3ae598){_0x451b4c[_0x50bb('0x8')]('unreadMessages',_0x3ae598[_0x50bb('0xb')]);WhatsappInteractionEvents[_0x50bb('0xc')](_0xfdc9d4+':'+_0x451b4c['id'],_0x451b4c);WhatsappInteractionEvents[_0x50bb('0xc')](_0xfdc9d4,_0x451b4c);_0x4e6093(null);})[_0x50bb('0xd')](_0x4e6093(null));};}for(var e in events){if(events[_0x50bb('0xe')](e)){var event=events[e];WhatsappInteraction[_0x50bb('0xf')](e,emitEvent(event));}}module[_0x50bb('0x10')]=WhatsappInteractionEvents;