f9bb9f23e5dc61e8464e046a99ac92bfeefb4ab5
[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 _0x3d7f=['setMaxListeners','save','update','then','setDataValue','map','findAll','unreadMessages','length','emit','catch','exports','events','WhatsappInteraction','WhatsappMessage'];(function(_0x1123bb,_0x54472a){var _0xdeb602=function(_0x529467){while(--_0x529467){_0x1123bb['push'](_0x1123bb['shift']());}};_0xdeb602(++_0x54472a);}(_0x3d7f,0x1a1));var _0xf3d7=function(_0x5c3c0b,_0x4ee35e){_0x5c3c0b=_0x5c3c0b-0x0;var _0x52ecd2=_0x3d7f[_0x5c3c0b];return _0x52ecd2;};'use strict';var EventEmitter=require(_0xf3d7('0x0'));var WhatsappInteraction=require('../../mysqldb')['db'][_0xf3d7('0x1')];var WhatsappMessage=require('../../mysqldb')['db'][_0xf3d7('0x2')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents[_0xf3d7('0x3')](0x0);var events={'afterCreate':_0xf3d7('0x4'),'afterUpdate':_0xf3d7('0x5'),'afterDestroy':'remove'};function emitEvent(_0x574073){return function(_0x433483,_0x20fb37,_0x5b667c){_0x433483['getUsers']({'attributes':['id'],'raw':!![]})[_0xf3d7('0x6')](function(_0x17d875){_0x433483[_0xf3d7('0x7')]('Users',_0x17d875[_0xf3d7('0x8')](function(_0x2d2bcd){return{'id':_0x2d2bcd['id']};}));return WhatsappMessage[_0xf3d7('0x9')]({'where':{'WhatsappInteractionId':_0x433483['id'],'direction':'in','read':![]},'raw':!![]});})[_0xf3d7('0x6')](function(_0x167637){_0x433483[_0xf3d7('0x7')](_0xf3d7('0xa'),_0x167637[_0xf3d7('0xb')]);WhatsappInteractionEvents[_0xf3d7('0xc')](_0x574073+':'+_0x433483['id'],_0x433483);WhatsappInteractionEvents[_0xf3d7('0xc')](_0x574073,_0x433483);_0x5b667c(null);})[_0xf3d7('0xd')](_0x5b667c(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];WhatsappInteraction['hook'](e,emitEvent(event));}}module[_0xf3d7('0xe')]=WhatsappInteractionEvents;