Built motion from commit b5413ace.|2.6.9
[motion2.git] / server / api / whatsappAccount / whatsappAccount.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 _0x8af3=['client','http','redis','localhost','socket.io-emitter','request','info','WhatsappAccount,\x20%s,\x20%s','request\x20sent','debug','WhatsappAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','ShowWhatsappAccount','WhatsappAccount','options','attributes','include','model','map','lodash','util','moment','bluebird','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment'];(function(_0x5ec8d5,_0x266c3d){var _0x34c0f5=function(_0x50bce5){while(--_0x50bce5){_0x5ec8d5['push'](_0x5ec8d5['shift']());}};_0x34c0f5(++_0x266c3d);}(_0x8af3,0xf7));var _0x38af=function(_0x46f73c,_0x2df92c){_0x46f73c=_0x46f73c-0x0;var _0x20a2ca=_0x8af3[_0x46f73c];return _0x20a2ca;};'use strict';var _=require(_0x38af('0x0'));var util=require(_0x38af('0x1'));var moment=require(_0x38af('0x2'));var BPromise=require(_0x38af('0x3'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require(_0x38af('0x4'))['db'];var utils=require(_0x38af('0x5'));var logger=require(_0x38af('0x6'))(_0x38af('0x7'));var config=require(_0x38af('0x8'));var jayson=require('jayson/promise');var client=jayson[_0x38af('0x9')][_0x38af('0xa')]({'port':0x232a});config['redis']=_['defaults'](config[_0x38af('0xb')],{'host':_0x38af('0xc'),'port':0x18eb});var socket=require(_0x38af('0xd'))(new Redis(config['redis']));require('./whatsappAccount.socket')['register'](socket);function respondWithRpcPromise(_0x5ee795,_0x2308c8,_0x3d11d1){return new BPromise(function(_0x2b478b,_0x4e22aa){return client[_0x38af('0xe')](_0x5ee795,_0x3d11d1)['then'](function(_0x28c395){logger[_0x38af('0xf')](_0x38af('0x10'),_0x2308c8,_0x38af('0x11'));logger[_0x38af('0x12')](_0x38af('0x13'),_0x2308c8,'request\x20sent',JSON[_0x38af('0x14')](_0x28c395));if(_0x28c395[_0x38af('0x15')]){if(_0x28c395['error'][_0x38af('0x16')]===0x1f4){logger[_0x38af('0x15')]('WhatsappAccount,\x20%s,\x20%s',_0x2308c8,_0x28c395[_0x38af('0x15')][_0x38af('0x17')]);return _0x4e22aa(_0x28c395[_0x38af('0x15')]['message']);}logger[_0x38af('0x15')](_0x38af('0x10'),_0x2308c8,_0x28c395['error'][_0x38af('0x17')]);return _0x2b478b(_0x28c395['error'][_0x38af('0x17')]);}else{logger[_0x38af('0xf')]('WhatsappAccount,\x20%s,\x20%s',_0x2308c8,'request\x20sent');_0x2b478b(_0x28c395['result'][_0x38af('0x17')]);}})[_0x38af('0x18')](function(_0xec3ca5){logger[_0x38af('0x15')](_0x38af('0x10'),_0x2308c8,_0xec3ca5);_0x4e22aa(_0xec3ca5);});});}exports[_0x38af('0x19')]=function(_0x26c1d8){var _0x338172=this;return new Promise(function(_0x3baa77,_0x4a1f68){return db[_0x38af('0x1a')]['find']({'raw':_0x26c1d8['options']?_0x26c1d8['options']['raw']===undefined?!![]:![]:!![],'where':_0x26c1d8[_0x38af('0x1b')]?_0x26c1d8[_0x38af('0x1b')]['where']||null:null,'attributes':_0x26c1d8[_0x38af('0x1b')]?_0x26c1d8[_0x38af('0x1b')][_0x38af('0x1c')]||null:null,'include':_0x26c1d8['options']?_0x26c1d8[_0x38af('0x1b')]['include']?_['map'](_0x26c1d8[_0x38af('0x1b')][_0x38af('0x1d')],function(_0x253bc2){return{'model':db[_0x253bc2[_0x38af('0x1e')]],'as':_0x253bc2['as'],'attributes':_0x253bc2['attributes'],'include':_0x253bc2[_0x38af('0x1d')]?_[_0x38af('0x1f')](_0x253bc2[_0x38af('0x1d')],function(_0xb5acc8){return{'model':db[_0xb5acc8[_0x38af('0x1e')]],'as':_0xb5acc8['as'],'attributes':_0xb5acc8[_0x38af('0x1c')],'include':_0xb5acc8[_0x38af('0x1d')]?_[_0x38af('0x1f')](_0xb5acc8[_0x38af('0x1d')],function(_0x400113){return{'model':db[_0x400113[_0x38af('0x1e')]],'as':_0x400113['as'],'attributes':_0x400113[_0x38af('0x1c')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x5eff4d){logger[_0x38af('0xf')](_0x38af('0x19'),_0x26c1d8);logger['debug'](_0x38af('0x19'),_0x26c1d8,JSON[_0x38af('0x14')](_0x5eff4d));_0x3baa77(_0x5eff4d);})[_0x38af('0x18')](function(_0x184c28){logger[_0x38af('0x15')](_0x38af('0x19'),_0x184c28[_0x38af('0x17')],_0x26c1d8);_0x4a1f68(_0x338172[_0x38af('0x15')](0x1f4,_0x184c28['message']));});});};