d48da51700085f13ea45ce38690356d09657a346
[motion2.git] / server / api / openchannelInteraction / openchannelInteraction.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 _0x7905=['update','body','options','raw','then','debug','stringify','AddTagsToOpenchannelInteraction','find','where','ids','omit','AddTags','util','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','jayson/promise','client','http','redis','defaults','localhost','socket.io-emitter','./openchannelInteraction.socket','register','info','request\x20sent','OpenchannelInteraction,\x20%s,\x20%s,\x20%s','error','OpenchannelInteraction,\x20%s,\x20%s','message','catch','UpdateOpenchannelInteraction'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x7905,0xf1));var _0x5790=function(_0x2df8fa,_0x3c7dcd){_0x2df8fa=_0x2df8fa-0x0;var _0x3c8c45=_0x7905[_0x2df8fa];return _0x3c8c45;};'use strict';var _=require('lodash');var util=require(_0x5790('0x0'));var moment=require('moment');var BPromise=require(_0x5790('0x1'));var rs=require(_0x5790('0x2'));var fs=require('fs');var Redis=require(_0x5790('0x3'));var db=require(_0x5790('0x4'))['db'];var utils=require(_0x5790('0x5'));var logger=require(_0x5790('0x6'))(_0x5790('0x7'));var config=require('../../config/environment');var jayson=require(_0x5790('0x8'));var client=jayson[_0x5790('0x9')][_0x5790('0xa')]({'port':0x232a});config[_0x5790('0xb')]=_[_0x5790('0xc')](config[_0x5790('0xb')],{'host':_0x5790('0xd'),'port':0x18eb});var socket=require(_0x5790('0xe'))(new Redis(config[_0x5790('0xb')]));require(_0x5790('0xf'))[_0x5790('0x10')](socket);function respondWithRpcPromise(_0x517626,_0x123052,_0x54edbf){return new BPromise(function(_0x5efc79,_0x155acc){return client['request'](_0x517626,_0x54edbf)['then'](function(_0x298ea9){logger[_0x5790('0x11')]('OpenchannelInteraction,\x20%s,\x20%s',_0x123052,_0x5790('0x12'));logger['debug'](_0x5790('0x13'),_0x123052,_0x5790('0x12'),JSON['stringify'](_0x298ea9));if(_0x298ea9[_0x5790('0x14')]){if(_0x298ea9[_0x5790('0x14')]['code']===0x1f4){logger[_0x5790('0x14')](_0x5790('0x15'),_0x123052,_0x298ea9[_0x5790('0x14')][_0x5790('0x16')]);return _0x155acc(_0x298ea9[_0x5790('0x14')][_0x5790('0x16')]);}logger[_0x5790('0x14')](_0x5790('0x15'),_0x123052,_0x298ea9[_0x5790('0x14')]['message']);return _0x5efc79(_0x298ea9[_0x5790('0x14')][_0x5790('0x16')]);}else{logger[_0x5790('0x11')](_0x5790('0x15'),_0x123052,_0x5790('0x12'));_0x5efc79(_0x298ea9['result'][_0x5790('0x16')]);}})[_0x5790('0x17')](function(_0x2e1353){logger['error'](_0x5790('0x15'),_0x123052,_0x2e1353);_0x155acc(_0x2e1353);});});}exports[_0x5790('0x18')]=function(_0xac6ff){var _0x409fb2=this;return new Promise(function(_0x46bda0,_0x59dfb3){return db['OpenchannelInteraction'][_0x5790('0x19')](_0xac6ff[_0x5790('0x1a')],{'raw':_0xac6ff['options']?_0xac6ff[_0x5790('0x1b')][_0x5790('0x1c')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0xac6ff[_0x5790('0x1b')]?_0xac6ff[_0x5790('0x1b')]['where']||null:null,'attributes':_0xac6ff[_0x5790('0x1b')]?_0xac6ff['options']['attributes']||null:null,'limit':_0xac6ff[_0x5790('0x1b')]?_0xac6ff[_0x5790('0x1b')]['limit']||null:null})[_0x5790('0x1d')](function(_0x13eda9){logger[_0x5790('0x11')]('UpdateOpenchannelInteraction',_0xac6ff);logger[_0x5790('0x1e')](_0x5790('0x18'),_0xac6ff,JSON[_0x5790('0x1f')](_0x13eda9));_0x46bda0(_0x13eda9);})[_0x5790('0x17')](function(_0x1dda3a){logger[_0x5790('0x14')](_0x5790('0x18'),_0x1dda3a[_0x5790('0x16')],_0xac6ff);_0x59dfb3(_0x409fb2[_0x5790('0x14')](0x1f4,_0x1dda3a[_0x5790('0x16')]));});});};exports[_0x5790('0x20')]=function(_0x3e1bc1){return new Promise(function(_0x12ee11,_0x1f2edd){return db['OpenchannelInteraction'][_0x5790('0x21')]({'where':_0x3e1bc1[_0x5790('0x1b')]?_0x3e1bc1['options'][_0x5790('0x22')]||null:null})[_0x5790('0x1d')](function(_0x4c7184){if(_0x4c7184){return _0x4c7184['addTags'](_0x3e1bc1[_0x5790('0x1a')][_0x5790('0x23')],_[_0x5790('0x24')](_0x3e1bc1['body'],[_0x5790('0x23'),'id'])||{});}})['spread'](function(_0x4d6293){logger[_0x5790('0x11')]('AddTags',_0x3e1bc1);logger['debug'](_0x5790('0x25'),_0x3e1bc1,JSON[_0x5790('0x1f')](_0x4d6293));_0x12ee11(_0x4d6293);})[_0x5790('0x17')](function(_0x30c1c4){logger[_0x5790('0x14')]('AddTags',_0x30c1c4[_0x5790('0x16')],_0x3e1bc1);_0x1f2edd(_this[_0x5790('0x14')](0x1f4,_0x30c1c4['message']));});});};