Built motion from commit 47436d59.|2.6.7
[motion2.git] / server / api / mailInteraction / mailInteraction.rpc.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 _0x0404=['../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','client','http','redis','defaults','socket.io-emitter','then','MailInteraction,\x20%s,\x20%s','request\x20sent','debug','MailInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','UpdateMailInteraction','options','attributes','limit','AddTagsToMailInteraction','addTags','body','omit','spread','info','AddTags','util','moment','bluebird','randomstring','ioredis'];(function(_0xc22509,_0x1e32a0){var _0x5af8e7=function(_0x1bd3b8){while(--_0x1bd3b8){_0xc22509['push'](_0xc22509['shift']());}};_0x5af8e7(++_0x1e32a0);}(_0x0404,0x123));var _0x4040=function(_0x3e531a,_0x28a82a){_0x3e531a=_0x3e531a-0x0;var _0x3c2574=_0x0404[_0x3e531a];return _0x3c2574;};'use strict';var _=require('lodash');var util=require(_0x4040('0x0'));var moment=require(_0x4040('0x1'));var BPromise=require(_0x4040('0x2'));var rs=require(_0x4040('0x3'));var fs=require('fs');var Redis=require(_0x4040('0x4'));var db=require(_0x4040('0x5'))['db'];var utils=require(_0x4040('0x6'));var logger=require(_0x4040('0x7'))(_0x4040('0x8'));var config=require(_0x4040('0x9'));var jayson=require('jayson/promise');var client=jayson[_0x4040('0xa')][_0x4040('0xb')]({'port':0x232a});config[_0x4040('0xc')]=_[_0x4040('0xd')](config[_0x4040('0xc')],{'host':'localhost','port':0x18eb});var socket=require(_0x4040('0xe'))(new Redis(config[_0x4040('0xc')]));require('./mailInteraction.socket')['register'](socket);function respondWithRpcPromise(_0xf90610,_0x21edec,_0x57c170){return new BPromise(function(_0x2b9595,_0x4a0628){return client['request'](_0xf90610,_0x57c170)[_0x4040('0xf')](function(_0x47fd00){logger['info'](_0x4040('0x10'),_0x21edec,_0x4040('0x11'));logger[_0x4040('0x12')](_0x4040('0x13'),_0x21edec,_0x4040('0x11'),JSON[_0x4040('0x14')](_0x47fd00));if(_0x47fd00[_0x4040('0x15')]){if(_0x47fd00['error'][_0x4040('0x16')]===0x1f4){logger[_0x4040('0x15')](_0x4040('0x10'),_0x21edec,_0x47fd00[_0x4040('0x15')][_0x4040('0x17')]);return _0x4a0628(_0x47fd00['error']['message']);}logger[_0x4040('0x15')]('MailInteraction,\x20%s,\x20%s',_0x21edec,_0x47fd00['error'][_0x4040('0x17')]);return _0x2b9595(_0x47fd00[_0x4040('0x15')]['message']);}else{logger['info']('MailInteraction,\x20%s,\x20%s',_0x21edec,_0x4040('0x11'));_0x2b9595(_0x47fd00[_0x4040('0x18')][_0x4040('0x17')]);}})[_0x4040('0x19')](function(_0x3f9328){logger[_0x4040('0x15')]('MailInteraction,\x20%s,\x20%s',_0x21edec,_0x3f9328);_0x4a0628(_0x3f9328);});});}exports[_0x4040('0x1a')]=function(_0x453b65){var _0x45b562=this;return new Promise(function(_0x70353c,_0x2ea97c){return db['MailInteraction']['update'](_0x453b65['body'],{'raw':_0x453b65[_0x4040('0x1b')]?_0x453b65['options']['raw']===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x453b65['options']?_0x453b65['options']['where']||null:null,'attributes':_0x453b65[_0x4040('0x1b')]?_0x453b65['options'][_0x4040('0x1c')]||null:null,'limit':_0x453b65['options']?_0x453b65['options'][_0x4040('0x1d')]||null:null})[_0x4040('0xf')](function(_0xf6353d){logger['info'](_0x4040('0x1a'),_0x453b65);logger[_0x4040('0x12')](_0x4040('0x1a'),_0x453b65,JSON[_0x4040('0x14')](_0xf6353d));_0x70353c(_0xf6353d);})[_0x4040('0x19')](function(_0x256521){logger['error'](_0x4040('0x1a'),_0x256521[_0x4040('0x17')],_0x453b65);_0x2ea97c(_0x45b562['error'](0x1f4,_0x256521[_0x4040('0x17')]));});});};exports[_0x4040('0x1e')]=function(_0x588512){return new Promise(function(_0x1c167f,_0x29a175){return db['MailInteraction']['find']({'where':_0x588512[_0x4040('0x1b')]?_0x588512[_0x4040('0x1b')]['where']||null:null})[_0x4040('0xf')](function(_0x1337a7){if(_0x1337a7){return _0x1337a7[_0x4040('0x1f')](_0x588512[_0x4040('0x20')]['ids'],_[_0x4040('0x21')](_0x588512['body'],['ids','id'])||{});}})[_0x4040('0x22')](function(_0x2eee92){logger[_0x4040('0x23')](_0x4040('0x24'),_0x588512);logger['debug']('AddTags',_0x588512,JSON[_0x4040('0x14')](_0x2eee92));_0x1c167f(_0x2eee92);})['catch'](function(_0x446f78){logger[_0x4040('0x15')](_0x4040('0x24'),_0x446f78['message'],_0x588512);_0x29a175(_this['error'](0x1f4,_0x446f78[_0x4040('0x17')]));});});};