Built motion from commit b58257bb.|2.5.37
[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 _0x1bd1=['unreadMessages','length','emit','catch','hasOwnProperty','hook','events','../../mysqldb','WhatsappInteraction','WhatsappMessage','then','setDataValue','Users','map','findAll'];(function(_0x4b9c83,_0x3e6e05){var _0x2ee121=function(_0x5d7572){while(--_0x5d7572){_0x4b9c83['push'](_0x4b9c83['shift']());}};_0x2ee121(++_0x3e6e05);}(_0x1bd1,0x123));var _0x11bd=function(_0x47d949,_0x43e42e){_0x47d949=_0x47d949-0x0;var _0x23dbe6=_0x1bd1[_0x47d949];return _0x23dbe6;};'use strict';var EventEmitter=require(_0x11bd('0x0'));var WhatsappInteraction=require(_0x11bd('0x1'))['db'][_0x11bd('0x2')];var WhatsappMessage=require('../../mysqldb')['db'][_0x11bd('0x3')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents['setMaxListeners'](0x0);var events={'afterCreate':'save','afterUpdate':'update','afterDestroy':'remove'};function emitEvent(_0x1f41c3){return function(_0x31869a,_0x336fd5,_0x612ff3){_0x31869a['getUsers']({'attributes':['id'],'raw':!![]})[_0x11bd('0x4')](function(_0x1f813c){_0x31869a[_0x11bd('0x5')](_0x11bd('0x6'),_0x1f813c[_0x11bd('0x7')](function(_0x4e514c){return{'id':_0x4e514c['id']};}));return WhatsappMessage[_0x11bd('0x8')]({'where':{'WhatsappInteractionId':_0x31869a['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x4b3471){_0x31869a[_0x11bd('0x5')](_0x11bd('0x9'),_0x4b3471[_0x11bd('0xa')]);WhatsappInteractionEvents[_0x11bd('0xb')](_0x1f41c3+':'+_0x31869a['id'],_0x31869a);WhatsappInteractionEvents[_0x11bd('0xb')](_0x1f41c3,_0x31869a);_0x612ff3(null);})[_0x11bd('0xc')](_0x612ff3(null));};}for(var e in events){if(events[_0x11bd('0xd')](e)){var event=events[e];WhatsappInteraction[_0x11bd('0xe')](e,emitEvent(event));}}module['exports']=WhatsappInteractionEvents;