Built motion from commit (unavailable).|2.5.4
[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 _0x8b4c=['map','then','length','emit','catch','hasOwnProperty','exports','../../mysqldb','WhatsappInteraction','WhatsappMessage','setMaxListeners','save','update','remove','getUsers','setDataValue','Users'];(function(_0x5396a1,_0x191c86){var _0x487a1e=function(_0x493835){while(--_0x493835){_0x5396a1['push'](_0x5396a1['shift']());}};_0x487a1e(++_0x191c86);}(_0x8b4c,0xb1));var _0xc8b4=function(_0x6dc069,_0x3c9b94){_0x6dc069=_0x6dc069-0x0;var _0x68396b=_0x8b4c[_0x6dc069];return _0x68396b;};'use strict';var EventEmitter=require('events');var WhatsappInteraction=require(_0xc8b4('0x0'))['db'][_0xc8b4('0x1')];var WhatsappMessage=require('../../mysqldb')['db'][_0xc8b4('0x2')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents[_0xc8b4('0x3')](0x0);var events={'afterCreate':_0xc8b4('0x4'),'afterUpdate':_0xc8b4('0x5'),'afterDestroy':_0xc8b4('0x6')};function emitEvent(_0x19f5f6){return function(_0x2b5e13,_0xc9150e,_0x21c5d8){_0x2b5e13[_0xc8b4('0x7')]({'attributes':['id'],'raw':!![]})['then'](function(_0x2172be){_0x2b5e13[_0xc8b4('0x8')](_0xc8b4('0x9'),_0x2172be[_0xc8b4('0xa')](function(_0x34b32d){return{'id':_0x34b32d['id']};}));return WhatsappMessage['findAll']({'where':{'WhatsappInteractionId':_0x2b5e13['id'],'direction':'in','read':![]},'raw':!![]});})[_0xc8b4('0xb')](function(_0x7a02ff){_0x2b5e13[_0xc8b4('0x8')]('unreadMessages',_0x7a02ff[_0xc8b4('0xc')]);WhatsappInteractionEvents[_0xc8b4('0xd')](_0x19f5f6+':'+_0x2b5e13['id'],_0x2b5e13);WhatsappInteractionEvents[_0xc8b4('0xd')](_0x19f5f6,_0x2b5e13);_0x21c5d8(null);})[_0xc8b4('0xe')](_0x21c5d8(null));};}for(var e in events){if(events[_0xc8b4('0xf')](e)){var event=events[e];WhatsappInteraction['hook'](e,emitEvent(event));}}module[_0xc8b4('0x10')]=WhatsappInteractionEvents;