Built motion from commit 0900f080.|2.5.45
[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 _0xffd8=['limit','then','catch','find','addTags','ids','omit','spread','AddTags','util','moment','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','defaults','redis','./smsInteraction.socket','request','info','SmsInteraction,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','result','UpdateSmsInteraction','SmsInteraction','update','body','options','raw','where','attributes'];(function(_0x44ca6e,_0x5e2c91){var _0x2edab2=function(_0x3afa91){while(--_0x3afa91){_0x44ca6e['push'](_0x44ca6e['shift']());}};_0x2edab2(++_0x5e2c91);}(_0xffd8,0xf9));var _0x8ffd=function(_0x3cbe85,_0x4c3091){_0x3cbe85=_0x3cbe85-0x0;var _0x396936=_0xffd8[_0x3cbe85];return _0x396936;};'use strict';var _=require('lodash');var util=require(_0x8ffd('0x0'));var moment=require(_0x8ffd('0x1'));var BPromise=require('bluebird');var rs=require(_0x8ffd('0x2'));var fs=require('fs');var Redis=require(_0x8ffd('0x3'));var db=require(_0x8ffd('0x4'))['db'];var utils=require(_0x8ffd('0x5'));var logger=require(_0x8ffd('0x6'))(_0x8ffd('0x7'));var config=require(_0x8ffd('0x8'));var jayson=require(_0x8ffd('0x9'));var client=jayson['client']['http']({'port':0x232a});config['redis']=_[_0x8ffd('0xa')](config[_0x8ffd('0xb')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x8ffd('0xb')]));require(_0x8ffd('0xc'))['register'](socket);function respondWithRpcPromise(_0x39afbe,_0x223538,_0x585cbc){return new BPromise(function(_0x3d86ce,_0x5a1d90){return client[_0x8ffd('0xd')](_0x39afbe,_0x585cbc)['then'](function(_0x3f418f){logger[_0x8ffd('0xe')](_0x8ffd('0xf'),_0x223538,_0x8ffd('0x10'));logger[_0x8ffd('0x11')]('SmsInteraction,\x20%s,\x20%s,\x20%s',_0x223538,_0x8ffd('0x10'),JSON[_0x8ffd('0x12')](_0x3f418f));if(_0x3f418f[_0x8ffd('0x13')]){if(_0x3f418f['error'][_0x8ffd('0x14')]===0x1f4){logger[_0x8ffd('0x13')](_0x8ffd('0xf'),_0x223538,_0x3f418f[_0x8ffd('0x13')]['message']);return _0x5a1d90(_0x3f418f[_0x8ffd('0x13')][_0x8ffd('0x15')]);}logger[_0x8ffd('0x13')]('SmsInteraction,\x20%s,\x20%s',_0x223538,_0x3f418f[_0x8ffd('0x13')][_0x8ffd('0x15')]);return _0x3d86ce(_0x3f418f['error'][_0x8ffd('0x15')]);}else{logger[_0x8ffd('0xe')](_0x8ffd('0xf'),_0x223538,'request\x20sent');_0x3d86ce(_0x3f418f[_0x8ffd('0x16')][_0x8ffd('0x15')]);}})['catch'](function(_0x3e7856){logger[_0x8ffd('0x13')](_0x8ffd('0xf'),_0x223538,_0x3e7856);_0x5a1d90(_0x3e7856);});});}exports[_0x8ffd('0x17')]=function(_0x5ef1cc){var _0x536b8d=this;return new Promise(function(_0x51c942,_0x2f72e6){return db[_0x8ffd('0x18')][_0x8ffd('0x19')](_0x5ef1cc[_0x8ffd('0x1a')],{'raw':_0x5ef1cc[_0x8ffd('0x1b')]?_0x5ef1cc[_0x8ffd('0x1b')][_0x8ffd('0x1c')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x5ef1cc[_0x8ffd('0x1b')]?_0x5ef1cc[_0x8ffd('0x1b')][_0x8ffd('0x1d')]||null:null,'attributes':_0x5ef1cc[_0x8ffd('0x1b')]?_0x5ef1cc['options'][_0x8ffd('0x1e')]||null:null,'limit':_0x5ef1cc[_0x8ffd('0x1b')]?_0x5ef1cc['options'][_0x8ffd('0x1f')]||null:null})[_0x8ffd('0x20')](function(_0x5abbed){logger[_0x8ffd('0xe')](_0x8ffd('0x17'),_0x5ef1cc);logger[_0x8ffd('0x11')](_0x8ffd('0x17'),_0x5ef1cc,JSON[_0x8ffd('0x12')](_0x5abbed));_0x51c942(_0x5abbed);})[_0x8ffd('0x21')](function(_0x5497c5){logger['error']('UpdateSmsInteraction',_0x5497c5[_0x8ffd('0x15')],_0x5ef1cc);_0x2f72e6(_0x536b8d[_0x8ffd('0x13')](0x1f4,_0x5497c5['message']));});});};exports['AddTagsToSmsInteraction']=function(_0x261aac){return new Promise(function(_0x5958d0,_0x2e9df4){return db['SmsInteraction'][_0x8ffd('0x22')]({'where':_0x261aac[_0x8ffd('0x1b')]?_0x261aac[_0x8ffd('0x1b')]['where']||null:null})[_0x8ffd('0x20')](function(_0x58555e){if(_0x58555e){return _0x58555e[_0x8ffd('0x23')](_0x261aac[_0x8ffd('0x1a')][_0x8ffd('0x24')],_[_0x8ffd('0x25')](_0x261aac[_0x8ffd('0x1a')],[_0x8ffd('0x24'),'id'])||{});}})[_0x8ffd('0x26')](function(_0x350405){logger[_0x8ffd('0xe')](_0x8ffd('0x27'),_0x261aac);logger[_0x8ffd('0x11')](_0x8ffd('0x27'),_0x261aac,JSON[_0x8ffd('0x12')](_0x350405));_0x5958d0(_0x350405);})[_0x8ffd('0x21')](function(_0x30410e){logger[_0x8ffd('0x13')](_0x8ffd('0x27'),_0x30410e['message'],_0x261aac);_0x2e9df4(_this['error'](0x1f4,_0x30410e[_0x8ffd('0x15')]));});});};