Built motion from commit 994c64e1.|2.6.1
[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 _0xc36d=['map','unreadMessages','length','emit','catch','hasOwnProperty','events','../../mysqldb','WhatsappInteraction','WhatsappMessage','setMaxListeners','update','remove','getUsers','then','setDataValue','Users'];(function(_0x6ff419,_0x4b4615){var _0x519d78=function(_0x459006){while(--_0x459006){_0x6ff419['push'](_0x6ff419['shift']());}};_0x519d78(++_0x4b4615);}(_0xc36d,0x7d));var _0xdc36=function(_0x2b5eae,_0x55010d){_0x2b5eae=_0x2b5eae-0x0;var _0x5f3ac9=_0xc36d[_0x2b5eae];return _0x5f3ac9;};'use strict';var EventEmitter=require(_0xdc36('0x0'));var WhatsappInteraction=require(_0xdc36('0x1'))['db'][_0xdc36('0x2')];var WhatsappMessage=require(_0xdc36('0x1'))['db'][_0xdc36('0x3')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents[_0xdc36('0x4')](0x0);var events={'afterCreate':'save','afterUpdate':_0xdc36('0x5'),'afterDestroy':_0xdc36('0x6')};function emitEvent(_0x53ac17){return function(_0x18c8fe,_0xbc5223,_0x186c58){_0x18c8fe[_0xdc36('0x7')]({'attributes':['id'],'raw':!![]})[_0xdc36('0x8')](function(_0x571311){_0x18c8fe[_0xdc36('0x9')](_0xdc36('0xa'),_0x571311[_0xdc36('0xb')](function(_0xdca7f7){return{'id':_0xdca7f7['id']};}));return WhatsappMessage['findAll']({'where':{'WhatsappInteractionId':_0x18c8fe['id'],'direction':'in','read':![]},'raw':!![]});})[_0xdc36('0x8')](function(_0x23956b){_0x18c8fe['setDataValue'](_0xdc36('0xc'),_0x23956b[_0xdc36('0xd')]);WhatsappInteractionEvents[_0xdc36('0xe')](_0x53ac17+':'+_0x18c8fe['id'],_0x18c8fe);WhatsappInteractionEvents['emit'](_0x53ac17,_0x18c8fe);_0x186c58(null);})[_0xdc36('0xf')](_0x186c58(null));};}for(var e in events){if(events[_0xdc36('0x10')](e)){var event=events[e];WhatsappInteraction['hook'](e,emitEvent(event));}}module['exports']=WhatsappInteractionEvents;