Built motion from commit 013e4bb4.|2.6.18
[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 _0x9176=['options','attributes','include','map','model','debug','lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/environment','jayson/promise','client','http','redis','socket.io-emitter','./whatsappAccount.socket','register','request','then','info','stringify','error','message','WhatsappAccount,\x20%s,\x20%s','request\x20sent','catch','ShowWhatsappAccount','WhatsappAccount','find','raw'];(function(_0x52b839,_0x4f40e4){var _0x52d00f=function(_0x5012a1){while(--_0x5012a1){_0x52b839['push'](_0x52b839['shift']());}};_0x52d00f(++_0x4f40e4);}(_0x9176,0x164));var _0x6917=function(_0x5050c3,_0x329596){_0x5050c3=_0x5050c3-0x0;var _0x370fbf=_0x9176[_0x5050c3];return _0x370fbf;};'use strict';var _=require(_0x6917('0x0'));var util=require(_0x6917('0x1'));var moment=require(_0x6917('0x2'));var BPromise=require(_0x6917('0x3'));var rs=require(_0x6917('0x4'));var fs=require('fs');var Redis=require(_0x6917('0x5'));var db=require(_0x6917('0x6'))['db'];var utils=require(_0x6917('0x7'));var logger=require('../../config/logger')('rpc');var config=require(_0x6917('0x8'));var jayson=require(_0x6917('0x9'));var client=jayson[_0x6917('0xa')][_0x6917('0xb')]({'port':0x232a});config[_0x6917('0xc')]=_['defaults'](config[_0x6917('0xc')],{'host':'localhost','port':0x18eb});var socket=require(_0x6917('0xd'))(new Redis(config['redis']));require(_0x6917('0xe'))[_0x6917('0xf')](socket);function respondWithRpcPromise(_0x24d878,_0x56a4f6,_0x11fc8b){return new BPromise(function(_0x53a1de,_0x4610d4){return client[_0x6917('0x10')](_0x24d878,_0x11fc8b)[_0x6917('0x11')](function(_0xbf96a7){logger[_0x6917('0x12')]('WhatsappAccount,\x20%s,\x20%s',_0x56a4f6,'request\x20sent');logger['debug']('WhatsappAccount,\x20%s,\x20%s,\x20%s',_0x56a4f6,'request\x20sent',JSON[_0x6917('0x13')](_0xbf96a7));if(_0xbf96a7[_0x6917('0x14')]){if(_0xbf96a7[_0x6917('0x14')]['code']===0x1f4){logger[_0x6917('0x14')]('WhatsappAccount,\x20%s,\x20%s',_0x56a4f6,_0xbf96a7[_0x6917('0x14')]['message']);return _0x4610d4(_0xbf96a7[_0x6917('0x14')][_0x6917('0x15')]);}logger['error'](_0x6917('0x16'),_0x56a4f6,_0xbf96a7['error']['message']);return _0x53a1de(_0xbf96a7[_0x6917('0x14')][_0x6917('0x15')]);}else{logger[_0x6917('0x12')]('WhatsappAccount,\x20%s,\x20%s',_0x56a4f6,_0x6917('0x17'));_0x53a1de(_0xbf96a7['result'][_0x6917('0x15')]);}})[_0x6917('0x18')](function(_0x1d8b8b){logger[_0x6917('0x14')]('WhatsappAccount,\x20%s,\x20%s',_0x56a4f6,_0x1d8b8b);_0x4610d4(_0x1d8b8b);});});}exports[_0x6917('0x19')]=function(_0x39eeb9){var _0x39fd85=this;return new Promise(function(_0x1728f4,_0x334629){return db[_0x6917('0x1a')][_0x6917('0x1b')]({'raw':_0x39eeb9['options']?_0x39eeb9['options'][_0x6917('0x1c')]===undefined?!![]:![]:!![],'where':_0x39eeb9[_0x6917('0x1d')]?_0x39eeb9[_0x6917('0x1d')]['where']||null:null,'attributes':_0x39eeb9['options']?_0x39eeb9['options'][_0x6917('0x1e')]||null:null,'include':_0x39eeb9[_0x6917('0x1d')]?_0x39eeb9[_0x6917('0x1d')][_0x6917('0x1f')]?_[_0x6917('0x20')](_0x39eeb9[_0x6917('0x1d')][_0x6917('0x1f')],function(_0x42ab0d){return{'model':db[_0x42ab0d['model']],'as':_0x42ab0d['as'],'attributes':_0x42ab0d[_0x6917('0x1e')],'include':_0x42ab0d[_0x6917('0x1f')]?_[_0x6917('0x20')](_0x42ab0d[_0x6917('0x1f')],function(_0x3ca45a){return{'model':db[_0x3ca45a[_0x6917('0x21')]],'as':_0x3ca45a['as'],'attributes':_0x3ca45a[_0x6917('0x1e')],'include':_0x3ca45a['include']?_[_0x6917('0x20')](_0x3ca45a[_0x6917('0x1f')],function(_0x44ff4c){return{'model':db[_0x44ff4c[_0x6917('0x21')]],'as':_0x44ff4c['as'],'attributes':_0x44ff4c['attributes']};}):[]};}):[]};}):[]:[]})[_0x6917('0x11')](function(_0x3de9b6){logger[_0x6917('0x12')](_0x6917('0x19'),_0x39eeb9);logger[_0x6917('0x22')](_0x6917('0x19'),_0x39eeb9,JSON[_0x6917('0x13')](_0x3de9b6));_0x1728f4(_0x3de9b6);})[_0x6917('0x18')](function(_0x1fbdd9){logger[_0x6917('0x14')]('ShowWhatsappAccount',_0x1fbdd9[_0x6917('0x15')],_0x39eeb9);_0x334629(_0x39fd85['error'](0x1f4,_0x1fbdd9[_0x6917('0x15')]));});});};