7a56c2f36ce8e7a3449e2276ed4d9b3c3c89a2f5
[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 _0x9fc2=['message','info','result','catch','UpdateChatInteraction','ChatInteraction','update','body','options','attributes','limit','AddTagsToChatInteraction','find','where','addTags','ids','omit','spread','AddTags','lodash','util','bluebird','randomstring','ioredis','../../config/utils','rpc','../../config/environment','client','http','redis','defaults','localhost','socket.io-emitter','request','then','ChatInteraction,\x20%s,\x20%s','request\x20sent','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code'];(function(_0x11579f,_0x26ab6b){var _0x56e613=function(_0x21c110){while(--_0x21c110){_0x11579f['push'](_0x11579f['shift']());}};_0x56e613(++_0x26ab6b);}(_0x9fc2,0x163));var _0x29fc=function(_0x27a444,_0x5902d4){_0x27a444=_0x27a444-0x0;var _0x370fdc=_0x9fc2[_0x27a444];return _0x370fdc;};'use strict';var _=require(_0x29fc('0x0'));var util=require(_0x29fc('0x1'));var moment=require('moment');var BPromise=require(_0x29fc('0x2'));var rs=require(_0x29fc('0x3'));var fs=require('fs');var Redis=require(_0x29fc('0x4'));var db=require('../../mysqldb')['db'];var utils=require(_0x29fc('0x5'));var logger=require('../../config/logger')(_0x29fc('0x6'));var config=require(_0x29fc('0x7'));var jayson=require('jayson/promise');var client=jayson[_0x29fc('0x8')][_0x29fc('0x9')]({'port':0x232a});config[_0x29fc('0xa')]=_[_0x29fc('0xb')](config[_0x29fc('0xa')],{'host':_0x29fc('0xc'),'port':0x18eb});var socket=require(_0x29fc('0xd'))(new Redis(config[_0x29fc('0xa')]));require('./chatInteraction.socket')['register'](socket);function respondWithRpcPromise(_0x3e4494,_0x5f4b1d,_0x31b8e7){return new BPromise(function(_0x4fccf9,_0x4171a2){return client[_0x29fc('0xe')](_0x3e4494,_0x31b8e7)[_0x29fc('0xf')](function(_0x54084b){logger['info'](_0x29fc('0x10'),_0x5f4b1d,_0x29fc('0x11'));logger[_0x29fc('0x12')](_0x29fc('0x13'),_0x5f4b1d,_0x29fc('0x11'),JSON[_0x29fc('0x14')](_0x54084b));if(_0x54084b[_0x29fc('0x15')]){if(_0x54084b['error'][_0x29fc('0x16')]===0x1f4){logger[_0x29fc('0x15')](_0x29fc('0x10'),_0x5f4b1d,_0x54084b['error']['message']);return _0x4171a2(_0x54084b['error'][_0x29fc('0x17')]);}logger[_0x29fc('0x15')](_0x29fc('0x10'),_0x5f4b1d,_0x54084b[_0x29fc('0x15')][_0x29fc('0x17')]);return _0x4fccf9(_0x54084b[_0x29fc('0x15')]['message']);}else{logger[_0x29fc('0x18')]('ChatInteraction,\x20%s,\x20%s',_0x5f4b1d,_0x29fc('0x11'));_0x4fccf9(_0x54084b[_0x29fc('0x19')][_0x29fc('0x17')]);}})[_0x29fc('0x1a')](function(_0xcd7c0d){logger['error']('ChatInteraction,\x20%s,\x20%s',_0x5f4b1d,_0xcd7c0d);_0x4171a2(_0xcd7c0d);});});}exports[_0x29fc('0x1b')]=function(_0x13eabe){var _0x25a599=this;return new Promise(function(_0x29baa0,_0x3d3da8){return db[_0x29fc('0x1c')][_0x29fc('0x1d')](_0x13eabe[_0x29fc('0x1e')],{'raw':_0x13eabe[_0x29fc('0x1f')]?_0x13eabe['options']['raw']===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x13eabe[_0x29fc('0x1f')]?_0x13eabe[_0x29fc('0x1f')]['where']||null:null,'attributes':_0x13eabe[_0x29fc('0x1f')]?_0x13eabe[_0x29fc('0x1f')][_0x29fc('0x20')]||null:null,'limit':_0x13eabe[_0x29fc('0x1f')]?_0x13eabe[_0x29fc('0x1f')][_0x29fc('0x21')]||null:null})[_0x29fc('0xf')](function(_0x32c549){logger[_0x29fc('0x18')](_0x29fc('0x1b'),_0x13eabe);logger['debug']('UpdateChatInteraction',_0x13eabe,JSON[_0x29fc('0x14')](_0x32c549));_0x29baa0(_0x32c549);})[_0x29fc('0x1a')](function(_0x311404){logger['error'](_0x29fc('0x1b'),_0x311404['message'],_0x13eabe);_0x3d3da8(_0x25a599[_0x29fc('0x15')](0x1f4,_0x311404[_0x29fc('0x17')]));});});};exports[_0x29fc('0x22')]=function(_0xbb7b27){return new Promise(function(_0x52de38,_0xa60c8d){return db['ChatInteraction'][_0x29fc('0x23')]({'where':_0xbb7b27['options']?_0xbb7b27[_0x29fc('0x1f')][_0x29fc('0x24')]||null:null})[_0x29fc('0xf')](function(_0x4994b1){if(_0x4994b1){return _0x4994b1[_0x29fc('0x25')](_0xbb7b27[_0x29fc('0x1e')][_0x29fc('0x26')],_[_0x29fc('0x27')](_0xbb7b27['body'],[_0x29fc('0x26'),'id'])||{});}})[_0x29fc('0x28')](function(_0x3c96a4){logger['info'](_0x29fc('0x29'),_0xbb7b27);logger[_0x29fc('0x12')]('AddTags',_0xbb7b27,JSON[_0x29fc('0x14')](_0x3c96a4));_0x52de38(_0x3c96a4);})[_0x29fc('0x1a')](function(_0x3e1565){logger[_0x29fc('0x15')](_0x29fc('0x29'),_0x3e1565[_0x29fc('0x17')],_0xbb7b27);_0xa60c8d(_this[_0x29fc('0x15')](0x1f4,_0x3e1565[_0x29fc('0x17')]));});});};