4bffeb7477bcdf9ae8ad6c1821b4827046b52412
[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 _0xe130=['update','then','map','setDataValue','unreadMessages','length','catch','hasOwnProperty','hook','exports','events','../../mysqldb','WhatsappMessage','setMaxListeners','save'];(function(_0x4d0cc5,_0x3d1776){var _0xa6f552=function(_0x2c2e66){while(--_0x2c2e66){_0x4d0cc5['push'](_0x4d0cc5['shift']());}};_0xa6f552(++_0x3d1776);}(_0xe130,0x127));var _0x0e13=function(_0xdfb448,_0x2921fd){_0xdfb448=_0xdfb448-0x0;var _0x164a0f=_0xe130[_0xdfb448];return _0x164a0f;};'use strict';var EventEmitter=require(_0x0e13('0x0'));var WhatsappInteraction=require(_0x0e13('0x1'))['db']['WhatsappInteraction'];var WhatsappMessage=require(_0x0e13('0x1'))['db'][_0x0e13('0x2')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents[_0x0e13('0x3')](0x0);var events={'afterCreate':_0x0e13('0x4'),'afterUpdate':_0x0e13('0x5'),'afterDestroy':'remove'};function emitEvent(_0x1489a9){return function(_0x223c28,_0xf8d012,_0xcd92e){_0x223c28['getUsers']({'attributes':['id'],'raw':!![]})[_0x0e13('0x6')](function(_0x5f0d09){_0x223c28['setDataValue']('Users',_0x5f0d09[_0x0e13('0x7')](function(_0x45dcfe){return{'id':_0x45dcfe['id']};}));return WhatsappMessage['findAll']({'where':{'WhatsappInteractionId':_0x223c28['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x2906e9){_0x223c28[_0x0e13('0x8')](_0x0e13('0x9'),_0x2906e9[_0x0e13('0xa')]);WhatsappInteractionEvents['emit'](_0x1489a9+':'+_0x223c28['id'],_0x223c28);WhatsappInteractionEvents['emit'](_0x1489a9,_0x223c28);_0xcd92e(null);})[_0x0e13('0xb')](_0xcd92e(null));};}for(var e in events){if(events[_0x0e13('0xc')](e)){var event=events[e];WhatsappInteraction[_0x0e13('0xd')](e,emitEvent(event));}}module[_0x0e13('0xe')]=WhatsappInteractionEvents;