f25cf7113fcbd82d0cbb8c9acc3a7515e26d9ba0
[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 _0xcb87=['map','findAll','then','unreadMessages','length','emit','catch','hasOwnProperty','events','../../mysqldb','WhatsappInteraction','WhatsappMessage','setMaxListeners','save','remove','getUsers','setDataValue'];(function(_0x903228,_0x42c429){var _0xcec81d=function(_0x4da97a){while(--_0x4da97a){_0x903228['push'](_0x903228['shift']());}};_0xcec81d(++_0x42c429);}(_0xcb87,0x1c2));var _0x7cb8=function(_0x256b72,_0x340985){_0x256b72=_0x256b72-0x0;var _0x2183e3=_0xcb87[_0x256b72];return _0x2183e3;};'use strict';var EventEmitter=require(_0x7cb8('0x0'));var WhatsappInteraction=require(_0x7cb8('0x1'))['db'][_0x7cb8('0x2')];var WhatsappMessage=require(_0x7cb8('0x1'))['db'][_0x7cb8('0x3')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents[_0x7cb8('0x4')](0x0);var events={'afterCreate':_0x7cb8('0x5'),'afterUpdate':'update','afterDestroy':_0x7cb8('0x6')};function emitEvent(_0x700f4e){return function(_0x5c4bb7,_0x67b6d5,_0x5c1278){_0x5c4bb7[_0x7cb8('0x7')]({'attributes':['id'],'raw':!![]})['then'](function(_0x2e9934){_0x5c4bb7[_0x7cb8('0x8')]('Users',_0x2e9934[_0x7cb8('0x9')](function(_0x4b1a54){return{'id':_0x4b1a54['id']};}));return WhatsappMessage[_0x7cb8('0xa')]({'where':{'WhatsappInteractionId':_0x5c4bb7['id'],'direction':'in','read':![]},'raw':!![]});})[_0x7cb8('0xb')](function(_0x328b00){_0x5c4bb7['setDataValue'](_0x7cb8('0xc'),_0x328b00[_0x7cb8('0xd')]);WhatsappInteractionEvents[_0x7cb8('0xe')](_0x700f4e+':'+_0x5c4bb7['id'],_0x5c4bb7);WhatsappInteractionEvents[_0x7cb8('0xe')](_0x700f4e,_0x5c4bb7);_0x5c1278(null);})[_0x7cb8('0xf')](_0x5c1278(null));};}for(var e in events){if(events[_0x7cb8('0x10')](e)){var event=events[e];WhatsappInteraction['hook'](e,emitEvent(event));}}module['exports']=WhatsappInteractionEvents;