734779cc1891a2b6b7001471204296bfc168bb52
[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 _0x3ce2=['../../mysqldb','../../config/utils','rpc','../../config/environment','client','http','redis','defaults','localhost','./whatsappAccount.socket','request','then','info','WhatsappAccount,\x20%s,\x20%s','debug','WhatsappAccount,\x20%s,\x20%s,\x20%s','request\x20sent','error','code','message','result','catch','ShowWhatsappAccount','WhatsappAccount','options','raw','where','include','model','map','attributes','stringify','lodash','util','bluebird','randomstring','ioredis'];(function(_0xfff28b,_0x204443){var _0x13c9f0=function(_0x4d9f58){while(--_0x4d9f58){_0xfff28b['push'](_0xfff28b['shift']());}};_0x13c9f0(++_0x204443);}(_0x3ce2,0x192));var _0x23ce=function(_0x3b1b23,_0x21bccd){_0x3b1b23=_0x3b1b23-0x0;var _0x1efc85=_0x3ce2[_0x3b1b23];return _0x1efc85;};'use strict';var _=require(_0x23ce('0x0'));var util=require(_0x23ce('0x1'));var moment=require('moment');var BPromise=require(_0x23ce('0x2'));var rs=require(_0x23ce('0x3'));var fs=require('fs');var Redis=require(_0x23ce('0x4'));var db=require(_0x23ce('0x5'))['db'];var utils=require(_0x23ce('0x6'));var logger=require('../../config/logger')(_0x23ce('0x7'));var config=require(_0x23ce('0x8'));var jayson=require('jayson/promise');var client=jayson[_0x23ce('0x9')][_0x23ce('0xa')]({'port':0x232a});config[_0x23ce('0xb')]=_[_0x23ce('0xc')](config[_0x23ce('0xb')],{'host':_0x23ce('0xd'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x23ce('0xb')]));require(_0x23ce('0xe'))['register'](socket);function respondWithRpcPromise(_0x58e051,_0x5a8ffc,_0x59ca1a){return new BPromise(function(_0x3bba5b,_0x19964f){return client[_0x23ce('0xf')](_0x58e051,_0x59ca1a)[_0x23ce('0x10')](function(_0x246916){logger[_0x23ce('0x11')](_0x23ce('0x12'),_0x5a8ffc,'request\x20sent');logger[_0x23ce('0x13')](_0x23ce('0x14'),_0x5a8ffc,_0x23ce('0x15'),JSON['stringify'](_0x246916));if(_0x246916[_0x23ce('0x16')]){if(_0x246916['error'][_0x23ce('0x17')]===0x1f4){logger['error']('WhatsappAccount,\x20%s,\x20%s',_0x5a8ffc,_0x246916[_0x23ce('0x16')][_0x23ce('0x18')]);return _0x19964f(_0x246916[_0x23ce('0x16')][_0x23ce('0x18')]);}logger[_0x23ce('0x16')](_0x23ce('0x12'),_0x5a8ffc,_0x246916[_0x23ce('0x16')][_0x23ce('0x18')]);return _0x3bba5b(_0x246916[_0x23ce('0x16')][_0x23ce('0x18')]);}else{logger[_0x23ce('0x11')](_0x23ce('0x12'),_0x5a8ffc,_0x23ce('0x15'));_0x3bba5b(_0x246916[_0x23ce('0x19')][_0x23ce('0x18')]);}})[_0x23ce('0x1a')](function(_0x2af883){logger[_0x23ce('0x16')](_0x23ce('0x12'),_0x5a8ffc,_0x2af883);_0x19964f(_0x2af883);});});}exports[_0x23ce('0x1b')]=function(_0x172a65){var _0x1a162e=this;return new Promise(function(_0x23abc7,_0x42658a){return db[_0x23ce('0x1c')]['find']({'raw':_0x172a65[_0x23ce('0x1d')]?_0x172a65[_0x23ce('0x1d')][_0x23ce('0x1e')]===undefined?!![]:![]:!![],'where':_0x172a65[_0x23ce('0x1d')]?_0x172a65[_0x23ce('0x1d')][_0x23ce('0x1f')]||null:null,'attributes':_0x172a65[_0x23ce('0x1d')]?_0x172a65[_0x23ce('0x1d')]['attributes']||null:null,'include':_0x172a65[_0x23ce('0x1d')]?_0x172a65[_0x23ce('0x1d')][_0x23ce('0x20')]?_['map'](_0x172a65[_0x23ce('0x1d')][_0x23ce('0x20')],function(_0x1b838f){return{'model':db[_0x1b838f[_0x23ce('0x21')]],'as':_0x1b838f['as'],'attributes':_0x1b838f['attributes'],'include':_0x1b838f[_0x23ce('0x20')]?_[_0x23ce('0x22')](_0x1b838f[_0x23ce('0x20')],function(_0x236e68){return{'model':db[_0x236e68['model']],'as':_0x236e68['as'],'attributes':_0x236e68[_0x23ce('0x23')],'include':_0x236e68['include']?_[_0x23ce('0x22')](_0x236e68[_0x23ce('0x20')],function(_0x5980ac){return{'model':db[_0x5980ac['model']],'as':_0x5980ac['as'],'attributes':_0x5980ac[_0x23ce('0x23')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x2d0b75){logger[_0x23ce('0x11')](_0x23ce('0x1b'),_0x172a65);logger[_0x23ce('0x13')](_0x23ce('0x1b'),_0x172a65,JSON[_0x23ce('0x24')](_0x2d0b75));_0x23abc7(_0x2d0b75);})[_0x23ce('0x1a')](function(_0x3600cd){logger['error'](_0x23ce('0x1b'),_0x3600cd[_0x23ce('0x18')],_0x172a65);_0x42658a(_0x1a162e[_0x23ce('0x16')](0x1f4,_0x3600cd['message']));});});};