Built motion from commit e781dc3c.|2.5.42
[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 _0x4fb8=['moment','randomstring','../../config/logger','rpc','../../config/environment','jayson/promise','redis','defaults','localhost','socket.io-emitter','./smsInteraction.socket','register','request','then','info','SmsInteraction,\x20%s,\x20%s','request\x20sent','debug','SmsInteraction,\x20%s,\x20%s,\x20%s','error','code','message','catch','UpdateSmsInteraction','SmsInteraction','body','options','raw','limit','stringify','AddTagsToSmsInteraction','ids','omit','spread','AddTags'];(function(_0x1d171c,_0x52384d){var _0x2da1a5=function(_0x256713){while(--_0x256713){_0x1d171c['push'](_0x1d171c['shift']());}};_0x2da1a5(++_0x52384d);}(_0x4fb8,0x69));var _0x84fb=function(_0x4f4c94,_0x3131ce){_0x4f4c94=_0x4f4c94-0x0;var _0x479b75=_0x4fb8[_0x4f4c94];return _0x479b75;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0x84fb('0x0'));var BPromise=require('bluebird');var rs=require(_0x84fb('0x1'));var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require(_0x84fb('0x2'))(_0x84fb('0x3'));var config=require(_0x84fb('0x4'));var jayson=require(_0x84fb('0x5'));var client=jayson['client']['http']({'port':0x232a});config[_0x84fb('0x6')]=_[_0x84fb('0x7')](config['redis'],{'host':_0x84fb('0x8'),'port':0x18eb});var socket=require(_0x84fb('0x9'))(new Redis(config[_0x84fb('0x6')]));require(_0x84fb('0xa'))[_0x84fb('0xb')](socket);function respondWithRpcPromise(_0x210c21,_0x23e6f5,_0x3e220b){return new BPromise(function(_0x3bf064,_0x30ff3f){return client[_0x84fb('0xc')](_0x210c21,_0x3e220b)[_0x84fb('0xd')](function(_0x1f5998){logger[_0x84fb('0xe')](_0x84fb('0xf'),_0x23e6f5,_0x84fb('0x10'));logger[_0x84fb('0x11')](_0x84fb('0x12'),_0x23e6f5,_0x84fb('0x10'),JSON['stringify'](_0x1f5998));if(_0x1f5998[_0x84fb('0x13')]){if(_0x1f5998[_0x84fb('0x13')][_0x84fb('0x14')]===0x1f4){logger['error']('SmsInteraction,\x20%s,\x20%s',_0x23e6f5,_0x1f5998['error'][_0x84fb('0x15')]);return _0x30ff3f(_0x1f5998[_0x84fb('0x13')][_0x84fb('0x15')]);}logger['error'](_0x84fb('0xf'),_0x23e6f5,_0x1f5998[_0x84fb('0x13')][_0x84fb('0x15')]);return _0x3bf064(_0x1f5998[_0x84fb('0x13')]['message']);}else{logger['info'](_0x84fb('0xf'),_0x23e6f5,_0x84fb('0x10'));_0x3bf064(_0x1f5998['result'][_0x84fb('0x15')]);}})[_0x84fb('0x16')](function(_0x5b69a5){logger[_0x84fb('0x13')](_0x84fb('0xf'),_0x23e6f5,_0x5b69a5);_0x30ff3f(_0x5b69a5);});});}exports[_0x84fb('0x17')]=function(_0x1af3df){var _0x5175bc=this;return new Promise(function(_0x22f35a,_0x5c76d7){return db[_0x84fb('0x18')]['update'](_0x1af3df[_0x84fb('0x19')],{'raw':_0x1af3df['options']?_0x1af3df[_0x84fb('0x1a')][_0x84fb('0x1b')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x1af3df['options']?_0x1af3df[_0x84fb('0x1a')]['where']||null:null,'attributes':_0x1af3df['options']?_0x1af3df[_0x84fb('0x1a')]['attributes']||null:null,'limit':_0x1af3df[_0x84fb('0x1a')]?_0x1af3df['options'][_0x84fb('0x1c')]||null:null})['then'](function(_0x3decb5){logger[_0x84fb('0xe')](_0x84fb('0x17'),_0x1af3df);logger[_0x84fb('0x11')](_0x84fb('0x17'),_0x1af3df,JSON[_0x84fb('0x1d')](_0x3decb5));_0x22f35a(_0x3decb5);})['catch'](function(_0x5955d9){logger[_0x84fb('0x13')](_0x84fb('0x17'),_0x5955d9[_0x84fb('0x15')],_0x1af3df);_0x5c76d7(_0x5175bc[_0x84fb('0x13')](0x1f4,_0x5955d9['message']));});});};exports[_0x84fb('0x1e')]=function(_0x4684f5){return new Promise(function(_0x446d73,_0x578919){return db[_0x84fb('0x18')]['find']({'where':_0x4684f5[_0x84fb('0x1a')]?_0x4684f5[_0x84fb('0x1a')]['where']||null:null})[_0x84fb('0xd')](function(_0x29e5f4){if(_0x29e5f4){return _0x29e5f4['addTags'](_0x4684f5['body'][_0x84fb('0x1f')],_[_0x84fb('0x20')](_0x4684f5[_0x84fb('0x19')],[_0x84fb('0x1f'),'id'])||{});}})[_0x84fb('0x21')](function(_0x7eda53){logger['info']('AddTags',_0x4684f5);logger['debug']('AddTags',_0x4684f5,JSON[_0x84fb('0x1d')](_0x7eda53));_0x446d73(_0x7eda53);})['catch'](function(_0x43687b){logger[_0x84fb('0x13')](_0x84fb('0x22'),_0x43687b[_0x84fb('0x15')],_0x4684f5);_0x578919(_this[_0x84fb('0x13')](0x1f4,_0x43687b[_0x84fb('0x15')]));});});};