18d95fb809b4fa01bcdf67e03589740a29f4dfdc
[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 _0xb16f=['map','unreadMessages','length','emit','catch','hasOwnProperty','hook','exports','events','../../mysqldb','WhatsappInteraction','WhatsappMessage','setMaxListeners','save','update','then','setDataValue'];(function(_0x138adb,_0x193fee){var _0x1b27f2=function(_0x5e97a2){while(--_0x5e97a2){_0x138adb['push'](_0x138adb['shift']());}};_0x1b27f2(++_0x193fee);}(_0xb16f,0xf6));var _0xfb16=function(_0x152121,_0x120c53){_0x152121=_0x152121-0x0;var _0x592a85=_0xb16f[_0x152121];return _0x592a85;};'use strict';var EventEmitter=require(_0xfb16('0x0'));var WhatsappInteraction=require(_0xfb16('0x1'))['db'][_0xfb16('0x2')];var WhatsappMessage=require('../../mysqldb')['db'][_0xfb16('0x3')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents[_0xfb16('0x4')](0x0);var events={'afterCreate':_0xfb16('0x5'),'afterUpdate':_0xfb16('0x6'),'afterDestroy':'remove'};function emitEvent(_0x21fee8){return function(_0x5317a0,_0x4dadf4,_0x5ed3ef){_0x5317a0['getUsers']({'attributes':['id'],'raw':!![]})[_0xfb16('0x7')](function(_0x4de946){_0x5317a0[_0xfb16('0x8')]('Users',_0x4de946[_0xfb16('0x9')](function(_0x2b9baf){return{'id':_0x2b9baf['id']};}));return WhatsappMessage['findAll']({'where':{'WhatsappInteractionId':_0x5317a0['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x5cdd02){_0x5317a0[_0xfb16('0x8')](_0xfb16('0xa'),_0x5cdd02[_0xfb16('0xb')]);WhatsappInteractionEvents[_0xfb16('0xc')](_0x21fee8+':'+_0x5317a0['id'],_0x5317a0);WhatsappInteractionEvents[_0xfb16('0xc')](_0x21fee8,_0x5317a0);_0x5ed3ef(null);})[_0xfb16('0xd')](_0x5ed3ef(null));};}for(var e in events){if(events[_0xfb16('0xe')](e)){var event=events[e];WhatsappInteraction[_0xfb16('0xf')](e,emitEvent(event));}}module[_0xfb16('0x10')]=WhatsappInteractionEvents;