Built motion from commit df3e9871f6bcc3432fec345b2f4facbd4dba8b5c. Version 3.0.0...
[motion-next.git] / server / api / whatsappMessage / whatsappMessage.controller.js
index 7dcdc80..89c429f 100644 (file)
@@ -1 +1 @@
-const a801_0x15bd=['Contact','model','show','inspect','whatsapp-interactions','reject','fields','jayson/promise','WhatsappMessage,\x20%s,\x20%s','findOne','catch','Content-Range','filter','accept','VIRTUAL','length','read','params','get','SIP/%s','rejectMessage','query','error','interaction','destroy','stack','pick','CmContact','channel','filters','[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','where','register','message','RejectMessage','findAll','EventManager','interface','WhatsappAccount','readAt','rejectmessage','moment','format','stringify','keys','isNil','client','then','type','request','set','MessageStatus','MessageSid','order','attributes','key','include','WhatsppMessage,\x20%s,\x20%s,\x20%s','role','fieldName','status','WhatsappAccount,\x20%s,\x20%s,\x20%s','request\x20sent','options','info','../../config/logger','read1stAt','map','received\x20delivery\x20report\x20from','WhatsappMessage','includeAll','WhatsappMessage,\x20%s,\x20%s,\x20%s','undefined','null','limit','messageId','json','user','count','update','offset','result','describe','WhatsappInteractionId','like','create','http','WhatsappInteraction','name','event','end','sequelize','sort','body','merge','rawAttributes','intersection','send','AcceptMessage','twilio','UserId'];(function(_0x25d4de,_0x15bd64){const _0x51f149=function(_0x29224c){while(--_0x29224c){_0x25d4de['push'](_0x25d4de['shift']());}};_0x51f149(++_0x15bd64);}(a801_0x15bd,0xef));const a801_0x51f1=function(_0x25d4de,_0x15bd64){_0x25d4de=_0x25d4de-0x0;let _0x51f149=a801_0x15bd[_0x25d4de];return _0x51f149;};const _0x3382fe=a801_0x51f1;'use strict';const moment=require(_0x3382fe('0x4')),util=require('util'),_=require('lodash'),qs=require('../../components/parsers/qs'),logger=require(_0x3382fe('0x1c'))('api'),{getSocket}=require('../../rediscache'),socket=getSocket(),interaction_log=require('../../config/logger')(_0x3382fe('0x44')),db=require('../../mysqldb')['db'],{Op}=require(_0x3382fe('0x36'));require('./whatsappMessage.socket')[_0x3382fe('0x60')](socket);const jayson=require(_0x3382fe('0x47')),client=jayson[_0x3382fe('0x9')]['http']({'port':0x232c}),client9002=jayson[_0x3382fe('0x9')][_0x3382fe('0x31')]({'port':0x232a});function respondWithRpcPromise(_0x29224c,_0x591f26,_0x57779f,_0x3b5280){return new Promise(function(_0x58a74e,_0x29a850){const _0x414664=a801_0x51f1,_0x3a92ad=_0x3b5280||client;return _0x3a92ad[_0x414664('0xc')](_0x29224c,_0x57779f)[_0x414664('0xa')](function(_0x375426){const _0x4f5248=_0x414664;logger[_0x4f5248('0x1b')](_0x4f5248('0x48'),_0x591f26,'request\x20sent'),logger['debug'](_0x4f5248('0x22'),_0x591f26,_0x4f5248('0x19'),JSON[_0x4f5248('0x6')](_0x375426));if(_0x375426['error']){if(_0x375426[_0x4f5248('0x56')]['code']===0x1f4)return logger[_0x4f5248('0x56')](_0x4f5248('0x48'),_0x591f26,_0x375426[_0x4f5248('0x56')]['message']),_0x29a850(_0x375426[_0x4f5248('0x56')][_0x4f5248('0x61')]);return logger['error'](_0x4f5248('0x48'),_0x591f26,_0x375426[_0x4f5248('0x56')][_0x4f5248('0x61')]),_0x58a74e(_0x375426['error'][_0x4f5248('0x61')]);}else logger[_0x4f5248('0x1b')](_0x4f5248('0x48'),_0x591f26,_0x4f5248('0x19')),_0x58a74e(_0x375426[_0x4f5248('0x2c')]['message']);})[_0x414664('0x4a')](function(_0x39af1a){const _0x3e6f79=_0x414664;logger[_0x3e6f79('0x56')](_0x3e6f79('0x48'),_0x591f26,_0x39af1a),_0x29a850(_0x39af1a);});});}function respondWithResult(_0x1e6c9f,_0x1bdf87){return _0x1bdf87=_0x1bdf87||0xc8,function(_0x5b3e57){const _0x2fd9a0=a801_0x51f1;if(_0x5b3e57)return _0x1e6c9f[_0x2fd9a0('0x17')](_0x1bdf87)[_0x2fd9a0('0x27')](_0x5b3e57);};}function respondWithFilteredResult(_0xc357a3,_0x4b8139){return function(_0x111a1e){const _0x3f3716=a801_0x51f1;if(_0x111a1e){const _0x3114a=_0x111a1e[_0x3f3716('0x29')],_0x338638=_0x4b8139[_0x3f3716('0x2b')];let _0xf984dc=_0x4b8139[_0x3f3716('0x2b')]+_0x4b8139[_0x3f3716('0x25')],_0x55f972;return _0xf984dc>=_0x3114a?(_0xf984dc=_0x3114a,_0x55f972=0xc8):_0x55f972=0xce,_0xc357a3[_0x3f3716('0x17')](_0x55f972),_0xc357a3[_0x3f3716('0xd')](_0x3f3716('0x4b'),_0x338638+'-'+_0xf984dc+'/'+_0x3114a)['json'](_0x111a1e);}return null;};}function saveUpdates(_0x57588c){return function(_0x4e7a79){const _0x5a4532=a801_0x51f1;if(_0x4e7a79)return _0x4e7a79['update'](_0x57588c)[_0x5a4532('0xa')](function(_0x4b0db8){return _0x4b0db8;});return null;};}function removeEntity(_0x458dc3){return function(_0x1c9e33){const _0x26e513=a801_0x51f1;if(_0x1c9e33)return _0x1c9e33['destroy']()[_0x26e513('0xa')](function(){const _0x3b1e6b=_0x26e513;_0x458dc3[_0x3b1e6b('0x17')](0xcc)[_0x3b1e6b('0x35')]();});};}function handleEntityNotFound(_0xcad0dc){return function(_0x309c58){return!_0x309c58&&_0xcad0dc['sendStatus'](0x194),_0x309c58;};}function handleError(_0x19bcc1,_0x36253f){return _0x36253f=_0x36253f||0x1f4,function(_0x46fce8){const _0x505785=a801_0x51f1;logger[_0x505785('0x56')](_0x46fce8[_0x505785('0x59')]),_0x46fce8[_0x505785('0x33')]&&delete _0x46fce8[_0x505785('0x33')],_0x19bcc1[_0x505785('0x17')](_0x36253f)[_0x505785('0x3c')](_0x46fce8);};}exports['index']=function(_0x1ffc7c,_0x232997){const _0x5081bf=_0x3382fe;let _0x356dc5={};const _0x3bb96c={},_0x4017ca={'count':0x0,'rows':[]},_0x5e7c58=_[_0x5081bf('0x1e')](db[_0x5081bf('0x20')]['rawAttributes'],function(_0x1e5060){const _0x5820f3=_0x5081bf;return{'name':_0x1e5060[_0x5820f3('0x16')],'type':_0x1e5060[_0x5820f3('0xb')][_0x5820f3('0x12')]};});_0x3bb96c[_0x5081bf('0x41')]=_[_0x5081bf('0x1e')](_0x5e7c58,'name'),_0x3bb96c[_0x5081bf('0x55')]=_[_0x5081bf('0x7')](_0x1ffc7c['query']),_0x3bb96c[_0x5081bf('0x5d')]=_[_0x5081bf('0x3b')](_0x3bb96c[_0x5081bf('0x41')],_0x3bb96c[_0x5081bf('0x55')]),_0x356dc5[_0x5081bf('0x11')]=_[_0x5081bf('0x3b')](_0x3bb96c[_0x5081bf('0x41')],qs[_0x5081bf('0x46')](_0x1ffc7c[_0x5081bf('0x55')][_0x5081bf('0x46')])),_0x356dc5[_0x5081bf('0x11')]=_0x356dc5[_0x5081bf('0x11')][_0x5081bf('0x4f')]?_0x356dc5[_0x5081bf('0x11')]:_0x3bb96c[_0x5081bf('0x41')];typeof _0x1ffc7c[_0x5081bf('0x55')]['nolimit']===_0x5081bf('0x23')&&(_0x356dc5[_0x5081bf('0x25')]=qs[_0x5081bf('0x25')](_0x1ffc7c[_0x5081bf('0x55')][_0x5081bf('0x25')]),_0x356dc5[_0x5081bf('0x2b')]=qs['offset'](_0x1ffc7c[_0x5081bf('0x55')][_0x5081bf('0x2b')]));_0x356dc5[_0x5081bf('0x10')]=qs['sort'](_0x1ffc7c[_0x5081bf('0x55')][_0x5081bf('0x37')]),_0x356dc5[_0x5081bf('0x5f')]=qs['filters'](_[_0x5081bf('0x5a')](_0x1ffc7c[_0x5081bf('0x55')],_0x3bb96c[_0x5081bf('0x5d')]),_0x5e7c58);_0x1ffc7c[_0x5081bf('0x55')]['filter']&&(_0x356dc5[_0x5081bf('0x5f')]=_[_0x5081bf('0x39')](_0x356dc5['where'],{[Op['or']]:_[_0x5081bf('0x1e')](_0x5e7c58,function(_0x444f12){const _0x367d85=_0x5081bf;if(_0x444f12['type']!==_0x367d85('0x4e')){const _0x40a7eb={};return _0x40a7eb[_0x444f12[_0x367d85('0x33')]]={[Op[_0x367d85('0x2f')]]:'%'+_0x1ffc7c[_0x367d85('0x55')][_0x367d85('0x4c')]+'%'},_0x40a7eb;}})}));_0x356dc5=_[_0x5081bf('0x39')]({},_0x356dc5,_0x1ffc7c[_0x5081bf('0x1a')]);const _0x2ed25b={'where':_0x356dc5[_0x5081bf('0x5f')]};return db[_0x5081bf('0x20')][_0x5081bf('0x29')](_0x2ed25b)[_0x5081bf('0xa')](function(_0x384d0d){const _0x1d145f=_0x5081bf;return _0x4017ca['count']=_0x384d0d,_0x1ffc7c[_0x1d145f('0x55')]['includeAll']&&(_0x356dc5[_0x1d145f('0x13')]=[{'all':!![]}]),db[_0x1d145f('0x20')][_0x1d145f('0x63')](_0x356dc5);})[_0x5081bf('0xa')](function(_0xc3a1b6){return _0x4017ca['rows']=_0xc3a1b6,_0x4017ca;})[_0x5081bf('0xa')](respondWithFilteredResult(_0x232997,_0x356dc5))[_0x5081bf('0x4a')](handleError(_0x232997,null));},exports[_0x3382fe('0x42')]=function(_0x1a1122,_0x2c18b2){const _0x154697=_0x3382fe;let _0x43f140={'raw':!![],'where':{'id':_0x1a1122[_0x154697('0x51')]['id']}};const _0x86af23={};return _0x86af23[_0x154697('0x41')]=_[_0x154697('0x7')](db[_0x154697('0x20')][_0x154697('0x3a')]),_0x86af23[_0x154697('0x55')]=_['keys'](_0x1a1122[_0x154697('0x55')]),_0x86af23[_0x154697('0x5d')]=_[_0x154697('0x3b')](_0x86af23[_0x154697('0x41')],_0x86af23[_0x154697('0x55')]),_0x43f140[_0x154697('0x11')]=_[_0x154697('0x3b')](_0x86af23['model'],qs[_0x154697('0x46')](_0x1a1122[_0x154697('0x55')][_0x154697('0x46')])),_0x43f140['attributes']=_0x43f140['attributes'][_0x154697('0x4f')]?_0x43f140['attributes']:_0x86af23[_0x154697('0x41')],_0x1a1122['query'][_0x154697('0x21')]&&(_0x43f140[_0x154697('0x13')]=[{'all':!![]}]),_0x43f140=_[_0x154697('0x39')]({},_0x43f140,_0x1a1122[_0x154697('0x1a')]),db[_0x154697('0x20')][_0x154697('0x49')](_0x43f140)['then'](handleEntityNotFound(_0x2c18b2,null))[_0x154697('0xa')](respondWithResult(_0x2c18b2,null))['catch'](handleError(_0x2c18b2,null));},exports[_0x3382fe('0x30')]=function(_0x323502,_0x37e597){const _0x3a5cec=_0x3382fe;return db[_0x3a5cec('0x20')][_0x3a5cec('0x30')](_0x323502[_0x3a5cec('0x38')],{})[_0x3a5cec('0xa')](respondWithResult(_0x37e597,0xc9))[_0x3a5cec('0x4a')](handleError(_0x37e597,null));},exports['update']=function(_0x1cac7e,_0x570b64){const _0xe460ee=_0x3382fe;return _0x1cac7e[_0xe460ee('0x38')]['id']&&delete _0x1cac7e['body']['id'],db[_0xe460ee('0x20')][_0xe460ee('0x49')]({'where':{'id':_0x1cac7e[_0xe460ee('0x51')]['id']}})[_0xe460ee('0xa')](handleEntityNotFound(_0x570b64,null))[_0xe460ee('0xa')](saveUpdates(_0x1cac7e['body'],null))[_0xe460ee('0xa')](respondWithResult(_0x570b64,null))[_0xe460ee('0x4a')](handleError(_0x570b64,null));},exports[_0x3382fe('0x58')]=function(_0x50567e,_0x535de0){const _0x5c524f=_0x3382fe;return db[_0x5c524f('0x20')][_0x5c524f('0x49')]({'where':{'id':_0x50567e[_0x5c524f('0x51')]['id']}})['then'](handleEntityNotFound(_0x535de0,null))[_0x5c524f('0xa')](removeEntity(_0x535de0,null))[_0x5c524f('0x4a')](handleError(_0x535de0,null));},exports[_0x3382fe('0x2d')]=function(_0x11118b,_0x5f28f4){const _0x4ae1af=_0x3382fe;return db[_0x4ae1af('0x20')][_0x4ae1af('0x2d')]()[_0x4ae1af('0xa')](respondWithResult(_0x5f28f4,null))['catch'](handleError(_0x5f28f4,null));},exports[_0x3382fe('0x4d')]=function(_0x347146,_0x4df2c9){const _0x5933fb=_0x3382fe,_0x4a198c={'channel':'whatsapp'};return _0x347146[_0x5933fb('0x38')]['id']&&delete _0x347146['body']['id'],_0x347146['body'][_0x5933fb('0x50')]=!![],_0x347146['body'][_0x5933fb('0x2')]=moment()[_0x5933fb('0x5')]('YYYY-MM-DD\x20HH:mm:ss'),_0x347146['body'][_0x5933fb('0x3f')]=_0x347146[_0x5933fb('0x38')][_0x5933fb('0x3f')]||_0x347146['user']['id'],db[_0x5933fb('0x20')][_0x5933fb('0x49')]({'where':{'id':_0x347146[_0x5933fb('0x51')]['id'],'UserId':null},'include':[{'model':db[_0x5933fb('0x5b')],'as':_0x5933fb('0x40')}]})[_0x5933fb('0xa')](handleEntityNotFound(_0x4df2c9,null))['then'](saveUpdates(_0x347146[_0x5933fb('0x38')],null))[_0x5933fb('0xa')](function(_0x39a370){const _0x566b43=_0x5933fb;if(_0x39a370)return _0x4a198c[_0x566b43('0x61')]=_0x39a370[_0x566b43('0x52')]({'plain':!![]}),db['WhatsappInteraction'][_0x566b43('0x49')]({'where':{'id':_0x39a370[_0x566b43('0x2e')]}});return null;})[_0x5933fb('0xa')](handleEntityNotFound(_0x4df2c9,null))[_0x5933fb('0xa')](function(_0x45bb2a){const _0x1d99f9=_0x5933fb;if(_0x45bb2a)return _0x45bb2a[_0x1d99f9('0x2a')]({'UserId':_0x347146[_0x1d99f9('0x38')][_0x1d99f9('0x3f')],'read1stAt':_[_0x1d99f9('0x8')](_0x45bb2a[_0x1d99f9('0x1d')])?moment()['format']('YYYY-MM-DD\x20HH:mm:ss'):undefined});return null;})[_0x5933fb('0xa')](function(_0x9f5ec1){const _0x2e0f49=_0x5933fb;if(_0x9f5ec1)return _0x4a198c['interaction']=_0x9f5ec1[_0x2e0f49('0x52')]({'plain':!![]}),interaction_log['info'](_0x2e0f49('0x5e'),_0x347146[_0x2e0f49('0x28')]['id'],_0x347146[_0x2e0f49('0x28')]['name'],_0x347146[_0x2e0f49('0x28')][_0x2e0f49('0x15')],_0x4a198c[_0x2e0f49('0x57')]['id'],_0x347146[_0x2e0f49('0x38')]?JSON[_0x2e0f49('0x6')](_0x347146[_0x2e0f49('0x38')]):_0x2e0f49('0x24')),respondWithRpcPromise(_0x2e0f49('0x3d'),'acceptMessage',_0x4a198c);return null;})[_0x5933fb('0xa')](function(_0x26e3e1){const _0xd13bfe=_0x5933fb;if(_0x26e3e1){if(_0x347146['body']['manual'])return _0x4a198c['message'][_0xd13bfe('0x0')]=util[_0xd13bfe('0x5')](_0xd13bfe('0x53'),_0x347146['user'][_0xd13bfe('0x33')]),_0x4a198c[_0xd13bfe('0x61')][_0xd13bfe('0x5c')]=_0x4a198c['channel'],_0x4a198c['message'][_0xd13bfe('0x34')]=_0xd13bfe('0x4d'),respondWithRpcPromise(_0xd13bfe('0x64'),_0xd13bfe('0x64'),{'event':'acceptmessage','message':_0x4a198c[_0xd13bfe('0x61')]},client9002)[_0xd13bfe('0xa')](function(){return _0x4a198c;});return _0x4a198c;}return null;})[_0x5933fb('0xa')](respondWithResult(_0x4df2c9,null))[_0x5933fb('0x4a')](handleError(_0x4df2c9,null));},exports['reject']=function(_0x2d299b,_0x4c1a6e){const _0x555bdf=_0x3382fe,_0x3da684={'agent':{},'channel':'whatsapp'};return _0x2d299b['body']['id']&&delete _0x2d299b[_0x555bdf('0x38')]['id'],_0x2d299b[_0x555bdf('0x38')][_0x555bdf('0x3f')]=_0x2d299b['body'][_0x555bdf('0x3f')]||_0x2d299b[_0x555bdf('0x28')]['id'],_0x3da684['agent']['id']=_0x2d299b[_0x555bdf('0x38')]['UserId'],db['WhatsappMessage'][_0x555bdf('0x49')]({'where':{'id':_0x2d299b[_0x555bdf('0x51')]['id'],'UserId':null}})[_0x555bdf('0xa')](handleEntityNotFound(_0x4c1a6e,null))[_0x555bdf('0xa')](function(_0x28d85f){const _0x1f094c=_0x555bdf;if(_0x28d85f)return _0x3da684['message']=_0x28d85f[_0x1f094c('0x52')]({'plain':!![]}),db[_0x1f094c('0x32')][_0x1f094c('0x49')]({'where':{'id':_0x28d85f['WhatsappInteractionId']}});return null;})['then'](handleEntityNotFound(_0x4c1a6e,null))['then'](function(_0x30396d){const _0x3c6604=_0x555bdf;if(_0x30396d)return _0x3da684[_0x3c6604('0x57')]=_0x30396d[_0x3c6604('0x52')]({'plain':!![]}),interaction_log[_0x3c6604('0x1b')]('[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x2d299b[_0x3c6604('0x28')]['id'],_0x2d299b[_0x3c6604('0x28')][_0x3c6604('0x33')],_0x2d299b[_0x3c6604('0x28')][_0x3c6604('0x15')],_0x3da684['interaction']['id'],_0x2d299b[_0x3c6604('0x38')]?JSON[_0x3c6604('0x6')](_0x2d299b['body']):_0x3c6604('0x24')),respondWithRpcPromise(_0x3c6604('0x62'),_0x3c6604('0x54'),_0x3da684);return null;})[_0x555bdf('0xa')](function(_0x589059){const _0x3d797c=_0x555bdf;if(_0x589059)return _0x589059[_0x3d797c('0x61')]['interface']=util[_0x3d797c('0x5')](_0x3d797c('0x53'),_0x2d299b[_0x3d797c('0x28')][_0x3d797c('0x33')]),_0x589059['message'][_0x3d797c('0x5c')]=_0x3da684[_0x3d797c('0x5c')],_0x589059[_0x3d797c('0x61')]['event']=_0x3d797c('0x45'),respondWithRpcPromise(_0x3d797c('0x64'),_0x3d797c('0x64'),{'event':_0x3d797c('0x3'),'message':_0x589059[_0x3d797c('0x61')]},client9002),_0x3da684;return null;})['then'](respondWithResult(_0x4c1a6e,null))[_0x555bdf('0x4a')](handleError(_0x4c1a6e,null));},exports[_0x3382fe('0x17')]=function(_0x4037f8,_0xf24ba3){const _0x1c81ea=_0x3382fe;_0x4037f8[_0x1c81ea('0x38')]['id']&&delete _0x4037f8[_0x1c81ea('0x38')]['id'];let _0x1efd78;return db[_0x1c81ea('0x20')][_0x1c81ea('0x49')]({'where':{'id':_0x4037f8[_0x1c81ea('0x51')]['id']}})['then'](handleEntityNotFound(_0xf24ba3,null))[_0x1c81ea('0xa')](function(_0x5473b6){const _0x2adeec=_0x1c81ea;if(_0x5473b6)return _0x1efd78=_0x5473b6,db[_0x2adeec('0x1')][_0x2adeec('0x49')]({'where':{'id':_0x5473b6['WhatsappAccountId']}});})[_0x1c81ea('0xa')](handleEntityNotFound(_0xf24ba3,null))[_0x1c81ea('0xa')](function(_0x2e2833){const _0x2855a7=_0x1c81ea;if(_0x2e2833){logger['debug'](_0x2855a7('0x14'),'status',_0x2855a7('0x1f'),_0x2e2833[_0x2855a7('0xb')],util['inspect'](_0x4037f8[_0x2855a7('0x38')],{'showHidden':![],'depth':null}));switch(_0x2e2833[_0x2855a7('0xb')]){case _0x2855a7('0x3e'):if(_0x4037f8['body'][_0x2855a7('0xf')]&&_0x4037f8[_0x2855a7('0x38')][_0x2855a7('0xf')]===_0x1efd78[_0x2855a7('0x26')]&&_0x4037f8[_0x2855a7('0x38')][_0x2855a7('0xe')]&&_0x4037f8[_0x2855a7('0x38')][_0x2855a7('0xe')]===_0x2855a7('0x50'))return _0x1efd78[_0x2855a7('0x2a')]({'read':!![]});else logger[_0x2855a7('0x56')](_0x2855a7('0x18'),'status',_0x2855a7('0x3e'),util[_0x2855a7('0x43')](_0x4037f8['body'],{'showHidden':![],'depth':null}));break;}return _0x1efd78;}})[_0x1c81ea('0xa')](respondWithResult(_0xf24ba3,null))[_0x1c81ea('0x4a')](handleError(_0xf24ba3,null));};
\ No newline at end of file
+const a801_0x3306=['rows','acceptMessage','status','CmContact','update','role','rawAttributes','MessageSid','request\x20sent','format','index','received\x20delivery\x20report\x20from','WhatsppMessage,\x20%s,\x20%s,\x20%s','util','stack','stringify','order','end','read1stAt','inspect','YYYY-MM-DD\x20HH:mm:ss','reject','WhatsappMessage','filter','Contact','messageId','query','WhatsappInteraction','options','like','fieldName','limit','user','client','catch','request','send','[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','destroy','rejectmessage','debug','moment','rejectMessage','interface','../../components/parsers/qs','name','offset','whatsapp','where','../../config/logger','lodash','WhatsappMessage,\x20%s,\x20%s','VIRTUAL','key','../../mysqldb','findAll','show','WhatsappInteractionId','event','attributes','merge','filters','api','isNil','whatsapp-interactions','include','findOne','register','info','then','model','create','message','map','get','intersection','sort','null','readAt','includeAll','keys','MessageStatus','EventManager','error','body','WhatsappAccountId','code','length','json','params','AcceptMessage','twilio','WhatsappAccount','pick','fields','interaction','undefined','sequelize','UserId','set','count','channel','read','result','agent','http','accept','type','describe','WhatsappAccount,\x20%s,\x20%s,\x20%s'];(function(_0x59b7bd,_0x3306a4){const _0x476793=function(_0x5853d3){while(--_0x5853d3){_0x59b7bd['push'](_0x59b7bd['shift']());}};_0x476793(++_0x3306a4);}(a801_0x3306,0x17a));const a801_0x4767=function(_0x59b7bd,_0x3306a4){_0x59b7bd=_0x59b7bd-0x0;let _0x476793=a801_0x3306[_0x59b7bd];return _0x476793;};const _0x551220=a801_0x4767;'use strict';const moment=require(_0x551220('0x67')),util=require(_0x551220('0x4b')),_=require(_0x551220('0x2')),qs=require(_0x551220('0x6a')),logger=require(_0x551220('0x1'))(_0x551220('0xe')),{getSocket}=require('../../rediscache'),socket=getSocket(),interaction_log=require(_0x551220('0x1'))(_0x551220('0x10')),db=require(_0x551220('0x6'))['db'],{Op}=require(_0x551220('0x31'));require('./whatsappMessage.socket')[_0x551220('0x13')](socket);const jayson=require('jayson/promise'),client=jayson['client']['http']({'port':0x232c}),client9002=jayson[_0x551220('0x5f')][_0x551220('0x39')]({'port':0x232a});function respondWithRpcPromise(_0x5853d3,_0x37f9e0,_0x5730a1,_0x15dad1){return new Promise(function(_0x287342,_0x34f0a2){const _0x24709b=a801_0x4767,_0x394fc6=_0x15dad1||client;return _0x394fc6[_0x24709b('0x61')](_0x5853d3,_0x5730a1)['then'](function(_0x2c2158){const _0x13a53f=_0x24709b;logger['info']('WhatsappMessage,\x20%s,\x20%s',_0x37f9e0,'request\x20sent'),logger['debug']('WhatsappMessage,\x20%s,\x20%s,\x20%s',_0x37f9e0,_0x13a53f('0x46'),JSON[_0x13a53f('0x4d')](_0x2c2158));if(_0x2c2158[_0x13a53f('0x23')]){if(_0x2c2158['error'][_0x13a53f('0x26')]===0x1f4)return logger[_0x13a53f('0x23')]('WhatsappMessage,\x20%s,\x20%s',_0x37f9e0,_0x2c2158['error'][_0x13a53f('0x18')]),_0x34f0a2(_0x2c2158[_0x13a53f('0x23')][_0x13a53f('0x18')]);return logger[_0x13a53f('0x23')](_0x13a53f('0x3'),_0x37f9e0,_0x2c2158[_0x13a53f('0x23')][_0x13a53f('0x18')]),_0x287342(_0x2c2158['error'][_0x13a53f('0x18')]);}else logger[_0x13a53f('0x14')]('WhatsappMessage,\x20%s,\x20%s',_0x37f9e0,_0x13a53f('0x46')),_0x287342(_0x2c2158[_0x13a53f('0x37')][_0x13a53f('0x18')]);})[_0x24709b('0x60')](function(_0x472943){const _0x2d24bd=_0x24709b;logger[_0x2d24bd('0x23')]('WhatsappMessage,\x20%s,\x20%s',_0x37f9e0,_0x472943),_0x34f0a2(_0x472943);});});}function respondWithResult(_0xa590f1,_0x1d6eb3){return _0x1d6eb3=_0x1d6eb3||0xc8,function(_0x57e329){const _0x2c87f8=a801_0x4767;if(_0x57e329)return _0xa590f1[_0x2c87f8('0x40')](_0x1d6eb3)[_0x2c87f8('0x28')](_0x57e329);};}function respondWithFilteredResult(_0x2bcdd1,_0x9d02c4){return function(_0xbac8b6){const _0x5a6899=a801_0x4767;if(_0xbac8b6){const _0x57ba1d=_0xbac8b6[_0x5a6899('0x34')],_0x10e6b0=_0x9d02c4[_0x5a6899('0x6c')];let _0x29d65a=_0x9d02c4['offset']+_0x9d02c4[_0x5a6899('0x5d')],_0x52f5ed;return _0x29d65a>=_0x57ba1d?(_0x29d65a=_0x57ba1d,_0x52f5ed=0xc8):_0x52f5ed=0xce,_0x2bcdd1[_0x5a6899('0x40')](_0x52f5ed),_0x2bcdd1[_0x5a6899('0x33')]('Content-Range',_0x10e6b0+'-'+_0x29d65a+'/'+_0x57ba1d)[_0x5a6899('0x28')](_0xbac8b6);}return null;};}function saveUpdates(_0xfd5bc3){return function(_0x1b4bd0){const _0x53b8b6=a801_0x4767;if(_0x1b4bd0)return _0x1b4bd0['update'](_0xfd5bc3)[_0x53b8b6('0x15')](function(_0x5abcfe){return _0x5abcfe;});return null;};}function removeEntity(_0x7727){return function(_0x41fc23){const _0x10661c=a801_0x4767;if(_0x41fc23)return _0x41fc23[_0x10661c('0x64')]()[_0x10661c('0x15')](function(){const _0x51d611=_0x10661c;_0x7727[_0x51d611('0x40')](0xcc)[_0x51d611('0x4f')]();});};}function handleEntityNotFound(_0x4d14cb){return function(_0x549af0){return!_0x549af0&&_0x4d14cb['sendStatus'](0x194),_0x549af0;};}function handleError(_0x13cceb,_0x5c03ff){return _0x5c03ff=_0x5c03ff||0x1f4,function(_0x13fc37){const _0x25190d=a801_0x4767;logger['error'](_0x13fc37[_0x25190d('0x4c')]),_0x13fc37[_0x25190d('0x6b')]&&delete _0x13fc37[_0x25190d('0x6b')],_0x13cceb['status'](_0x5c03ff)[_0x25190d('0x62')](_0x13fc37);};}exports[_0x551220('0x48')]=function(_0x159616,_0x4265f2){const _0x328532=_0x551220;let _0x287c67={};const _0x4211c4={},_0x20d00e={'count':0x0,'rows':[]},_0x3c77c4=_[_0x328532('0x19')](db['WhatsappMessage']['rawAttributes'],function(_0x22e454){const _0x1b1f60=_0x328532;return{'name':_0x22e454[_0x1b1f60('0x5c')],'type':_0x22e454[_0x1b1f60('0x3b')][_0x1b1f60('0x5')]};});_0x4211c4[_0x328532('0x16')]=_[_0x328532('0x19')](_0x3c77c4,_0x328532('0x6b')),_0x4211c4['query']=_[_0x328532('0x20')](_0x159616['query']),_0x4211c4['filters']=_[_0x328532('0x1b')](_0x4211c4[_0x328532('0x16')],_0x4211c4[_0x328532('0x58')]),_0x287c67[_0x328532('0xb')]=_[_0x328532('0x1b')](_0x4211c4[_0x328532('0x16')],qs['fields'](_0x159616[_0x328532('0x58')][_0x328532('0x2e')])),_0x287c67[_0x328532('0xb')]=_0x287c67[_0x328532('0xb')][_0x328532('0x27')]?_0x287c67['attributes']:_0x4211c4[_0x328532('0x16')];typeof _0x159616[_0x328532('0x58')]['nolimit']===_0x328532('0x30')&&(_0x287c67[_0x328532('0x5d')]=qs['limit'](_0x159616['query'][_0x328532('0x5d')]),_0x287c67[_0x328532('0x6c')]=qs[_0x328532('0x6c')](_0x159616['query'][_0x328532('0x6c')]));_0x287c67[_0x328532('0x4e')]=qs[_0x328532('0x1c')](_0x159616[_0x328532('0x58')][_0x328532('0x1c')]),_0x287c67['where']=qs[_0x328532('0xd')](_[_0x328532('0x2d')](_0x159616[_0x328532('0x58')],_0x4211c4[_0x328532('0xd')]),_0x3c77c4);_0x159616['query'][_0x328532('0x55')]&&(_0x287c67[_0x328532('0x0')]=_['merge'](_0x287c67[_0x328532('0x0')],{[Op['or']]:_[_0x328532('0x19')](_0x3c77c4,function(_0x4fa275){const _0x3e9f0d=_0x328532;if(_0x4fa275[_0x3e9f0d('0x3b')]!==_0x3e9f0d('0x4')){const _0x335d01={};return _0x335d01[_0x4fa275['name']]={[Op[_0x3e9f0d('0x5b')]]:'%'+_0x159616['query'][_0x3e9f0d('0x55')]+'%'},_0x335d01;}})}));_0x287c67=_[_0x328532('0xc')]({},_0x287c67,_0x159616[_0x328532('0x5a')]);const _0x3ae747={'where':_0x287c67[_0x328532('0x0')]};return db[_0x328532('0x54')][_0x328532('0x34')](_0x3ae747)[_0x328532('0x15')](function(_0x3064b9){const _0x3b94a9=_0x328532;return _0x20d00e['count']=_0x3064b9,_0x159616[_0x3b94a9('0x58')][_0x3b94a9('0x1f')]&&(_0x287c67[_0x3b94a9('0x11')]=[{'all':!![]}]),db[_0x3b94a9('0x54')][_0x3b94a9('0x7')](_0x287c67);})[_0x328532('0x15')](function(_0x134465){const _0x1db854=_0x328532;return _0x20d00e[_0x1db854('0x3e')]=_0x134465,_0x20d00e;})[_0x328532('0x15')](respondWithFilteredResult(_0x4265f2,_0x287c67))[_0x328532('0x60')](handleError(_0x4265f2,null));},exports[_0x551220('0x8')]=function(_0x13a22c,_0x837f2e){const _0x17e054=_0x551220;let _0x1fe320={'raw':!![],'where':{'id':_0x13a22c[_0x17e054('0x29')]['id']}};const _0x3edd0={};return _0x3edd0[_0x17e054('0x16')]=_[_0x17e054('0x20')](db[_0x17e054('0x54')][_0x17e054('0x44')]),_0x3edd0[_0x17e054('0x58')]=_[_0x17e054('0x20')](_0x13a22c[_0x17e054('0x58')]),_0x3edd0[_0x17e054('0xd')]=_[_0x17e054('0x1b')](_0x3edd0[_0x17e054('0x16')],_0x3edd0[_0x17e054('0x58')]),_0x1fe320['attributes']=_['intersection'](_0x3edd0[_0x17e054('0x16')],qs[_0x17e054('0x2e')](_0x13a22c[_0x17e054('0x58')][_0x17e054('0x2e')])),_0x1fe320[_0x17e054('0xb')]=_0x1fe320[_0x17e054('0xb')][_0x17e054('0x27')]?_0x1fe320[_0x17e054('0xb')]:_0x3edd0[_0x17e054('0x16')],_0x13a22c[_0x17e054('0x58')][_0x17e054('0x1f')]&&(_0x1fe320['include']=[{'all':!![]}]),_0x1fe320=_[_0x17e054('0xc')]({},_0x1fe320,_0x13a22c[_0x17e054('0x5a')]),db[_0x17e054('0x54')]['findOne'](_0x1fe320)[_0x17e054('0x15')](handleEntityNotFound(_0x837f2e,null))[_0x17e054('0x15')](respondWithResult(_0x837f2e,null))[_0x17e054('0x60')](handleError(_0x837f2e,null));},exports[_0x551220('0x17')]=function(_0x5fc65a,_0x2164f3){const _0x39cb78=_0x551220;return db['WhatsappMessage'][_0x39cb78('0x17')](_0x5fc65a['body'],{})[_0x39cb78('0x15')](respondWithResult(_0x2164f3,0xc9))['catch'](handleError(_0x2164f3,null));},exports[_0x551220('0x42')]=function(_0x45e350,_0x2109ed){const _0x41b997=_0x551220;return _0x45e350[_0x41b997('0x24')]['id']&&delete _0x45e350[_0x41b997('0x24')]['id'],db[_0x41b997('0x54')]['findOne']({'where':{'id':_0x45e350[_0x41b997('0x29')]['id']}})[_0x41b997('0x15')](handleEntityNotFound(_0x2109ed,null))[_0x41b997('0x15')](saveUpdates(_0x45e350[_0x41b997('0x24')],null))[_0x41b997('0x15')](respondWithResult(_0x2109ed,null))['catch'](handleError(_0x2109ed,null));},exports[_0x551220('0x64')]=function(_0x37b257,_0x50e05f){const _0x15aba2=_0x551220;return db[_0x15aba2('0x54')][_0x15aba2('0x12')]({'where':{'id':_0x37b257[_0x15aba2('0x29')]['id']}})[_0x15aba2('0x15')](handleEntityNotFound(_0x50e05f,null))[_0x15aba2('0x15')](removeEntity(_0x50e05f,null))[_0x15aba2('0x60')](handleError(_0x50e05f,null));},exports[_0x551220('0x3c')]=function(_0x239469,_0x2a1fdf){const _0x2185ca=_0x551220;return db[_0x2185ca('0x54')][_0x2185ca('0x3c')]()[_0x2185ca('0x15')](respondWithResult(_0x2a1fdf,null))[_0x2185ca('0x60')](handleError(_0x2a1fdf,null));},exports[_0x551220('0x3a')]=function(_0xd1f858,_0x558737){const _0x9cb088=_0x551220,_0x1796aa={'channel':_0x9cb088('0x6d')};return _0xd1f858[_0x9cb088('0x24')]['id']&&delete _0xd1f858['body']['id'],_0xd1f858['body'][_0x9cb088('0x36')]=!![],_0xd1f858[_0x9cb088('0x24')][_0x9cb088('0x1e')]=moment()[_0x9cb088('0x47')](_0x9cb088('0x52')),_0xd1f858[_0x9cb088('0x24')][_0x9cb088('0x32')]=_0xd1f858['body'][_0x9cb088('0x32')]||_0xd1f858[_0x9cb088('0x5e')]['id'],db[_0x9cb088('0x54')][_0x9cb088('0x12')]({'where':{'id':_0xd1f858['params']['id'],'UserId':null},'include':[{'model':db[_0x9cb088('0x41')],'as':_0x9cb088('0x56')}]})[_0x9cb088('0x15')](handleEntityNotFound(_0x558737,null))[_0x9cb088('0x15')](saveUpdates(_0xd1f858['body'],null))['then'](function(_0x19eb53){const _0x3517d4=_0x9cb088;if(_0x19eb53)return _0x1796aa[_0x3517d4('0x18')]=_0x19eb53['get']({'plain':!![]}),db[_0x3517d4('0x59')][_0x3517d4('0x12')]({'where':{'id':_0x19eb53[_0x3517d4('0x9')]}});return null;})[_0x9cb088('0x15')](handleEntityNotFound(_0x558737,null))['then'](function(_0x5628ca){const _0x2e2391=_0x9cb088;if(_0x5628ca)return _0x5628ca[_0x2e2391('0x42')]({'UserId':_0xd1f858['body'][_0x2e2391('0x32')],'read1stAt':_[_0x2e2391('0xf')](_0x5628ca[_0x2e2391('0x50')])?moment()[_0x2e2391('0x47')](_0x2e2391('0x52')):undefined});return null;})[_0x9cb088('0x15')](function(_0x4e9056){const _0x5113db=_0x9cb088;if(_0x4e9056)return _0x1796aa[_0x5113db('0x2f')]=_0x4e9056[_0x5113db('0x1a')]({'plain':!![]}),interaction_log[_0x5113db('0x14')](_0x5113db('0x63'),_0xd1f858[_0x5113db('0x5e')]['id'],_0xd1f858[_0x5113db('0x5e')][_0x5113db('0x6b')],_0xd1f858[_0x5113db('0x5e')][_0x5113db('0x43')],_0x1796aa[_0x5113db('0x2f')]['id'],_0xd1f858['body']?JSON[_0x5113db('0x4d')](_0xd1f858['body']):_0x5113db('0x1d')),respondWithRpcPromise(_0x5113db('0x2a'),_0x5113db('0x3f'),_0x1796aa);return null;})[_0x9cb088('0x15')](function(_0x2119a8){const _0x503367=_0x9cb088;if(_0x2119a8){if(_0xd1f858[_0x503367('0x24')]['manual'])return _0x1796aa[_0x503367('0x18')][_0x503367('0x69')]=util[_0x503367('0x47')]('SIP/%s',_0xd1f858[_0x503367('0x5e')][_0x503367('0x6b')]),_0x1796aa['message'][_0x503367('0x35')]=_0x1796aa[_0x503367('0x35')],_0x1796aa[_0x503367('0x18')][_0x503367('0xa')]=_0x503367('0x3a'),respondWithRpcPromise(_0x503367('0x22'),_0x503367('0x22'),{'event':'acceptmessage','message':_0x1796aa[_0x503367('0x18')]},client9002)[_0x503367('0x15')](function(){return _0x1796aa;});return _0x1796aa;}return null;})[_0x9cb088('0x15')](respondWithResult(_0x558737,null))[_0x9cb088('0x60')](handleError(_0x558737,null));},exports[_0x551220('0x53')]=function(_0x4fc9df,_0x55521f){const _0x172379=_0x551220,_0x46de10={'agent':{},'channel':_0x172379('0x6d')};return _0x4fc9df[_0x172379('0x24')]['id']&&delete _0x4fc9df[_0x172379('0x24')]['id'],_0x4fc9df[_0x172379('0x24')][_0x172379('0x32')]=_0x4fc9df[_0x172379('0x24')]['UserId']||_0x4fc9df['user']['id'],_0x46de10[_0x172379('0x38')]['id']=_0x4fc9df['body'][_0x172379('0x32')],db[_0x172379('0x54')][_0x172379('0x12')]({'where':{'id':_0x4fc9df[_0x172379('0x29')]['id'],'UserId':null}})[_0x172379('0x15')](handleEntityNotFound(_0x55521f,null))[_0x172379('0x15')](function(_0x14e7f2){const _0x39ecb4=_0x172379;if(_0x14e7f2)return _0x46de10[_0x39ecb4('0x18')]=_0x14e7f2[_0x39ecb4('0x1a')]({'plain':!![]}),db[_0x39ecb4('0x59')][_0x39ecb4('0x12')]({'where':{'id':_0x14e7f2[_0x39ecb4('0x9')]}});return null;})[_0x172379('0x15')](handleEntityNotFound(_0x55521f,null))[_0x172379('0x15')](function(_0x288a63){const _0x487789=_0x172379;if(_0x288a63)return _0x46de10[_0x487789('0x2f')]=_0x288a63['get']({'plain':!![]}),interaction_log[_0x487789('0x14')]('[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x4fc9df[_0x487789('0x5e')]['id'],_0x4fc9df['user']['name'],_0x4fc9df['user'][_0x487789('0x43')],_0x46de10[_0x487789('0x2f')]['id'],_0x4fc9df['body']?JSON[_0x487789('0x4d')](_0x4fc9df[_0x487789('0x24')]):_0x487789('0x1d')),respondWithRpcPromise('RejectMessage',_0x487789('0x68'),_0x46de10);return null;})['then'](function(_0x49ecd7){const _0xe3b831=_0x172379;if(_0x49ecd7)return _0x49ecd7[_0xe3b831('0x18')][_0xe3b831('0x69')]=util[_0xe3b831('0x47')]('SIP/%s',_0x4fc9df[_0xe3b831('0x5e')][_0xe3b831('0x6b')]),_0x49ecd7['message']['channel']=_0x46de10['channel'],_0x49ecd7['message'][_0xe3b831('0xa')]='reject',respondWithRpcPromise('EventManager',_0xe3b831('0x22'),{'event':_0xe3b831('0x65'),'message':_0x49ecd7[_0xe3b831('0x18')]},client9002),_0x46de10;return null;})['then'](respondWithResult(_0x55521f,null))[_0x172379('0x60')](handleError(_0x55521f,null));},exports[_0x551220('0x40')]=function(_0x2cdfa8,_0x2c1b3b){const _0x3163d9=_0x551220;_0x2cdfa8[_0x3163d9('0x24')]['id']&&delete _0x2cdfa8[_0x3163d9('0x24')]['id'];let _0x49d454;return db[_0x3163d9('0x54')][_0x3163d9('0x12')]({'where':{'id':_0x2cdfa8['params']['id']}})[_0x3163d9('0x15')](handleEntityNotFound(_0x2c1b3b,null))['then'](function(_0x196f44){const _0x79b357=_0x3163d9;if(_0x196f44)return _0x49d454=_0x196f44,db[_0x79b357('0x2c')][_0x79b357('0x12')]({'where':{'id':_0x196f44[_0x79b357('0x25')]}});})[_0x3163d9('0x15')](handleEntityNotFound(_0x2c1b3b,null))['then'](function(_0x3dddd7){const _0x5b5af6=_0x3163d9;if(_0x3dddd7){logger[_0x5b5af6('0x66')](_0x5b5af6('0x4a'),_0x5b5af6('0x40'),_0x5b5af6('0x49'),_0x3dddd7[_0x5b5af6('0x3b')],util[_0x5b5af6('0x51')](_0x2cdfa8[_0x5b5af6('0x24')],{'showHidden':![],'depth':null}));switch(_0x3dddd7[_0x5b5af6('0x3b')]){case _0x5b5af6('0x2b'):if(_0x2cdfa8[_0x5b5af6('0x24')][_0x5b5af6('0x45')]&&_0x2cdfa8[_0x5b5af6('0x24')]['MessageSid']===_0x49d454[_0x5b5af6('0x57')]&&_0x2cdfa8['body'][_0x5b5af6('0x21')]&&_0x2cdfa8[_0x5b5af6('0x24')]['MessageStatus']===_0x5b5af6('0x36'))return _0x49d454[_0x5b5af6('0x42')]({'read':!![]});else logger['error'](_0x5b5af6('0x3d'),_0x5b5af6('0x40'),_0x5b5af6('0x2b'),util[_0x5b5af6('0x51')](_0x2cdfa8[_0x5b5af6('0x24')],{'showHidden':![],'depth':null}));break;}return _0x49d454;}})['then'](respondWithResult(_0x2c1b3b,null))[_0x3163d9('0x60')](handleError(_0x2c1b3b,null));};
\ No newline at end of file