Built motion from commit (unavailable).|2.5.19
[motion2.git] / server / api / chatInteraction / chatInteraction.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 _0x5979=['code','ChatInteraction,\x20%s,\x20%s','message','result','catch','UpdateChatInteraction','update','body','options','limit','ChatInteraction','then','ids','omit','AddTags','util','moment','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','redis','defaults','localhost','socket.io-emitter','./chatInteraction.socket','register','info','request\x20sent','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','stringify','error'];(function(_0x32c998,_0x349653){var _0x21f02e=function(_0x2611fd){while(--_0x2611fd){_0x32c998['push'](_0x32c998['shift']());}};_0x21f02e(++_0x349653);}(_0x5979,0x120));var _0x9597=function(_0x3173fe,_0x258e34){_0x3173fe=_0x3173fe-0x0;var _0xfb8671=_0x5979[_0x3173fe];return _0xfb8671;};'use strict';var _=require('lodash');var util=require(_0x9597('0x0'));var moment=require(_0x9597('0x1'));var BPromise=require('bluebird');var rs=require(_0x9597('0x2'));var fs=require('fs');var Redis=require(_0x9597('0x3'));var db=require(_0x9597('0x4'))['db'];var utils=require(_0x9597('0x5'));var logger=require(_0x9597('0x6'))(_0x9597('0x7'));var config=require(_0x9597('0x8'));var jayson=require(_0x9597('0x9'));var client=jayson[_0x9597('0xa')][_0x9597('0xb')]({'port':0x232a});config[_0x9597('0xc')]=_[_0x9597('0xd')](config[_0x9597('0xc')],{'host':_0x9597('0xe'),'port':0x18eb});var socket=require(_0x9597('0xf'))(new Redis(config[_0x9597('0xc')]));require(_0x9597('0x10'))[_0x9597('0x11')](socket);function respondWithRpcPromise(_0x3f2b37,_0x3f400,_0x3aa23a){return new BPromise(function(_0x5d8b63,_0x5d5058){return client['request'](_0x3f2b37,_0x3aa23a)['then'](function(_0x4f45b7){logger[_0x9597('0x12')]('ChatInteraction,\x20%s,\x20%s',_0x3f400,_0x9597('0x13'));logger[_0x9597('0x14')](_0x9597('0x15'),_0x3f400,_0x9597('0x13'),JSON[_0x9597('0x16')](_0x4f45b7));if(_0x4f45b7['error']){if(_0x4f45b7[_0x9597('0x17')][_0x9597('0x18')]===0x1f4){logger['error'](_0x9597('0x19'),_0x3f400,_0x4f45b7[_0x9597('0x17')]['message']);return _0x5d5058(_0x4f45b7['error'][_0x9597('0x1a')]);}logger['error'](_0x9597('0x19'),_0x3f400,_0x4f45b7[_0x9597('0x17')][_0x9597('0x1a')]);return _0x5d8b63(_0x4f45b7[_0x9597('0x17')][_0x9597('0x1a')]);}else{logger[_0x9597('0x12')](_0x9597('0x19'),_0x3f400,'request\x20sent');_0x5d8b63(_0x4f45b7[_0x9597('0x1b')][_0x9597('0x1a')]);}})[_0x9597('0x1c')](function(_0x3e715a){logger[_0x9597('0x17')](_0x9597('0x19'),_0x3f400,_0x3e715a);_0x5d5058(_0x3e715a);});});}exports[_0x9597('0x1d')]=function(_0x4240eb){var _0x53a788=this;return new Promise(function(_0x4fdc23,_0x1530d6){return db['ChatInteraction'][_0x9597('0x1e')](_0x4240eb[_0x9597('0x1f')],{'raw':_0x4240eb[_0x9597('0x20')]?_0x4240eb[_0x9597('0x20')]['raw']===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x4240eb[_0x9597('0x20')]?_0x4240eb[_0x9597('0x20')]['where']||null:null,'attributes':_0x4240eb['options']?_0x4240eb[_0x9597('0x20')]['attributes']||null:null,'limit':_0x4240eb[_0x9597('0x20')]?_0x4240eb['options'][_0x9597('0x21')]||null:null})['then'](function(_0x4420b6){logger['info'](_0x9597('0x1d'),_0x4240eb);logger['debug'](_0x9597('0x1d'),_0x4240eb,JSON[_0x9597('0x16')](_0x4420b6));_0x4fdc23(_0x4420b6);})['catch'](function(_0x1b093d){logger[_0x9597('0x17')]('UpdateChatInteraction',_0x1b093d['message'],_0x4240eb);_0x1530d6(_0x53a788['error'](0x1f4,_0x1b093d['message']));});});};exports['AddTagsToChatInteraction']=function(_0x3e6684){return new Promise(function(_0x5990b3,_0x48942f){return db[_0x9597('0x22')]['find']({'where':_0x3e6684[_0x9597('0x20')]?_0x3e6684[_0x9597('0x20')]['where']||null:null})[_0x9597('0x23')](function(_0x572e7c){if(_0x572e7c){return _0x572e7c['addTags'](_0x3e6684[_0x9597('0x1f')][_0x9597('0x24')],_[_0x9597('0x25')](_0x3e6684[_0x9597('0x1f')],[_0x9597('0x24'),'id'])||{});}})['spread'](function(_0x438bd9){logger[_0x9597('0x12')]('AddTags',_0x3e6684);logger[_0x9597('0x14')](_0x9597('0x26'),_0x3e6684,JSON[_0x9597('0x16')](_0x438bd9));_0x5990b3(_0x438bd9);})[_0x9597('0x1c')](function(_0x4b9823){logger[_0x9597('0x17')](_0x9597('0x26'),_0x4b9823[_0x9597('0x1a')],_0x3e6684);_0x48942f(_this['error'](0x1f4,_0x4b9823[_0x9597('0x1a')]));});});};