45ba1238fd5927e63612509171be6bd4911e86c2
[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 _0xd845=['setDataValue','emit','catch','hasOwnProperty','hook','events','../../mysqldb','WhatsappInteraction','setMaxListeners','save','update','remove','getUsers','then','Users','findAll'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0xd845,0x135));var _0x5d84=function(_0x68ee8b,_0x3cc6c5){_0x68ee8b=_0x68ee8b-0x0;var _0x5148f7=_0xd845[_0x68ee8b];return _0x5148f7;};'use strict';var EventEmitter=require(_0x5d84('0x0'));var WhatsappInteraction=require(_0x5d84('0x1'))['db'][_0x5d84('0x2')];var WhatsappMessage=require(_0x5d84('0x1'))['db']['WhatsappMessage'];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents[_0x5d84('0x3')](0x0);var events={'afterCreate':_0x5d84('0x4'),'afterUpdate':_0x5d84('0x5'),'afterDestroy':_0x5d84('0x6')};function emitEvent(_0x53ba56){return function(_0x2a4c98,_0x134828,_0x3e48e4){_0x2a4c98[_0x5d84('0x7')]({'attributes':['id'],'raw':!![]})[_0x5d84('0x8')](function(_0x3f0541){_0x2a4c98['setDataValue'](_0x5d84('0x9'),_0x3f0541['map'](function(_0x8958eb){return{'id':_0x8958eb['id']};}));return WhatsappMessage[_0x5d84('0xa')]({'where':{'WhatsappInteractionId':_0x2a4c98['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x13dfc9){_0x2a4c98[_0x5d84('0xb')]('unreadMessages',_0x13dfc9['length']);WhatsappInteractionEvents[_0x5d84('0xc')](_0x53ba56+':'+_0x2a4c98['id'],_0x2a4c98);WhatsappInteractionEvents[_0x5d84('0xc')](_0x53ba56,_0x2a4c98);_0x3e48e4(null);})[_0x5d84('0xd')](_0x3e48e4(null));};}for(var e in events){if(events[_0x5d84('0xe')](e)){var event=events[e];WhatsappInteraction[_0x5d84('0xf')](e,emitEvent(event));}}module['exports']=WhatsappInteractionEvents;