Built motion from commit 10af8726.|2.6.34
[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 _0xf089=['WhatsappInteraction','WhatsappMessage','setMaxListeners','save','update','getUsers','then','setDataValue','Users','map','findAll','unreadMessages','length','emit','hasOwnProperty','hook','../../mysqldb'];(function(_0x3509b9,_0x38bb75){var _0x11704f=function(_0x37a435){while(--_0x37a435){_0x3509b9['push'](_0x3509b9['shift']());}};_0x11704f(++_0x38bb75);}(_0xf089,0xba));var _0x9f08=function(_0x315b01,_0x583ac1){_0x315b01=_0x315b01-0x0;var _0x37c9c4=_0xf089[_0x315b01];return _0x37c9c4;};'use strict';var EventEmitter=require('events');var WhatsappInteraction=require(_0x9f08('0x0'))['db'][_0x9f08('0x1')];var WhatsappMessage=require('../../mysqldb')['db'][_0x9f08('0x2')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents[_0x9f08('0x3')](0x0);var events={'afterCreate':_0x9f08('0x4'),'afterUpdate':_0x9f08('0x5'),'afterDestroy':'remove'};function emitEvent(_0x11d64c){return function(_0x1dced2,_0x352879,_0x13768c){_0x1dced2[_0x9f08('0x6')]({'attributes':['id'],'raw':!![]})[_0x9f08('0x7')](function(_0x5341c9){_0x1dced2[_0x9f08('0x8')](_0x9f08('0x9'),_0x5341c9[_0x9f08('0xa')](function(_0x4ce5b6){return{'id':_0x4ce5b6['id']};}));return WhatsappMessage[_0x9f08('0xb')]({'where':{'WhatsappInteractionId':_0x1dced2['id'],'direction':'in','read':![]},'raw':!![]});})[_0x9f08('0x7')](function(_0x3868b6){_0x1dced2['setDataValue'](_0x9f08('0xc'),_0x3868b6[_0x9f08('0xd')]);WhatsappInteractionEvents[_0x9f08('0xe')](_0x11d64c+':'+_0x1dced2['id'],_0x1dced2);WhatsappInteractionEvents['emit'](_0x11d64c,_0x1dced2);_0x13768c(null);})['catch'](_0x13768c(null));};}for(var e in events){if(events[_0x9f08('0xf')](e)){var event=events[e];WhatsappInteraction[_0x9f08('0x10')](e,emitEvent(event));}}module['exports']=WhatsappInteractionEvents;