Built motion from commit b0a9a629.|2.6.33
[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 _0xf5c2=['defaults','localhost','register','request','then','SmsQueue,\x20%s,\x20%s','request\x20sent','SmsQueue,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result','catch','options','raw','where','attributes','include','map','model','GetSmsQueue','ShowSmsQueue','find','debug','lodash','util','moment','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','http','redis'];(function(_0x2f0d4e,_0xa2ddfe){var _0x457d19=function(_0x15e752){while(--_0x15e752){_0x2f0d4e['push'](_0x2f0d4e['shift']());}};_0x457d19(++_0xa2ddfe);}(_0xf5c2,0x1ee));var _0x2f5c=function(_0x26bbd1,_0xb274f3){_0x26bbd1=_0x26bbd1-0x0;var _0x26b1eb=_0xf5c2[_0x26bbd1];return _0x26b1eb;};'use strict';var _=require(_0x2f5c('0x0'));var util=require(_0x2f5c('0x1'));var moment=require(_0x2f5c('0x2'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require(_0x2f5c('0x3'));var logger=require(_0x2f5c('0x4'))(_0x2f5c('0x5'));var config=require(_0x2f5c('0x6'));var jayson=require(_0x2f5c('0x7'));var client=jayson['client'][_0x2f5c('0x8')]({'port':0x232a});config[_0x2f5c('0x9')]=_[_0x2f5c('0xa')](config['redis'],{'host':_0x2f5c('0xb'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x2f5c('0x9')]));require('./smsQueue.socket')[_0x2f5c('0xc')](socket);function respondWithRpcPromise(_0x4b47f0,_0x1f168f,_0x4e301d){return new BPromise(function(_0x4834b3,_0x3bccaf){return client[_0x2f5c('0xd')](_0x4b47f0,_0x4e301d)[_0x2f5c('0xe')](function(_0x47ae14){logger['info'](_0x2f5c('0xf'),_0x1f168f,_0x2f5c('0x10'));logger['debug'](_0x2f5c('0x11'),_0x1f168f,_0x2f5c('0x10'),JSON[_0x2f5c('0x12')](_0x47ae14));if(_0x47ae14['error']){if(_0x47ae14[_0x2f5c('0x13')][_0x2f5c('0x14')]===0x1f4){logger[_0x2f5c('0x13')]('SmsQueue,\x20%s,\x20%s',_0x1f168f,_0x47ae14[_0x2f5c('0x13')]['message']);return _0x3bccaf(_0x47ae14[_0x2f5c('0x13')]['message']);}logger[_0x2f5c('0x13')](_0x2f5c('0xf'),_0x1f168f,_0x47ae14[_0x2f5c('0x13')][_0x2f5c('0x15')]);return _0x4834b3(_0x47ae14[_0x2f5c('0x13')][_0x2f5c('0x15')]);}else{logger[_0x2f5c('0x16')]('SmsQueue,\x20%s,\x20%s',_0x1f168f,_0x2f5c('0x10'));_0x4834b3(_0x47ae14[_0x2f5c('0x17')]['message']);}})[_0x2f5c('0x18')](function(_0x466e43){logger[_0x2f5c('0x13')](_0x2f5c('0xf'),_0x1f168f,_0x466e43);_0x3bccaf(_0x466e43);});});}exports['GetSmsQueue']=function(_0x69ba8b){var _0x343461=this;return new Promise(function(_0x308245,_0x45c3e1){return db['SmsQueue']['findAll']({'raw':_0x69ba8b['options']?_0x69ba8b[_0x2f5c('0x19')][_0x2f5c('0x1a')]===undefined?!![]:![]:!![],'where':_0x69ba8b['options']?_0x69ba8b[_0x2f5c('0x19')][_0x2f5c('0x1b')]||null:null,'attributes':_0x69ba8b['options']?_0x69ba8b[_0x2f5c('0x19')][_0x2f5c('0x1c')]||null:null,'limit':_0x69ba8b[_0x2f5c('0x19')]?_0x69ba8b[_0x2f5c('0x19')]['limit']||null:null,'include':_0x69ba8b['options']?_0x69ba8b[_0x2f5c('0x19')][_0x2f5c('0x1d')]?_[_0x2f5c('0x1e')](_0x69ba8b[_0x2f5c('0x19')]['include'],function(_0x5e0091){return{'model':db[_0x5e0091[_0x2f5c('0x1f')]],'as':_0x5e0091['as'],'attributes':_0x5e0091[_0x2f5c('0x1c')],'include':_0x5e0091[_0x2f5c('0x1d')]?_['map'](_0x5e0091[_0x2f5c('0x1d')],function(_0x3ce5ee){return{'model':db[_0x3ce5ee[_0x2f5c('0x1f')]],'as':_0x3ce5ee['as'],'attributes':_0x3ce5ee[_0x2f5c('0x1c')],'include':_0x3ce5ee[_0x2f5c('0x1d')]?_[_0x2f5c('0x1e')](_0x3ce5ee[_0x2f5c('0x1d')],function(_0x438200){return{'model':db[_0x438200[_0x2f5c('0x1f')]],'as':_0x438200['as'],'attributes':_0x438200[_0x2f5c('0x1c')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x8d2e4e){logger['info'](_0x2f5c('0x20'),_0x69ba8b);logger['debug'](_0x2f5c('0x20'),_0x69ba8b,JSON['stringify'](_0x8d2e4e));_0x308245(_0x8d2e4e);})[_0x2f5c('0x18')](function(_0x3815cd){logger[_0x2f5c('0x13')](_0x2f5c('0x20'),_0x3815cd[_0x2f5c('0x15')],_0x69ba8b);_0x45c3e1(_0x343461['error'](0x1f4,_0x3815cd[_0x2f5c('0x15')]));});});};exports[_0x2f5c('0x21')]=function(_0x351bec){var _0x56ac97=this;return new Promise(function(_0x126e7c,_0x53c3e7){return db['SmsQueue'][_0x2f5c('0x22')]({'raw':_0x351bec[_0x2f5c('0x19')]?_0x351bec[_0x2f5c('0x19')]['raw']===undefined?!![]:![]:!![],'where':_0x351bec[_0x2f5c('0x19')]?_0x351bec[_0x2f5c('0x19')][_0x2f5c('0x1b')]||null:null,'attributes':_0x351bec['options']?_0x351bec[_0x2f5c('0x19')][_0x2f5c('0x1c')]||null:null,'include':_0x351bec['options']?_0x351bec['options'][_0x2f5c('0x1d')]?_[_0x2f5c('0x1e')](_0x351bec[_0x2f5c('0x19')][_0x2f5c('0x1d')],function(_0x5c7cdf){return{'model':db[_0x5c7cdf['model']],'as':_0x5c7cdf['as'],'attributes':_0x5c7cdf[_0x2f5c('0x1c')],'include':_0x5c7cdf[_0x2f5c('0x1d')]?_['map'](_0x5c7cdf['include'],function(_0x28e44a){return{'model':db[_0x28e44a[_0x2f5c('0x1f')]],'as':_0x28e44a['as'],'attributes':_0x28e44a['attributes'],'include':_0x28e44a[_0x2f5c('0x1d')]?_[_0x2f5c('0x1e')](_0x28e44a['include'],function(_0x377fec){return{'model':db[_0x377fec['model']],'as':_0x377fec['as'],'attributes':_0x377fec['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x5cb62){logger[_0x2f5c('0x16')](_0x2f5c('0x21'),_0x351bec);logger[_0x2f5c('0x23')](_0x2f5c('0x21'),_0x351bec,JSON[_0x2f5c('0x12')](_0x5cb62));_0x126e7c(_0x5cb62);})['catch'](function(_0x17ae66){logger[_0x2f5c('0x13')](_0x2f5c('0x21'),_0x17ae66[_0x2f5c('0x15')],_0x351bec);_0x53c3e7(_0x56ac97[_0x2f5c('0x13')](0x1f4,_0x17ae66[_0x2f5c('0x15')]));});});};