43373d3074f04e2dba64371946e45ccaa60b4dad
[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 _0xdf9e=['emit','hasOwnProperty','exports','events','WhatsappInteraction','../../mysqldb','WhatsappMessage','save','update','then','setDataValue','findAll','unreadMessages','length'];(function(_0x1cd839,_0x232db6){var _0x46e563=function(_0x3ac82d){while(--_0x3ac82d){_0x1cd839['push'](_0x1cd839['shift']());}};_0x46e563(++_0x232db6);}(_0xdf9e,0x161));var _0xedf9=function(_0x3cf2e9,_0x557808){_0x3cf2e9=_0x3cf2e9-0x0;var _0x25b5f4=_0xdf9e[_0x3cf2e9];return _0x25b5f4;};'use strict';var EventEmitter=require(_0xedf9('0x0'));var WhatsappInteraction=require('../../mysqldb')['db'][_0xedf9('0x1')];var WhatsappMessage=require(_0xedf9('0x2'))['db'][_0xedf9('0x3')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents['setMaxListeners'](0x0);var events={'afterCreate':_0xedf9('0x4'),'afterUpdate':_0xedf9('0x5'),'afterDestroy':'remove'};function emitEvent(_0x2c926f){return function(_0x248c2f,_0x456d31,_0x299e66){_0x248c2f['getUsers']({'attributes':['id'],'raw':!![]})[_0xedf9('0x6')](function(_0x59a442){_0x248c2f[_0xedf9('0x7')]('Users',_0x59a442['map'](function(_0x48ef5b){return{'id':_0x48ef5b['id']};}));return WhatsappMessage[_0xedf9('0x8')]({'where':{'WhatsappInteractionId':_0x248c2f['id'],'direction':'in','read':![]},'raw':!![]});})[_0xedf9('0x6')](function(_0xea9e39){_0x248c2f[_0xedf9('0x7')](_0xedf9('0x9'),_0xea9e39[_0xedf9('0xa')]);WhatsappInteractionEvents['emit'](_0x2c926f+':'+_0x248c2f['id'],_0x248c2f);WhatsappInteractionEvents[_0xedf9('0xb')](_0x2c926f,_0x248c2f);_0x299e66(null);})['catch'](_0x299e66(null));};}for(var e in events){if(events[_0xedf9('0xc')](e)){var event=events[e];WhatsappInteraction['hook'](e,emitEvent(event));}}module[_0xedf9('0xd')]=WhatsappInteractionEvents;