9565225026384b10d6c4f9f1b92cd78b02fd9779
[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 _0x992c=['attributes','include','model','map','stringify','lodash','util','moment','bluebird','../../mysqldb','../../config/utils','../../config/logger','rpc','jayson/promise','client','redis','defaults','localhost','register','request','then','info','WhatsappAccount,\x20%s,\x20%s','request\x20sent','debug','WhatsappAccount,\x20%s,\x20%s,\x20%s','error','code','message','catch','ShowWhatsappAccount','WhatsappAccount','find','options','where'];(function(_0x21a9d9,_0x4d5ac8){var _0x46adce=function(_0xfdd336){while(--_0xfdd336){_0x21a9d9['push'](_0x21a9d9['shift']());}};_0x46adce(++_0x4d5ac8);}(_0x992c,0x163));var _0xc992=function(_0x5bdccd,_0x158276){_0x5bdccd=_0x5bdccd-0x0;var _0x507a81=_0x992c[_0x5bdccd];return _0x507a81;};'use strict';var _=require(_0xc992('0x0'));var util=require(_0xc992('0x1'));var moment=require(_0xc992('0x2'));var BPromise=require(_0xc992('0x3'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require(_0xc992('0x4'))['db'];var utils=require(_0xc992('0x5'));var logger=require(_0xc992('0x6'))(_0xc992('0x7'));var config=require('../../config/environment');var jayson=require(_0xc992('0x8'));var client=jayson[_0xc992('0x9')]['http']({'port':0x232a});config[_0xc992('0xa')]=_[_0xc992('0xb')](config[_0xc992('0xa')],{'host':_0xc992('0xc'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require('./whatsappAccount.socket')[_0xc992('0xd')](socket);function respondWithRpcPromise(_0x2cff29,_0x3259e2,_0x4b67c1){return new BPromise(function(_0xfe94ee,_0x3817ad){return client[_0xc992('0xe')](_0x2cff29,_0x4b67c1)[_0xc992('0xf')](function(_0x142571){logger[_0xc992('0x10')](_0xc992('0x11'),_0x3259e2,_0xc992('0x12'));logger[_0xc992('0x13')](_0xc992('0x14'),_0x3259e2,'request\x20sent',JSON['stringify'](_0x142571));if(_0x142571[_0xc992('0x15')]){if(_0x142571['error'][_0xc992('0x16')]===0x1f4){logger['error'](_0xc992('0x11'),_0x3259e2,_0x142571[_0xc992('0x15')]['message']);return _0x3817ad(_0x142571[_0xc992('0x15')][_0xc992('0x17')]);}logger[_0xc992('0x15')](_0xc992('0x11'),_0x3259e2,_0x142571['error'][_0xc992('0x17')]);return _0xfe94ee(_0x142571['error'][_0xc992('0x17')]);}else{logger['info'](_0xc992('0x11'),_0x3259e2,'request\x20sent');_0xfe94ee(_0x142571['result'][_0xc992('0x17')]);}})[_0xc992('0x18')](function(_0x4c0523){logger[_0xc992('0x15')](_0xc992('0x11'),_0x3259e2,_0x4c0523);_0x3817ad(_0x4c0523);});});}exports[_0xc992('0x19')]=function(_0xc6fafc){var _0x56cfa6=this;return new Promise(function(_0xeae773,_0x12b081){return db[_0xc992('0x1a')][_0xc992('0x1b')]({'raw':_0xc6fafc[_0xc992('0x1c')]?_0xc6fafc['options']['raw']===undefined?!![]:![]:!![],'where':_0xc6fafc[_0xc992('0x1c')]?_0xc6fafc[_0xc992('0x1c')][_0xc992('0x1d')]||null:null,'attributes':_0xc6fafc[_0xc992('0x1c')]?_0xc6fafc[_0xc992('0x1c')][_0xc992('0x1e')]||null:null,'include':_0xc6fafc['options']?_0xc6fafc[_0xc992('0x1c')][_0xc992('0x1f')]?_['map'](_0xc6fafc[_0xc992('0x1c')][_0xc992('0x1f')],function(_0x5bbee6){return{'model':db[_0x5bbee6[_0xc992('0x20')]],'as':_0x5bbee6['as'],'attributes':_0x5bbee6['attributes'],'include':_0x5bbee6[_0xc992('0x1f')]?_['map'](_0x5bbee6[_0xc992('0x1f')],function(_0x177d27){return{'model':db[_0x177d27[_0xc992('0x20')]],'as':_0x177d27['as'],'attributes':_0x177d27[_0xc992('0x1e')],'include':_0x177d27['include']?_[_0xc992('0x21')](_0x177d27[_0xc992('0x1f')],function(_0x253140){return{'model':db[_0x253140[_0xc992('0x20')]],'as':_0x253140['as'],'attributes':_0x253140['attributes']};}):[]};}):[]};}):[]:[]})[_0xc992('0xf')](function(_0x3891e4){logger[_0xc992('0x10')](_0xc992('0x19'),_0xc6fafc);logger[_0xc992('0x13')](_0xc992('0x19'),_0xc6fafc,JSON[_0xc992('0x22')](_0x3891e4));_0xeae773(_0x3891e4);})[_0xc992('0x18')](function(_0x3a543d){logger['error']('ShowWhatsappAccount',_0x3a543d['message'],_0xc6fafc);_0x12b081(_0x56cfa6[_0xc992('0x15')](0x1f4,_0x3a543d[_0xc992('0x17')]));});});};