Built motion from commit (unavailable).|2.5.15
[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 _0xd6fb=['length','emit','catch','hasOwnProperty','hook','exports','../../mysqldb','WhatsappInteraction','WhatsappMessage','setMaxListeners','update','remove','getUsers','then','setDataValue','Users','map','unreadMessages'];(function(_0x1f0ec6,_0x5b152b){var _0x1f1619=function(_0x345886){while(--_0x345886){_0x1f0ec6['push'](_0x1f0ec6['shift']());}};_0x1f1619(++_0x5b152b);}(_0xd6fb,0xba));var _0xbd6f=function(_0x5ae6f0,_0x4733a9){_0x5ae6f0=_0x5ae6f0-0x0;var _0x23f4e1=_0xd6fb[_0x5ae6f0];return _0x23f4e1;};'use strict';var EventEmitter=require('events');var WhatsappInteraction=require(_0xbd6f('0x0'))['db'][_0xbd6f('0x1')];var WhatsappMessage=require('../../mysqldb')['db'][_0xbd6f('0x2')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents[_0xbd6f('0x3')](0x0);var events={'afterCreate':'save','afterUpdate':_0xbd6f('0x4'),'afterDestroy':_0xbd6f('0x5')};function emitEvent(_0x17ac0e){return function(_0x4a3de0,_0x20b8ed,_0xa8e9ed){_0x4a3de0[_0xbd6f('0x6')]({'attributes':['id'],'raw':!![]})[_0xbd6f('0x7')](function(_0x4bc5de){_0x4a3de0[_0xbd6f('0x8')](_0xbd6f('0x9'),_0x4bc5de[_0xbd6f('0xa')](function(_0x5a532e){return{'id':_0x5a532e['id']};}));return WhatsappMessage['findAll']({'where':{'WhatsappInteractionId':_0x4a3de0['id'],'direction':'in','read':![]},'raw':!![]});})[_0xbd6f('0x7')](function(_0x396dbf){_0x4a3de0[_0xbd6f('0x8')](_0xbd6f('0xb'),_0x396dbf[_0xbd6f('0xc')]);WhatsappInteractionEvents[_0xbd6f('0xd')](_0x17ac0e+':'+_0x4a3de0['id'],_0x4a3de0);WhatsappInteractionEvents['emit'](_0x17ac0e,_0x4a3de0);_0xa8e9ed(null);})[_0xbd6f('0xe')](_0xa8e9ed(null));};}for(var e in events){if(events[_0xbd6f('0xf')](e)){var event=events[e];WhatsappInteraction[_0xbd6f('0x10')](e,emitEvent(event));}}module[_0xbd6f('0x11')]=WhatsappInteractionEvents;