a9a8464e508fd8292eb97085160fbfdda5a1a184
[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 _0x7739=['AddTags','lodash','util','moment','randomstring','ioredis','../../config/utils','rpc','jayson/promise','defaults','redis','localhost','socket.io-emitter','request','then','info','ChatInteraction,\x20%s,\x20%s','request\x20sent','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','stringify','code','error','message','UpdateChatInteraction','update','options','raw','attributes','limit','AddTagsToChatInteraction','ChatInteraction','find','where','addTags','body','ids','omit','spread'];(function(_0x36cec5,_0x11477e){var _0x328186=function(_0x5bca9d){while(--_0x5bca9d){_0x36cec5['push'](_0x36cec5['shift']());}};_0x328186(++_0x11477e);}(_0x7739,0xeb));var _0x9773=function(_0x218ee2,_0x44b8e8){_0x218ee2=_0x218ee2-0x0;var _0x5b74a6=_0x7739[_0x218ee2];return _0x5b74a6;};'use strict';var _=require(_0x9773('0x0'));var util=require(_0x9773('0x1'));var moment=require(_0x9773('0x2'));var BPromise=require('bluebird');var rs=require(_0x9773('0x3'));var fs=require('fs');var Redis=require(_0x9773('0x4'));var db=require('../../mysqldb')['db'];var utils=require(_0x9773('0x5'));var logger=require('../../config/logger')(_0x9773('0x6'));var config=require('../../config/environment');var jayson=require(_0x9773('0x7'));var client=jayson['client']['http']({'port':0x232a});config['redis']=_[_0x9773('0x8')](config[_0x9773('0x9')],{'host':_0x9773('0xa'),'port':0x18eb});var socket=require(_0x9773('0xb'))(new Redis(config[_0x9773('0x9')]));require('./chatInteraction.socket')['register'](socket);function respondWithRpcPromise(_0x14d4cc,_0xa1cba5,_0x88f214){return new BPromise(function(_0x12957e,_0x2eb139){return client[_0x9773('0xc')](_0x14d4cc,_0x88f214)[_0x9773('0xd')](function(_0x3db0dc){logger[_0x9773('0xe')](_0x9773('0xf'),_0xa1cba5,_0x9773('0x10'));logger[_0x9773('0x11')](_0x9773('0x12'),_0xa1cba5,_0x9773('0x10'),JSON[_0x9773('0x13')](_0x3db0dc));if(_0x3db0dc['error']){if(_0x3db0dc['error'][_0x9773('0x14')]===0x1f4){logger[_0x9773('0x15')](_0x9773('0xf'),_0xa1cba5,_0x3db0dc[_0x9773('0x15')][_0x9773('0x16')]);return _0x2eb139(_0x3db0dc[_0x9773('0x15')][_0x9773('0x16')]);}logger[_0x9773('0x15')](_0x9773('0xf'),_0xa1cba5,_0x3db0dc[_0x9773('0x15')]['message']);return _0x12957e(_0x3db0dc[_0x9773('0x15')]['message']);}else{logger[_0x9773('0xe')](_0x9773('0xf'),_0xa1cba5,_0x9773('0x10'));_0x12957e(_0x3db0dc['result']['message']);}})['catch'](function(_0x2f6012){logger[_0x9773('0x15')]('ChatInteraction,\x20%s,\x20%s',_0xa1cba5,_0x2f6012);_0x2eb139(_0x2f6012);});});}exports[_0x9773('0x17')]=function(_0x177e9a){var _0x1b8bc7=this;return new Promise(function(_0x44e259,_0x4e12ce){return db['ChatInteraction'][_0x9773('0x18')](_0x177e9a['body'],{'raw':_0x177e9a[_0x9773('0x19')]?_0x177e9a[_0x9773('0x19')][_0x9773('0x1a')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x177e9a[_0x9773('0x19')]?_0x177e9a['options']['where']||null:null,'attributes':_0x177e9a[_0x9773('0x19')]?_0x177e9a[_0x9773('0x19')][_0x9773('0x1b')]||null:null,'limit':_0x177e9a[_0x9773('0x19')]?_0x177e9a[_0x9773('0x19')][_0x9773('0x1c')]||null:null})[_0x9773('0xd')](function(_0x4eff96){logger[_0x9773('0xe')](_0x9773('0x17'),_0x177e9a);logger[_0x9773('0x11')](_0x9773('0x17'),_0x177e9a,JSON[_0x9773('0x13')](_0x4eff96));_0x44e259(_0x4eff96);})['catch'](function(_0x8a2758){logger['error'](_0x9773('0x17'),_0x8a2758['message'],_0x177e9a);_0x4e12ce(_0x1b8bc7[_0x9773('0x15')](0x1f4,_0x8a2758['message']));});});};exports[_0x9773('0x1d')]=function(_0x247bbc){return new Promise(function(_0x3286db,_0x291113){return db[_0x9773('0x1e')][_0x9773('0x1f')]({'where':_0x247bbc[_0x9773('0x19')]?_0x247bbc[_0x9773('0x19')][_0x9773('0x20')]||null:null})[_0x9773('0xd')](function(_0x524416){if(_0x524416){return _0x524416[_0x9773('0x21')](_0x247bbc[_0x9773('0x22')][_0x9773('0x23')],_[_0x9773('0x24')](_0x247bbc['body'],['ids','id'])||{});}})[_0x9773('0x25')](function(_0x59a381){logger[_0x9773('0xe')](_0x9773('0x26'),_0x247bbc);logger[_0x9773('0x11')](_0x9773('0x26'),_0x247bbc,JSON[_0x9773('0x13')](_0x59a381));_0x3286db(_0x59a381);})['catch'](function(_0x28b427){logger[_0x9773('0x15')]('AddTags',_0x28b427['message'],_0x247bbc);_0x291113(_this[_0x9773('0x15')](0x1f4,_0x28b427['message']));});});};