b3e8d7a0fe4857b0725e2c0d34cbb85cf3b05305
[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 _0xd61e=['findAll','then','setDataValue','emit','catch','events','../../mysqldb','WhatsappInteraction','WhatsappMessage','setMaxListeners','update','remove','getUsers'];(function(_0x3bf83f,_0x181cac){var _0x22c4a9=function(_0xb3ff0d){while(--_0xb3ff0d){_0x3bf83f['push'](_0x3bf83f['shift']());}};_0x22c4a9(++_0x181cac);}(_0xd61e,0x13d));var _0xed61=function(_0x1e49bb,_0x2cfd6c){_0x1e49bb=_0x1e49bb-0x0;var _0x63d439=_0xd61e[_0x1e49bb];return _0x63d439;};'use strict';var EventEmitter=require(_0xed61('0x0'));var WhatsappInteraction=require(_0xed61('0x1'))['db'][_0xed61('0x2')];var WhatsappMessage=require(_0xed61('0x1'))['db'][_0xed61('0x3')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents[_0xed61('0x4')](0x0);var events={'afterCreate':'save','afterUpdate':_0xed61('0x5'),'afterDestroy':_0xed61('0x6')};function emitEvent(_0x152e2d){return function(_0x376e19,_0x1739bd,_0x39e7f8){_0x376e19[_0xed61('0x7')]({'attributes':['id'],'raw':!![]})['then'](function(_0x5e6173){_0x376e19['setDataValue']('Users',_0x5e6173['map'](function(_0xbac89d){return{'id':_0xbac89d['id']};}));return WhatsappMessage[_0xed61('0x8')]({'where':{'WhatsappInteractionId':_0x376e19['id'],'direction':'in','read':![]},'raw':!![]});})[_0xed61('0x9')](function(_0xfd8844){_0x376e19[_0xed61('0xa')]('unreadMessages',_0xfd8844['length']);WhatsappInteractionEvents['emit'](_0x152e2d+':'+_0x376e19['id'],_0x376e19);WhatsappInteractionEvents[_0xed61('0xb')](_0x152e2d,_0x376e19);_0x39e7f8(null);})[_0xed61('0xc')](_0x39e7f8(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];WhatsappInteraction['hook'](e,emitEvent(event));}}module['exports']=WhatsappInteractionEvents;