3d99c903c40d841c7d61419f20710e8e42a5797f
[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 _0x5c00=['length','catch','hook','exports','events','../../mysqldb','WhatsappInteraction','WhatsappMessage','save','update','remove','getUsers','then','setDataValue','Users','map','findAll','unreadMessages'];(function(_0x1a473b,_0x1e579e){var _0x5535af=function(_0x59ec72){while(--_0x59ec72){_0x1a473b['push'](_0x1a473b['shift']());}};_0x5535af(++_0x1e579e);}(_0x5c00,0x17e));var _0x05c0=function(_0x1cfba1,_0xceafc){_0x1cfba1=_0x1cfba1-0x0;var _0x4fd6aa=_0x5c00[_0x1cfba1];return _0x4fd6aa;};'use strict';var EventEmitter=require(_0x05c0('0x0'));var WhatsappInteraction=require(_0x05c0('0x1'))['db'][_0x05c0('0x2')];var WhatsappMessage=require('../../mysqldb')['db'][_0x05c0('0x3')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents['setMaxListeners'](0x0);var events={'afterCreate':_0x05c0('0x4'),'afterUpdate':_0x05c0('0x5'),'afterDestroy':_0x05c0('0x6')};function emitEvent(_0x28d9c7){return function(_0x565efc,_0x145973,_0x3521fe){_0x565efc[_0x05c0('0x7')]({'attributes':['id'],'raw':!![]})[_0x05c0('0x8')](function(_0x5b9f09){_0x565efc[_0x05c0('0x9')](_0x05c0('0xa'),_0x5b9f09[_0x05c0('0xb')](function(_0x5afd4d){return{'id':_0x5afd4d['id']};}));return WhatsappMessage[_0x05c0('0xc')]({'where':{'WhatsappInteractionId':_0x565efc['id'],'direction':'in','read':![]},'raw':!![]});})[_0x05c0('0x8')](function(_0x996d6b){_0x565efc[_0x05c0('0x9')](_0x05c0('0xd'),_0x996d6b[_0x05c0('0xe')]);WhatsappInteractionEvents['emit'](_0x28d9c7+':'+_0x565efc['id'],_0x565efc);WhatsappInteractionEvents['emit'](_0x28d9c7,_0x565efc);_0x3521fe(null);})[_0x05c0('0xf')](_0x3521fe(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];WhatsappInteraction[_0x05c0('0x10')](e,emitEvent(event));}}module[_0x05c0('0x11')]=WhatsappInteractionEvents;