e1b14a6509d7f0d8ec910e9f32df95afc2b28e23
[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 _0x820a=['emit','catch','hook','exports','events','../../mysqldb','WhatsappInteraction','WhatsappMessage','save','update','remove','then','Users','findAll','setDataValue','length'];(function(_0xd42ae9,_0x562ea2){var _0x581cff=function(_0x54ec26){while(--_0x54ec26){_0xd42ae9['push'](_0xd42ae9['shift']());}};_0x581cff(++_0x562ea2);}(_0x820a,0x114));var _0xa820=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x820a[_0x3dd15e];return _0x231fd0;};'use strict';var EventEmitter=require(_0xa820('0x0'));var WhatsappInteraction=require(_0xa820('0x1'))['db'][_0xa820('0x2')];var WhatsappMessage=require(_0xa820('0x1'))['db'][_0xa820('0x3')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents['setMaxListeners'](0x0);var events={'afterCreate':_0xa820('0x4'),'afterUpdate':_0xa820('0x5'),'afterDestroy':_0xa820('0x6')};function emitEvent(_0x4395fb){return function(_0x1e48cc,_0x335e2c,_0x51567d){_0x1e48cc['getUsers']({'attributes':['id'],'raw':!![]})[_0xa820('0x7')](function(_0x3adfa3){_0x1e48cc['setDataValue'](_0xa820('0x8'),_0x3adfa3['map'](function(_0x47398a){return{'id':_0x47398a['id']};}));return WhatsappMessage[_0xa820('0x9')]({'where':{'WhatsappInteractionId':_0x1e48cc['id'],'direction':'in','read':![]},'raw':!![]});})[_0xa820('0x7')](function(_0x572522){_0x1e48cc[_0xa820('0xa')]('unreadMessages',_0x572522[_0xa820('0xb')]);WhatsappInteractionEvents['emit'](_0x4395fb+':'+_0x1e48cc['id'],_0x1e48cc);WhatsappInteractionEvents[_0xa820('0xc')](_0x4395fb,_0x1e48cc);_0x51567d(null);})[_0xa820('0xd')](_0x51567d(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];WhatsappInteraction[_0xa820('0xe')](e,emitEvent(event));}}module[_0xa820('0xf')]=WhatsappInteractionEvents;