a01fee02b4181da8918a0b608ad1a2e02bd13bc2
[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 _0x574d=['remove','getUsers','then','setDataValue','Users','map','unreadMessages','length','emit','hasOwnProperty','hook','exports','events','../../mysqldb','WhatsappInteraction','WhatsappMessage','setMaxListeners','save'];(function(_0x3b67fe,_0x3307a8){var _0x3ee0ae=function(_0x93188f){while(--_0x93188f){_0x3b67fe['push'](_0x3b67fe['shift']());}};_0x3ee0ae(++_0x3307a8);}(_0x574d,0xc0));var _0xd574=function(_0x5c2e3e,_0x26ecd3){_0x5c2e3e=_0x5c2e3e-0x0;var _0x53f64a=_0x574d[_0x5c2e3e];return _0x53f64a;};'use strict';var EventEmitter=require(_0xd574('0x0'));var WhatsappInteraction=require(_0xd574('0x1'))['db'][_0xd574('0x2')];var WhatsappMessage=require(_0xd574('0x1'))['db'][_0xd574('0x3')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents[_0xd574('0x4')](0x0);var events={'afterCreate':_0xd574('0x5'),'afterUpdate':'update','afterDestroy':_0xd574('0x6')};function emitEvent(_0x1be154){return function(_0x469ad7,_0x3e2e7d,_0x56ecee){_0x469ad7[_0xd574('0x7')]({'attributes':['id'],'raw':!![]})[_0xd574('0x8')](function(_0x3ce54f){_0x469ad7[_0xd574('0x9')](_0xd574('0xa'),_0x3ce54f[_0xd574('0xb')](function(_0x54fe4f){return{'id':_0x54fe4f['id']};}));return WhatsappMessage['findAll']({'where':{'WhatsappInteractionId':_0x469ad7['id'],'direction':'in','read':![]},'raw':!![]});})[_0xd574('0x8')](function(_0x11ef21){_0x469ad7[_0xd574('0x9')](_0xd574('0xc'),_0x11ef21[_0xd574('0xd')]);WhatsappInteractionEvents[_0xd574('0xe')](_0x1be154+':'+_0x469ad7['id'],_0x469ad7);WhatsappInteractionEvents[_0xd574('0xe')](_0x1be154,_0x469ad7);_0x56ecee(null);})['catch'](_0x56ecee(null));};}for(var e in events){if(events[_0xd574('0xf')](e)){var event=events[e];WhatsappInteraction[_0xd574('0x10')](e,emitEvent(event));}}module[_0xd574('0x11')]=WhatsappInteractionEvents;