Built motion from commit b0a9a629.|2.6.33
[motion2.git] / server / components / interaction / accept-message.js
index 17ef7ef..08be90d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xbc01=['APINotFoundError','../../config/logger','api','http','info','%s,\x20%s,\x20%s','debug','%s,\x20%s,\x20%s,\x20%s','error','code','message','request\x20sent','user','get','read','YYYY-MM-DD\x20HH:mm:ss','UserId','getAcceptParams','capitalize','findOne','then','Message\x20with\x20id\x20','\x20not\x20found','update','updateMessageById','Interaction','Interaction\x20with\x20id\x20','read1stAt','format','updateInteractionById','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','sequelize','query','QueryTypes','SELECT','Contact\x20with\x20id\x20','findContactById','User','agent','fullname','email','internal','chat','ChatInteractionId','fax','FaxInteractionId','mail','MailInteractionId','openchannel','OpenchannelInteractionId','sms','SmsInteractionId','WhatsappInteractionId','min','col','isNewInteraction','assign','parse','interaction','EventManager','acceptmessage','Message','AcceptMessage','acceptMessage','sendRoutingAcceptEvent','newinteraction','opened','sendInteractionOpenedEvent','lodash','../../mysqldb','../../errors/api'];(function(_0x132641,_0x153b24){var _0xc68b80=function(_0x14dd35){while(--_0x14dd35){_0x132641['push'](_0x132641['shift']());}};_0xc68b80(++_0x153b24);}(_0xbc01,0xd2));var _0x1bc0=function(_0x17be21,_0x311a25){_0x17be21=_0x17be21-0x0;var _0x4cbc37=_0xbc01[_0x17be21];return _0x4cbc37;};'use strict';var _=require(_0x1bc0('0x0'));var moment=require('moment');var jayson=require('jayson/promise');var db=require(_0x1bc0('0x1'))['db'];var APINotFoundError=require(_0x1bc0('0x2'))[_0x1bc0('0x3')];var logger=require(_0x1bc0('0x4'))(_0x1bc0('0x5'));var rpcAmiClient=jayson['client'][_0x1bc0('0x6')]({'port':0x232a});var rpcRoutingClient=jayson['client']['http']({'port':0x232c});function respondWithRpcPromise(_0x3b968a,_0x22d72c,_0x1972dc,_0x371851,_0x2e9e0d){return new Promise(function(_0x1a96a4,_0x53e05e){return _0x2e9e0d['request'](_0x22d72c,_0x371851)['then'](function(_0xbb47f8){logger[_0x1bc0('0x7')](_0x1bc0('0x8'),_0x3b968a,_0x1972dc,'request\x20sent');logger[_0x1bc0('0x9')](_0x1bc0('0xa'),_0x3b968a,_0x1972dc,'request\x20sent',JSON['stringify'](_0xbb47f8));if(_0xbb47f8[_0x1bc0('0xb')]){if(_0xbb47f8[_0x1bc0('0xb')][_0x1bc0('0xc')]===0x1f4){logger[_0x1bc0('0xb')]('%s,\x20%s,\x20%s',_0x3b968a,_0x1972dc,_0xbb47f8['error'][_0x1bc0('0xd')]);return _0x53e05e(_0xbb47f8['error']['message']);}logger[_0x1bc0('0xb')](_0x1bc0('0x8'),_0x3b968a,_0x1972dc,_0xbb47f8['error']['message']);return _0x1a96a4(_0xbb47f8['error'][_0x1bc0('0xd')]);}else{logger['info'](_0x1bc0('0x8'),_0x3b968a,_0x1972dc,_0x1bc0('0xe'));_0x1a96a4(_0xbb47f8['result']['message']);}})['catch'](function(_0x1b5a58){logger[_0x1bc0('0xb')](_0x1bc0('0x8'),_0x3b968a,_0x1972dc,_0x1b5a58);_0x53e05e(_0x1b5a58);});});}function getAcceptParams(_0x2b44d8){var _0x4db893=_0x2b44d8['params']['id'];var _0x10aaff=_0x2b44d8['body'];delete _0x10aaff['id'];var _0x4ed4a2=_0x2b44d8[_0x1bc0('0xf')][_0x1bc0('0x10')]({'plain':!![]});_0x10aaff[_0x1bc0('0x11')]=!![];_0x10aaff['readAt']=moment()['format'](_0x1bc0('0x12'));_0x10aaff[_0x1bc0('0x13')]=_0x10aaff['UserId']||_0x4ed4a2['id'];return{'messageId':_0x4db893,'payload':_0x10aaff,'user':_0x4ed4a2};}exports[_0x1bc0('0x14')]=getAcceptParams;function updateMessageById(_0xa9e857,_0x540b53,_0x5538d1){var _0x14ce8c=_[_0x1bc0('0x15')](_0xa9e857)+'Message';return db[_0x14ce8c][_0x1bc0('0x16')]({'where':{'id':_0x540b53,'UserId':null}})[_0x1bc0('0x17')](function(_0x50526b){if(!_0x50526b){throw new APINotFoundError(_0x1bc0('0x18')+_0x540b53+_0x1bc0('0x19'));}return _0x50526b[_0x1bc0('0x1a')](_0x5538d1);})[_0x1bc0('0x17')](function(_0x172a7d){return _0x172a7d[_0x1bc0('0x10')]({'plain':!![]});});}exports[_0x1bc0('0x1b')]=updateMessageById;function updateInteractionById(_0x211405,_0x54c123,_0x4c86c0){var _0x42e201=_['capitalize'](_0x211405)+_0x1bc0('0x1c');return db[_0x42e201][_0x1bc0('0x16')]({'where':{'id':_0x54c123}})['then'](function(_0x245f0f){if(!_0x245f0f){throw new APINotFoundError(_0x1bc0('0x1d')+_0x54c123+_0x1bc0('0x19'));}var _0x5091b1=_0x245f0f[_0x1bc0('0x1e')]||moment()[_0x1bc0('0x1f')]('YYYY-MM-DD\x20HH:mm:ss');return _0x245f0f['update']({'UserId':_0x4c86c0,'read1stAt':_0x5091b1});})['then'](function(_0x2e4343){return _0x2e4343['get']({'plain':!![]});});}exports[_0x1bc0('0x20')]=updateInteractionById;function findContactById(_0x644fa6){var _0xd2ab38=_0x1bc0('0x21')+_0x644fa6;return db[_0x1bc0('0x22')][_0x1bc0('0x23')](_0xd2ab38,{'type':db[_0x1bc0('0x22')][_0x1bc0('0x24')][_0x1bc0('0x25')],'raw':!![]})[_0x1bc0('0x17')](function(_0x2813c2){if(_0x2813c2['length']===0x0){throw new APINotFoundError(_0x1bc0('0x26')+_0x644fa6+_0x1bc0('0x19'));}return _0x2813c2[0x0];});}exports[_0x1bc0('0x27')]=findContactById;function findAgentById(_0x31206b){return db[_0x1bc0('0x28')][_0x1bc0('0x16')]({'where':{'id':_0x31206b,'role':_0x1bc0('0x29')},'attributes':['id','name',_0x1bc0('0x2a'),_0x1bc0('0x2b'),_0x1bc0('0x2c')],'raw':!![]});}exports['findAgentById']=findAgentById;function isNewInteraction(_0x2216fe,_0x26347a,_0x3939c4){var _0x16686d=_[_0x1bc0('0x15')](_0x2216fe)+'Message';var _0x32f838={};switch(_0x2216fe){case _0x1bc0('0x2d'):_0x32f838[_0x1bc0('0x2e')]=_0x26347a;break;case _0x1bc0('0x2f'):_0x32f838[_0x1bc0('0x30')]=_0x26347a;break;case _0x1bc0('0x31'):_0x32f838[_0x1bc0('0x32')]=_0x26347a;break;case _0x1bc0('0x33'):_0x32f838[_0x1bc0('0x34')]=_0x26347a;break;case _0x1bc0('0x35'):_0x32f838[_0x1bc0('0x36')]=_0x26347a;break;case'whatsapp':_0x32f838[_0x1bc0('0x37')]=_0x26347a;break;}return db[_0x16686d]['findOne']({'where':_0x32f838,'attributes':[[db['sequelize']['fn'](_0x1bc0('0x38'),db['sequelize'][_0x1bc0('0x39')]('id')),'id']],'raw':!![]})[_0x1bc0('0x17')](function(_0x118913){return _0x3939c4===_0x118913['id'];});}exports[_0x1bc0('0x3a')]=isNewInteraction;function sendAmiAcceptEvent(_0x397e4f,_0x1678ab){var _0x5b7aad=_[_0x1bc0('0x15')](_0x397e4f)+'Message';var _0x3a851c=_0x1678ab[_0x1bc0('0xd')];if(_0x397e4f==='chat'){Object[_0x1bc0('0x3b')](_0x3a851c,JSON[_0x1bc0('0x3c')](_0x1678ab[_0x1bc0('0x3d')]['formData']));}return respondWithRpcPromise(_0x5b7aad,_0x1bc0('0x3e'),_0x1bc0('0x3e'),{'event':_0x1bc0('0x3f'),'message':_0x3a851c},rpcAmiClient);}exports['sendAmiAcceptEvent']=sendAmiAcceptEvent;function sendRoutingAcceptEvent(_0x4131c0,_0x4d80f9){var _0x483395=_[_0x1bc0('0x15')](_0x4131c0)+_0x1bc0('0x40');return respondWithRpcPromise(_0x483395,_0x1bc0('0x41'),_0x1bc0('0x42'),_0x4d80f9,rpcRoutingClient);}exports[_0x1bc0('0x43')]=sendRoutingAcceptEvent;function sendInteractionOpenedEvent(_0x3ca4e8,_0x2976eb){var _0x502272=_['capitalize'](_0x3ca4e8)+_0x1bc0('0x40');return respondWithRpcPromise(_0x502272,_0x1bc0('0x3e'),_0x1bc0('0x3e'),{'event':_0x1bc0('0x44'),'message':Object['assign']({},_0x2976eb,{'event':_0x1bc0('0x45')})},rpcAmiClient);}exports[_0x1bc0('0x46')]=sendInteractionOpenedEvent;
\ No newline at end of file
+var _0xbf07=['EventManager','acceptmessage','sendAmiAcceptEvent','AcceptMessage','acceptMessage','sendRoutingAcceptEvent','newinteraction','sendInteractionOpenedEvent','../../mysqldb','../../errors/api','APINotFoundError','../../config/logger','api','client','http','then','info','%s,\x20%s,\x20%s','request\x20sent','debug','%s,\x20%s,\x20%s,\x20%s','code','error','message','catch','params','user','get','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','getAcceptParams','capitalize','findOne','Message\x20with\x20id\x20','\x20not\x20found','updateMessageById','Interaction','Interaction\x20with\x20id\x20','read1stAt','updateInteractionById','sequelize','query','QueryTypes','SELECT','length','Contact\x20with\x20id\x20','findContactById','name','fullname','internal','findAgentById','Message','chat','fax','mail','openchannel','OpenchannelInteractionId','sms','SmsInteractionId','WhatsappInteractionId','min','col','isNewInteraction','parse','interaction','formData'];(function(_0x209bbf,_0x2e2375){var _0x592d4b=function(_0x419947){while(--_0x419947){_0x209bbf['push'](_0x209bbf['shift']());}};_0x592d4b(++_0x2e2375);}(_0xbf07,0x92));var _0x7bf0=function(_0x2afbb0,_0x44f16d){_0x2afbb0=_0x2afbb0-0x0;var _0x411ff2=_0xbf07[_0x2afbb0];return _0x411ff2;};'use strict';var _=require('lodash');var moment=require('moment');var jayson=require('jayson/promise');var db=require(_0x7bf0('0x0'))['db'];var APINotFoundError=require(_0x7bf0('0x1'))[_0x7bf0('0x2')];var logger=require(_0x7bf0('0x3'))(_0x7bf0('0x4'));var rpcAmiClient=jayson[_0x7bf0('0x5')][_0x7bf0('0x6')]({'port':0x232a});var rpcRoutingClient=jayson[_0x7bf0('0x5')][_0x7bf0('0x6')]({'port':0x232c});function respondWithRpcPromise(_0xedc5bc,_0x27dd57,_0x5a8a9b,_0x279959,_0x2a40b4){return new Promise(function(_0xfe395b,_0x1c0632){return _0x2a40b4['request'](_0x27dd57,_0x279959)[_0x7bf0('0x7')](function(_0xb3c59d){logger[_0x7bf0('0x8')](_0x7bf0('0x9'),_0xedc5bc,_0x5a8a9b,_0x7bf0('0xa'));logger[_0x7bf0('0xb')](_0x7bf0('0xc'),_0xedc5bc,_0x5a8a9b,'request\x20sent',JSON['stringify'](_0xb3c59d));if(_0xb3c59d['error']){if(_0xb3c59d['error'][_0x7bf0('0xd')]===0x1f4){logger[_0x7bf0('0xe')]('%s,\x20%s,\x20%s',_0xedc5bc,_0x5a8a9b,_0xb3c59d[_0x7bf0('0xe')][_0x7bf0('0xf')]);return _0x1c0632(_0xb3c59d[_0x7bf0('0xe')][_0x7bf0('0xf')]);}logger[_0x7bf0('0xe')](_0x7bf0('0x9'),_0xedc5bc,_0x5a8a9b,_0xb3c59d[_0x7bf0('0xe')][_0x7bf0('0xf')]);return _0xfe395b(_0xb3c59d[_0x7bf0('0xe')][_0x7bf0('0xf')]);}else{logger[_0x7bf0('0x8')](_0x7bf0('0x9'),_0xedc5bc,_0x5a8a9b,'request\x20sent');_0xfe395b(_0xb3c59d['result'][_0x7bf0('0xf')]);}})[_0x7bf0('0x10')](function(_0x2ef9e9){logger['error'](_0x7bf0('0x9'),_0xedc5bc,_0x5a8a9b,_0x2ef9e9);_0x1c0632(_0x2ef9e9);});});}function getAcceptParams(_0x154d50){var _0x7e08ac=_0x154d50[_0x7bf0('0x11')]['id'];var _0x1a10a4=_0x154d50['body'];delete _0x1a10a4['id'];var _0x3a1cf0=_0x154d50[_0x7bf0('0x12')][_0x7bf0('0x13')]({'plain':!![]});_0x1a10a4[_0x7bf0('0x14')]=!![];_0x1a10a4[_0x7bf0('0x15')]=moment()[_0x7bf0('0x16')](_0x7bf0('0x17'));_0x1a10a4[_0x7bf0('0x18')]=_0x1a10a4[_0x7bf0('0x18')]||_0x3a1cf0['id'];return{'messageId':_0x7e08ac,'payload':_0x1a10a4,'user':_0x3a1cf0};}exports[_0x7bf0('0x19')]=getAcceptParams;function updateMessageById(_0x54356f,_0x5c41e7,_0x5a332a){var _0x5339c6=_[_0x7bf0('0x1a')](_0x54356f)+'Message';return db[_0x5339c6][_0x7bf0('0x1b')]({'where':{'id':_0x5c41e7,'UserId':null}})[_0x7bf0('0x7')](function(_0x52eca5){if(!_0x52eca5){throw new APINotFoundError(_0x7bf0('0x1c')+_0x5c41e7+_0x7bf0('0x1d'));}return _0x52eca5['update'](_0x5a332a);})['then'](function(_0xcb9281){return _0xcb9281[_0x7bf0('0x13')]({'plain':!![]});});}exports[_0x7bf0('0x1e')]=updateMessageById;function updateInteractionById(_0x12423d,_0x2f2a18,_0xda04c2){var _0x4c10dd=_[_0x7bf0('0x1a')](_0x12423d)+_0x7bf0('0x1f');return db[_0x4c10dd][_0x7bf0('0x1b')]({'where':{'id':_0x2f2a18}})[_0x7bf0('0x7')](function(_0xeb9d7d){if(!_0xeb9d7d){throw new APINotFoundError(_0x7bf0('0x20')+_0x2f2a18+'\x20not\x20found');}var _0x4f4ec9=_0xeb9d7d[_0x7bf0('0x21')]||moment()['format'](_0x7bf0('0x17'));return _0xeb9d7d['update']({'UserId':_0xda04c2,'read1stAt':_0x4f4ec9});})[_0x7bf0('0x7')](function(_0xe7931a){return _0xe7931a[_0x7bf0('0x13')]({'plain':!![]});});}exports[_0x7bf0('0x22')]=updateInteractionById;function findContactById(_0x180425){var _0xbd19a2='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x180425;return db[_0x7bf0('0x23')][_0x7bf0('0x24')](_0xbd19a2,{'type':db[_0x7bf0('0x23')][_0x7bf0('0x25')][_0x7bf0('0x26')],'raw':!![]})[_0x7bf0('0x7')](function(_0x12d750){if(_0x12d750[_0x7bf0('0x27')]===0x0){throw new APINotFoundError(_0x7bf0('0x28')+_0x180425+_0x7bf0('0x1d'));}return _0x12d750[0x0];});}exports[_0x7bf0('0x29')]=findContactById;function findAgentById(_0xeab2af){return db['User'][_0x7bf0('0x1b')]({'where':{'id':_0xeab2af,'role':'agent'},'attributes':['id',_0x7bf0('0x2a'),_0x7bf0('0x2b'),'email',_0x7bf0('0x2c')],'raw':!![]});}exports[_0x7bf0('0x2d')]=findAgentById;function isNewInteraction(_0x30e364,_0x31fcf9,_0x2dc69a){var _0x2ee4df=_['capitalize'](_0x30e364)+_0x7bf0('0x2e');var _0xbb5e05={};switch(_0x30e364){case _0x7bf0('0x2f'):_0xbb5e05['ChatInteractionId']=_0x31fcf9;break;case _0x7bf0('0x30'):_0xbb5e05['FaxInteractionId']=_0x31fcf9;break;case _0x7bf0('0x31'):_0xbb5e05['MailInteractionId']=_0x31fcf9;break;case _0x7bf0('0x32'):_0xbb5e05[_0x7bf0('0x33')]=_0x31fcf9;break;case _0x7bf0('0x34'):_0xbb5e05[_0x7bf0('0x35')]=_0x31fcf9;break;case'whatsapp':_0xbb5e05[_0x7bf0('0x36')]=_0x31fcf9;break;}return db[_0x2ee4df]['findOne']({'where':_0xbb5e05,'attributes':[[db[_0x7bf0('0x23')]['fn'](_0x7bf0('0x37'),db['sequelize'][_0x7bf0('0x38')]('id')),'id']],'raw':!![]})[_0x7bf0('0x7')](function(_0x3afb5b){return _0x2dc69a===_0x3afb5b['id'];});}exports[_0x7bf0('0x39')]=isNewInteraction;function sendAmiAcceptEvent(_0x512ddf,_0x3ebe14){var _0x753f43=_[_0x7bf0('0x1a')](_0x512ddf)+_0x7bf0('0x2e');var _0x3ab51c=_0x3ebe14['message'];if(_0x512ddf===_0x7bf0('0x2f')){Object['assign'](_0x3ab51c,JSON[_0x7bf0('0x3a')](_0x3ebe14[_0x7bf0('0x3b')][_0x7bf0('0x3c')]));}return respondWithRpcPromise(_0x753f43,_0x7bf0('0x3d'),_0x7bf0('0x3d'),{'event':_0x7bf0('0x3e'),'message':_0x3ab51c},rpcAmiClient);}exports[_0x7bf0('0x3f')]=sendAmiAcceptEvent;function sendRoutingAcceptEvent(_0x168026,_0xc4db2e){var _0x4adcf4=_['capitalize'](_0x168026)+'Message';return respondWithRpcPromise(_0x4adcf4,_0x7bf0('0x40'),_0x7bf0('0x41'),_0xc4db2e,rpcRoutingClient);}exports[_0x7bf0('0x42')]=sendRoutingAcceptEvent;function sendInteractionOpenedEvent(_0x1984b5,_0x42503e){var _0xbd4f2d=_[_0x7bf0('0x1a')](_0x1984b5)+_0x7bf0('0x2e');return respondWithRpcPromise(_0xbd4f2d,'EventManager','EventManager',{'event':_0x7bf0('0x43'),'message':Object['assign']({},_0x42503e,{'event':'opened'})},rpcAmiClient);}exports[_0x7bf0('0x44')]=sendInteractionOpenedEvent;
\ No newline at end of file