Built motion from commit a61a4a20.|2.5.46
[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 _0x87ae=['findAll','setDataValue','unreadMessages','length','emit','catch','exports','WhatsappInteraction','setMaxListeners','save','update','then','Users','map'];(function(_0xa1e3e3,_0x29fe0e){var _0xc980e9=function(_0x1f5adc){while(--_0x1f5adc){_0xa1e3e3['push'](_0xa1e3e3['shift']());}};_0xc980e9(++_0x29fe0e);}(_0x87ae,0xf5));var _0xe87a=function(_0xdd2bfa,_0x5bd304){_0xdd2bfa=_0xdd2bfa-0x0;var _0x55397e=_0x87ae[_0xdd2bfa];return _0x55397e;};'use strict';var EventEmitter=require('events');var WhatsappInteraction=require('../../mysqldb')['db'][_0xe87a('0x0')];var WhatsappMessage=require('../../mysqldb')['db']['WhatsappMessage'];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents[_0xe87a('0x1')](0x0);var events={'afterCreate':_0xe87a('0x2'),'afterUpdate':_0xe87a('0x3'),'afterDestroy':'remove'};function emitEvent(_0x28899c){return function(_0x1fa362,_0x1820dc,_0x5ef978){_0x1fa362['getUsers']({'attributes':['id'],'raw':!![]})[_0xe87a('0x4')](function(_0x2fbd6b){_0x1fa362['setDataValue'](_0xe87a('0x5'),_0x2fbd6b[_0xe87a('0x6')](function(_0x48873f){return{'id':_0x48873f['id']};}));return WhatsappMessage[_0xe87a('0x7')]({'where':{'WhatsappInteractionId':_0x1fa362['id'],'direction':'in','read':![]},'raw':!![]});})[_0xe87a('0x4')](function(_0x499cb8){_0x1fa362[_0xe87a('0x8')](_0xe87a('0x9'),_0x499cb8[_0xe87a('0xa')]);WhatsappInteractionEvents[_0xe87a('0xb')](_0x28899c+':'+_0x1fa362['id'],_0x1fa362);WhatsappInteractionEvents[_0xe87a('0xb')](_0x28899c,_0x1fa362);_0x5ef978(null);})[_0xe87a('0xc')](_0x5ef978(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];WhatsappInteraction['hook'](e,emitEvent(event));}}module[_0xe87a('0xd')]=WhatsappInteractionEvents;