f9d0d534a9d212f86fb953e7a337520ce3d182a1
[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 _0x9c5e=['hasOwnProperty','hook','exports','events','../../mysqldb','WhatsappInteraction','WhatsappMessage','remove','getUsers','then','setDataValue','Users','map','unreadMessages','length','emit','catch'];(function(_0xb7dce7,_0x247483){var _0x331bc4=function(_0x4a06b2){while(--_0x4a06b2){_0xb7dce7['push'](_0xb7dce7['shift']());}};_0x331bc4(++_0x247483);}(_0x9c5e,0x9c));var _0xe9c5=function(_0x54db3c,_0x57a938){_0x54db3c=_0x54db3c-0x0;var _0x89abe3=_0x9c5e[_0x54db3c];return _0x89abe3;};'use strict';var EventEmitter=require(_0xe9c5('0x0'));var WhatsappInteraction=require(_0xe9c5('0x1'))['db'][_0xe9c5('0x2')];var WhatsappMessage=require(_0xe9c5('0x1'))['db'][_0xe9c5('0x3')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents['setMaxListeners'](0x0);var events={'afterCreate':'save','afterUpdate':'update','afterDestroy':_0xe9c5('0x4')};function emitEvent(_0x13d5d7){return function(_0x4fa4c5,_0x361ef3,_0x5c11e5){_0x4fa4c5[_0xe9c5('0x5')]({'attributes':['id'],'raw':!![]})[_0xe9c5('0x6')](function(_0x5b1c04){_0x4fa4c5[_0xe9c5('0x7')](_0xe9c5('0x8'),_0x5b1c04[_0xe9c5('0x9')](function(_0x38218c){return{'id':_0x38218c['id']};}));return WhatsappMessage['findAll']({'where':{'WhatsappInteractionId':_0x4fa4c5['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x29d7e0){_0x4fa4c5[_0xe9c5('0x7')](_0xe9c5('0xa'),_0x29d7e0[_0xe9c5('0xb')]);WhatsappInteractionEvents[_0xe9c5('0xc')](_0x13d5d7+':'+_0x4fa4c5['id'],_0x4fa4c5);WhatsappInteractionEvents[_0xe9c5('0xc')](_0x13d5d7,_0x4fa4c5);_0x5c11e5(null);})[_0xe9c5('0xd')](_0x5c11e5(null));};}for(var e in events){if(events[_0xe9c5('0xe')](e)){var event=events[e];WhatsappInteraction[_0xe9c5('0xf')](e,emitEvent(event));}}module[_0xe9c5('0x10')]=WhatsappInteractionEvents;