5a7444894f214faf3a98962cbcf9417f9e26f2f6
[motion2.git] / server / api / smsQueue / smsQueue.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 _0x6b78=['../../config/utils','rpc','../../config/environment','jayson/promise','client','http','redis','defaults','localhost','socket.io-emitter','register','then','info','request\x20sent','debug','SmsQueue,\x20%s,\x20%s,\x20%s','error','SmsQueue,\x20%s,\x20%s','message','GetSmsQueue','SmsQueue','findAll','options','raw','where','attributes','limit','include','map','model','stringify','ShowSmsQueue','find','catch','util','bluebird','randomstring','ioredis'];(function(_0x24124d,_0x26ae83){var _0x56df41=function(_0x1f1ae5){while(--_0x1f1ae5){_0x24124d['push'](_0x24124d['shift']());}};_0x56df41(++_0x26ae83);}(_0x6b78,0x1c4));var _0x86b7=function(_0x2582cf,_0x2ab52e){_0x2582cf=_0x2582cf-0x0;var _0x399106=_0x6b78[_0x2582cf];return _0x399106;};'use strict';var _=require('lodash');var util=require(_0x86b7('0x0'));var moment=require('moment');var BPromise=require(_0x86b7('0x1'));var rs=require(_0x86b7('0x2'));var fs=require('fs');var Redis=require(_0x86b7('0x3'));var db=require('../../mysqldb')['db'];var utils=require(_0x86b7('0x4'));var logger=require('../../config/logger')(_0x86b7('0x5'));var config=require(_0x86b7('0x6'));var jayson=require(_0x86b7('0x7'));var client=jayson[_0x86b7('0x8')][_0x86b7('0x9')]({'port':0x232a});config[_0x86b7('0xa')]=_[_0x86b7('0xb')](config[_0x86b7('0xa')],{'host':_0x86b7('0xc'),'port':0x18eb});var socket=require(_0x86b7('0xd'))(new Redis(config[_0x86b7('0xa')]));require('./smsQueue.socket')[_0x86b7('0xe')](socket);function respondWithRpcPromise(_0x213b0f,_0x151757,_0x3c3a74){return new BPromise(function(_0x4ea20a,_0x3f5f92){return client['request'](_0x213b0f,_0x3c3a74)[_0x86b7('0xf')](function(_0x16c1b6){logger[_0x86b7('0x10')]('SmsQueue,\x20%s,\x20%s',_0x151757,_0x86b7('0x11'));logger[_0x86b7('0x12')](_0x86b7('0x13'),_0x151757,_0x86b7('0x11'),JSON['stringify'](_0x16c1b6));if(_0x16c1b6[_0x86b7('0x14')]){if(_0x16c1b6[_0x86b7('0x14')]['code']===0x1f4){logger[_0x86b7('0x14')](_0x86b7('0x15'),_0x151757,_0x16c1b6[_0x86b7('0x14')]['message']);return _0x3f5f92(_0x16c1b6[_0x86b7('0x14')][_0x86b7('0x16')]);}logger[_0x86b7('0x14')](_0x86b7('0x15'),_0x151757,_0x16c1b6['error']['message']);return _0x4ea20a(_0x16c1b6[_0x86b7('0x14')][_0x86b7('0x16')]);}else{logger[_0x86b7('0x10')](_0x86b7('0x15'),_0x151757,_0x86b7('0x11'));_0x4ea20a(_0x16c1b6['result'][_0x86b7('0x16')]);}})['catch'](function(_0x51696d){logger[_0x86b7('0x14')]('SmsQueue,\x20%s,\x20%s',_0x151757,_0x51696d);_0x3f5f92(_0x51696d);});});}exports[_0x86b7('0x17')]=function(_0x507369){var _0x15d5e5=this;return new Promise(function(_0x4932b9,_0x1a6b50){return db[_0x86b7('0x18')][_0x86b7('0x19')]({'raw':_0x507369['options']?_0x507369[_0x86b7('0x1a')][_0x86b7('0x1b')]===undefined?!![]:![]:!![],'where':_0x507369[_0x86b7('0x1a')]?_0x507369['options'][_0x86b7('0x1c')]||null:null,'attributes':_0x507369['options']?_0x507369['options'][_0x86b7('0x1d')]||null:null,'limit':_0x507369[_0x86b7('0x1a')]?_0x507369[_0x86b7('0x1a')][_0x86b7('0x1e')]||null:null,'include':_0x507369['options']?_0x507369[_0x86b7('0x1a')][_0x86b7('0x1f')]?_[_0x86b7('0x20')](_0x507369['options'][_0x86b7('0x1f')],function(_0x4fdbf6){return{'model':db[_0x4fdbf6[_0x86b7('0x21')]],'as':_0x4fdbf6['as'],'attributes':_0x4fdbf6[_0x86b7('0x1d')],'include':_0x4fdbf6[_0x86b7('0x1f')]?_[_0x86b7('0x20')](_0x4fdbf6['include'],function(_0x33e3e4){return{'model':db[_0x33e3e4[_0x86b7('0x21')]],'as':_0x33e3e4['as'],'attributes':_0x33e3e4['attributes'],'include':_0x33e3e4[_0x86b7('0x1f')]?_[_0x86b7('0x20')](_0x33e3e4['include'],function(_0x18ba80){return{'model':db[_0x18ba80[_0x86b7('0x21')]],'as':_0x18ba80['as'],'attributes':_0x18ba80[_0x86b7('0x1d')]};}):[]};}):[]};}):[]:[]})[_0x86b7('0xf')](function(_0x2248b9){logger[_0x86b7('0x10')](_0x86b7('0x17'),_0x507369);logger[_0x86b7('0x12')]('GetSmsQueue',_0x507369,JSON[_0x86b7('0x22')](_0x2248b9));_0x4932b9(_0x2248b9);})['catch'](function(_0x77926){logger['error'](_0x86b7('0x17'),_0x77926[_0x86b7('0x16')],_0x507369);_0x1a6b50(_0x15d5e5[_0x86b7('0x14')](0x1f4,_0x77926[_0x86b7('0x16')]));});});};exports[_0x86b7('0x23')]=function(_0x19e18b){var _0x38da4d=this;return new Promise(function(_0x4cc9f7,_0x73d0f4){return db[_0x86b7('0x18')][_0x86b7('0x24')]({'raw':_0x19e18b[_0x86b7('0x1a')]?_0x19e18b[_0x86b7('0x1a')][_0x86b7('0x1b')]===undefined?!![]:![]:!![],'where':_0x19e18b[_0x86b7('0x1a')]?_0x19e18b[_0x86b7('0x1a')][_0x86b7('0x1c')]||null:null,'attributes':_0x19e18b['options']?_0x19e18b[_0x86b7('0x1a')][_0x86b7('0x1d')]||null:null,'include':_0x19e18b[_0x86b7('0x1a')]?_0x19e18b[_0x86b7('0x1a')][_0x86b7('0x1f')]?_[_0x86b7('0x20')](_0x19e18b['options'][_0x86b7('0x1f')],function(_0x1ec680){return{'model':db[_0x1ec680[_0x86b7('0x21')]],'as':_0x1ec680['as'],'attributes':_0x1ec680[_0x86b7('0x1d')],'include':_0x1ec680[_0x86b7('0x1f')]?_['map'](_0x1ec680[_0x86b7('0x1f')],function(_0x1751e2){return{'model':db[_0x1751e2[_0x86b7('0x21')]],'as':_0x1751e2['as'],'attributes':_0x1751e2[_0x86b7('0x1d')],'include':_0x1751e2[_0x86b7('0x1f')]?_[_0x86b7('0x20')](_0x1751e2[_0x86b7('0x1f')],function(_0x1f16e9){return{'model':db[_0x1f16e9[_0x86b7('0x21')]],'as':_0x1f16e9['as'],'attributes':_0x1f16e9[_0x86b7('0x1d')]};}):[]};}):[]};}):[]:[]})[_0x86b7('0xf')](function(_0x5dd0a7){logger[_0x86b7('0x10')](_0x86b7('0x23'),_0x19e18b);logger[_0x86b7('0x12')](_0x86b7('0x23'),_0x19e18b,JSON[_0x86b7('0x22')](_0x5dd0a7));_0x4cc9f7(_0x5dd0a7);})[_0x86b7('0x25')](function(_0x1f66e3){logger['error']('ShowSmsQueue',_0x1f66e3['message'],_0x19e18b);_0x73d0f4(_0x38da4d['error'](0x1f4,_0x1f66e3['message']));});});};