5eedf744058e42bdaa89c5d160a7d74b59c023f0
[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 _0x27c4=['hook','exports','../../mysqldb','WhatsappMessage','setMaxListeners','save','update','remove','then','setDataValue','Users','findAll','unreadMessages','length','emit','catch','hasOwnProperty'];(function(_0x528651,_0x1bfbdd){var _0x296da8=function(_0x47d202){while(--_0x47d202){_0x528651['push'](_0x528651['shift']());}};_0x296da8(++_0x1bfbdd);}(_0x27c4,0x189));var _0x427c=function(_0x51ecea,_0xc086da){_0x51ecea=_0x51ecea-0x0;var _0x124dcf=_0x27c4[_0x51ecea];return _0x124dcf;};'use strict';var EventEmitter=require('events');var WhatsappInteraction=require(_0x427c('0x0'))['db']['WhatsappInteraction'];var WhatsappMessage=require(_0x427c('0x0'))['db'][_0x427c('0x1')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents[_0x427c('0x2')](0x0);var events={'afterCreate':_0x427c('0x3'),'afterUpdate':_0x427c('0x4'),'afterDestroy':_0x427c('0x5')};function emitEvent(_0xf634e1){return function(_0x58ce91,_0x5bbd70,_0x7b7914){_0x58ce91['getUsers']({'attributes':['id'],'raw':!![]})[_0x427c('0x6')](function(_0x5de80b){_0x58ce91[_0x427c('0x7')](_0x427c('0x8'),_0x5de80b['map'](function(_0x2ee123){return{'id':_0x2ee123['id']};}));return WhatsappMessage[_0x427c('0x9')]({'where':{'WhatsappInteractionId':_0x58ce91['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x53dddc){_0x58ce91[_0x427c('0x7')](_0x427c('0xa'),_0x53dddc[_0x427c('0xb')]);WhatsappInteractionEvents['emit'](_0xf634e1+':'+_0x58ce91['id'],_0x58ce91);WhatsappInteractionEvents[_0x427c('0xc')](_0xf634e1,_0x58ce91);_0x7b7914(null);})[_0x427c('0xd')](_0x7b7914(null));};}for(var e in events){if(events[_0x427c('0xe')](e)){var event=events[e];WhatsappInteraction[_0x427c('0xf')](e,emitEvent(event));}}module[_0x427c('0x10')]=WhatsappInteractionEvents;