733ddeb343769c1b08546ec021d7dbd17b0b43e3
[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 _0x6885=['stringify','error','code','message','result','catch','UpdateChatInteraction','update','body','options','raw','attributes','limit','AddTagsToChatInteraction','ChatInteraction','where','addTags','ids','omit','AddTags','lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','client','redis','localhost','socket.io-emitter','./chatInteraction.socket','register','request','then','info','ChatInteraction,\x20%s,\x20%s','request\x20sent','debug','ChatInteraction,\x20%s,\x20%s,\x20%s'];(function(_0x5a6db4,_0x3c2cd4){var _0x50b8d9=function(_0x3c1faa){while(--_0x3c1faa){_0x5a6db4['push'](_0x5a6db4['shift']());}};_0x50b8d9(++_0x3c2cd4);}(_0x6885,0xc4));var _0x5688=function(_0x39ee70,_0xf9ad42){_0x39ee70=_0x39ee70-0x0;var _0x5ea1f6=_0x6885[_0x39ee70];return _0x5ea1f6;};'use strict';var _=require(_0x5688('0x0'));var util=require(_0x5688('0x1'));var moment=require(_0x5688('0x2'));var BPromise=require(_0x5688('0x3'));var rs=require(_0x5688('0x4'));var fs=require('fs');var Redis=require(_0x5688('0x5'));var db=require(_0x5688('0x6'))['db'];var utils=require(_0x5688('0x7'));var logger=require(_0x5688('0x8'))(_0x5688('0x9'));var config=require(_0x5688('0xa'));var jayson=require('jayson/promise');var client=jayson[_0x5688('0xb')]['http']({'port':0x232a});config['redis']=_['defaults'](config[_0x5688('0xc')],{'host':_0x5688('0xd'),'port':0x18eb});var socket=require(_0x5688('0xe'))(new Redis(config[_0x5688('0xc')]));require(_0x5688('0xf'))[_0x5688('0x10')](socket);function respondWithRpcPromise(_0xd7c19b,_0x2b3d34,_0xcefddf){return new BPromise(function(_0x5dfd7f,_0x121968){return client[_0x5688('0x11')](_0xd7c19b,_0xcefddf)[_0x5688('0x12')](function(_0x1e801e){logger[_0x5688('0x13')](_0x5688('0x14'),_0x2b3d34,_0x5688('0x15'));logger[_0x5688('0x16')](_0x5688('0x17'),_0x2b3d34,_0x5688('0x15'),JSON[_0x5688('0x18')](_0x1e801e));if(_0x1e801e[_0x5688('0x19')]){if(_0x1e801e['error'][_0x5688('0x1a')]===0x1f4){logger['error'](_0x5688('0x14'),_0x2b3d34,_0x1e801e[_0x5688('0x19')][_0x5688('0x1b')]);return _0x121968(_0x1e801e[_0x5688('0x19')][_0x5688('0x1b')]);}logger['error']('ChatInteraction,\x20%s,\x20%s',_0x2b3d34,_0x1e801e[_0x5688('0x19')][_0x5688('0x1b')]);return _0x5dfd7f(_0x1e801e[_0x5688('0x19')][_0x5688('0x1b')]);}else{logger[_0x5688('0x13')](_0x5688('0x14'),_0x2b3d34,_0x5688('0x15'));_0x5dfd7f(_0x1e801e[_0x5688('0x1c')][_0x5688('0x1b')]);}})[_0x5688('0x1d')](function(_0x48e768){logger[_0x5688('0x19')](_0x5688('0x14'),_0x2b3d34,_0x48e768);_0x121968(_0x48e768);});});}exports[_0x5688('0x1e')]=function(_0x42231d){var _0x5a2e1c=this;return new Promise(function(_0x25a718,_0x2dbc8d){return db['ChatInteraction'][_0x5688('0x1f')](_0x42231d[_0x5688('0x20')],{'raw':_0x42231d[_0x5688('0x21')]?_0x42231d[_0x5688('0x21')][_0x5688('0x22')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x42231d['options']?_0x42231d['options']['where']||null:null,'attributes':_0x42231d['options']?_0x42231d[_0x5688('0x21')][_0x5688('0x23')]||null:null,'limit':_0x42231d[_0x5688('0x21')]?_0x42231d[_0x5688('0x21')][_0x5688('0x24')]||null:null})[_0x5688('0x12')](function(_0x17785c){logger['info']('UpdateChatInteraction',_0x42231d);logger[_0x5688('0x16')]('UpdateChatInteraction',_0x42231d,JSON[_0x5688('0x18')](_0x17785c));_0x25a718(_0x17785c);})[_0x5688('0x1d')](function(_0x5db433){logger['error'](_0x5688('0x1e'),_0x5db433['message'],_0x42231d);_0x2dbc8d(_0x5a2e1c[_0x5688('0x19')](0x1f4,_0x5db433[_0x5688('0x1b')]));});});};exports[_0x5688('0x25')]=function(_0x461d5d){return new Promise(function(_0xc2f1a0,_0x2a6ed9){return db[_0x5688('0x26')]['find']({'where':_0x461d5d[_0x5688('0x21')]?_0x461d5d[_0x5688('0x21')][_0x5688('0x27')]||null:null})[_0x5688('0x12')](function(_0x49b3e5){if(_0x49b3e5){return _0x49b3e5[_0x5688('0x28')](_0x461d5d[_0x5688('0x20')][_0x5688('0x29')],_[_0x5688('0x2a')](_0x461d5d[_0x5688('0x20')],['ids','id'])||{});}})['spread'](function(_0xeaa469){logger[_0x5688('0x13')](_0x5688('0x2b'),_0x461d5d);logger[_0x5688('0x16')](_0x5688('0x2b'),_0x461d5d,JSON[_0x5688('0x18')](_0xeaa469));_0xc2f1a0(_0xeaa469);})[_0x5688('0x1d')](function(_0xf10275){logger[_0x5688('0x19')]('AddTags',_0xf10275[_0x5688('0x1b')],_0x461d5d);_0x2a6ed9(_this[_0x5688('0x19')](0x1f4,_0xf10275['message']));});});};