c518f5b53fd11e8797000636e344b2a0b226c44f
[motion2.git] / server / api / smsInteraction / smsInteraction.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 _0x95f7=['ioredis','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','http','redis','defaults','localhost','socket.io-emitter','then','info','SmsInteraction,\x20%s,\x20%s','SmsInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','update','body','options','raw','where','attributes','limit','UpdateSmsInteraction','debug','AddTagsToSmsInteraction','find','ids','omit','spread','AddTags','lodash','moment','randomstring'];(function(_0x36936b,_0x47abad){var _0x5ebf66=function(_0x1c35da){while(--_0x1c35da){_0x36936b['push'](_0x36936b['shift']());}};_0x5ebf66(++_0x47abad);}(_0x95f7,0x6f));var _0x795f=function(_0x15f108,_0x57487c){_0x15f108=_0x15f108-0x0;var _0x13361e=_0x95f7[_0x15f108];return _0x13361e;};'use strict';var _=require(_0x795f('0x0'));var util=require('util');var moment=require(_0x795f('0x1'));var BPromise=require('bluebird');var rs=require(_0x795f('0x2'));var fs=require('fs');var Redis=require(_0x795f('0x3'));var db=require('../../mysqldb')['db'];var utils=require(_0x795f('0x4'));var logger=require(_0x795f('0x5'))('rpc');var config=require(_0x795f('0x6'));var jayson=require(_0x795f('0x7'));var client=jayson[_0x795f('0x8')][_0x795f('0x9')]({'port':0x232a});config[_0x795f('0xa')]=_[_0x795f('0xb')](config['redis'],{'host':_0x795f('0xc'),'port':0x18eb});var socket=require(_0x795f('0xd'))(new Redis(config[_0x795f('0xa')]));require('./smsInteraction.socket')['register'](socket);function respondWithRpcPromise(_0x239f4b,_0x592b34,_0x2109c1){return new BPromise(function(_0x2f340e,_0x209517){return client['request'](_0x239f4b,_0x2109c1)[_0x795f('0xe')](function(_0x374d44){logger[_0x795f('0xf')](_0x795f('0x10'),_0x592b34,'request\x20sent');logger['debug'](_0x795f('0x11'),_0x592b34,'request\x20sent',JSON[_0x795f('0x12')](_0x374d44));if(_0x374d44[_0x795f('0x13')]){if(_0x374d44[_0x795f('0x13')][_0x795f('0x14')]===0x1f4){logger[_0x795f('0x13')](_0x795f('0x10'),_0x592b34,_0x374d44[_0x795f('0x13')][_0x795f('0x15')]);return _0x209517(_0x374d44[_0x795f('0x13')]['message']);}logger[_0x795f('0x13')](_0x795f('0x10'),_0x592b34,_0x374d44[_0x795f('0x13')][_0x795f('0x15')]);return _0x2f340e(_0x374d44['error']['message']);}else{logger[_0x795f('0xf')](_0x795f('0x10'),_0x592b34,'request\x20sent');_0x2f340e(_0x374d44['result'][_0x795f('0x15')]);}})[_0x795f('0x16')](function(_0x49ed63){logger[_0x795f('0x13')](_0x795f('0x10'),_0x592b34,_0x49ed63);_0x209517(_0x49ed63);});});}exports['UpdateSmsInteraction']=function(_0x43c778){var _0x5edb3a=this;return new Promise(function(_0x3fbddd,_0x42c297){return db['SmsInteraction'][_0x795f('0x17')](_0x43c778[_0x795f('0x18')],{'raw':_0x43c778['options']?_0x43c778[_0x795f('0x19')][_0x795f('0x1a')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x43c778[_0x795f('0x19')]?_0x43c778[_0x795f('0x19')][_0x795f('0x1b')]||null:null,'attributes':_0x43c778[_0x795f('0x19')]?_0x43c778['options'][_0x795f('0x1c')]||null:null,'limit':_0x43c778['options']?_0x43c778['options'][_0x795f('0x1d')]||null:null})['then'](function(_0x381b20){logger[_0x795f('0xf')](_0x795f('0x1e'),_0x43c778);logger[_0x795f('0x1f')]('UpdateSmsInteraction',_0x43c778,JSON[_0x795f('0x12')](_0x381b20));_0x3fbddd(_0x381b20);})['catch'](function(_0x30a89d){logger[_0x795f('0x13')](_0x795f('0x1e'),_0x30a89d[_0x795f('0x15')],_0x43c778);_0x42c297(_0x5edb3a[_0x795f('0x13')](0x1f4,_0x30a89d[_0x795f('0x15')]));});});};exports[_0x795f('0x20')]=function(_0x2b4055){return new Promise(function(_0x25f457,_0x3fca8e){return db['SmsInteraction'][_0x795f('0x21')]({'where':_0x2b4055['options']?_0x2b4055['options']['where']||null:null})[_0x795f('0xe')](function(_0x1300d2){if(_0x1300d2){return _0x1300d2['addTags'](_0x2b4055[_0x795f('0x18')][_0x795f('0x22')],_[_0x795f('0x23')](_0x2b4055[_0x795f('0x18')],[_0x795f('0x22'),'id'])||{});}})[_0x795f('0x24')](function(_0x417ef5){logger[_0x795f('0xf')]('AddTags',_0x2b4055);logger['debug'](_0x795f('0x25'),_0x2b4055,JSON[_0x795f('0x12')](_0x417ef5));_0x25f457(_0x417ef5);})[_0x795f('0x16')](function(_0x343fc2){logger[_0x795f('0x13')](_0x795f('0x25'),_0x343fc2[_0x795f('0x15')],_0x2b4055);_0x3fca8e(_this['error'](0x1f4,_0x343fc2[_0x795f('0x15')]));});});};