Built motion from commit eddce310.|2.6.12
[motion2.git] / server / services / routing / server / applications / amazonlex.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 _0xc756=['[%s][AMAZONLEX]\x20%s','body','catch','error','stringify','finally','[%s][AMAZONLEX]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','[%s][AMAZONLEX]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','LexRuntime','$LATEST','message','toString','postText','next','amazonlex','dialogState','Failed','moment','aws-sdk','./utils','routing','../../rpc/chatMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','consequence','isNil','interaction','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','whatsapp','phone','channel','chat','account','upperFirst','InteractionId','created','isEmpty','Message','then','info'];(function(_0x48f827,_0x269e8d){var _0xc763f7=function(_0x19769a){while(--_0x19769a){_0x48f827['push'](_0x48f827['shift']());}};_0xc763f7(++_0x269e8d);}(_0xc756,0x154));var _0x6c75=function(_0x3b71ba,_0x26ccbc){_0x3b71ba=_0x3b71ba-0x0;var _0x34acdd=_0xc756[_0x3b71ba];return _0x34acdd;};'use strict';var _=require('lodash');var moment=require(_0x6c75('0x0'));var AWS=require(_0x6c75('0x1'));var utils=require(_0x6c75('0x2'));var logger=require('../../../../config/logger')(_0x6c75('0x3'));var rpc={'chatMessage':require(_0x6c75('0x4')),'openchannelMessage':require('../../rpc/openchannelMessage'),'mailMessage':require(_0x6c75('0x5')),'smsMessage':require(_0x6c75('0x6')),'faxMessage':require(_0x6c75('0x7')),'whatsappMessage':require(_0x6c75('0x8'))};exports[_0x6c75('0x9')]=function(_0x27446c,_0x86b38){return function(_0x32bffc){try{if(!_[_0x6c75('0xa')](this[_0x6c75('0xb')]['UserId'])){logger['info']('[%s][AMAZONLEX]\x20%s',_0x27446c,'Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.');return _0x32bffc['next']();}var _0x1f0aa4={'ContactId':this[_0x6c75('0xc')]['id'],'sentAt':moment()[_0x6c75('0xd')](_0x6c75('0xe')),'direction':_0x6c75('0xf')};if(this['channel']==='sms'||this['channel']===_0x6c75('0x10')){_0x1f0aa4['phone']=this['interaction'][_0x6c75('0x11')];}var _0x253ceb=this[_0x6c75('0x12')];if(_0x253ceb===_0x6c75('0x13')){_0x1f0aa4['ChatWebsiteId']=this[_0x6c75('0x14')]['id'];}else{_0x1f0aa4[_['upperFirst'](_0x253ceb)+'AccountId']=this[_0x6c75('0x14')]['id'];}_0x1f0aa4[_[_0x6c75('0x15')](_0x253ceb)+_0x6c75('0x16')]=this[_0x6c75('0xb')]['id'];if(this[_0x6c75('0xb')][_0x6c75('0x17')]){var _0x163aba=_0x86b38[0x4];if(!_[_0x6c75('0x18')](_0x163aba)){_0x1f0aa4['body']=utils['getMustacheRender'](_0x163aba,this);return rpc[_0x253ceb+_0x6c75('0x19')]['create'](_0x1f0aa4)[_0x6c75('0x1a')](function(_0x2459f7){logger[_0x6c75('0x1b')](_0x6c75('0x1c'),_0x27446c,_0x1f0aa4[_0x6c75('0x1d')]);})[_0x6c75('0x1e')](function(_0x4dba2f){logger[_0x6c75('0x1f')](_0x6c75('0x1c'),_0x27446c,JSON[_0x6c75('0x20')](_0x4dba2f));})[_0x6c75('0x21')](function(){logger[_0x6c75('0x1b')](_0x6c75('0x22'),_0x27446c);_0x32bffc[_0x6c75('0x23')]();});}else{logger[_0x6c75('0x1b')](_0x6c75('0x24'),_0x27446c);_0x32bffc[_0x6c75('0x23')]();}}else{var _0x449ffe=this;var _0x5b3e82=new AWS[(_0x6c75('0x25'))]({'accessKeyId':_0x86b38[0x0],'secretAccessKey':_0x86b38[0x1],'region':_0x86b38[0x2]});var _0x374952={'botAlias':_0x6c75('0x26'),'botName':_0x86b38[0x3],'inputText':this[_0x6c75('0x27')][_0x6c75('0x1d')],'userId':this[_0x6c75('0x12')]+':'+this[_0x6c75('0xb')]['id'][_0x6c75('0x28')]()};_0x5b3e82[_0x6c75('0x29')](_0x374952,function(_0xc9a0a8,_0x1af68f){if(_0xc9a0a8){logger[_0x6c75('0x1f')](_0x6c75('0x1c'),_0x27446c,_0xc9a0a8['message']);_0x32bffc[_0x6c75('0x2a')]();}else if(_0x1af68f&&_0x1af68f[_0x6c75('0x27')]){_0x449ffe['body']['amazonlex']=_0x1af68f;_0x1f0aa4[_0x6c75('0x1d')]=_0x1af68f[_0x6c75('0x27')];_0x1f0aa4['providerName']=_0x6c75('0x2b');_0x1f0aa4['providerResponse']=JSON[_0x6c75('0x20')](_0x1af68f);return rpc[_0x253ceb+_0x6c75('0x19')]['create'](_0x1f0aa4)['then'](function(_0x56b0c7){logger['info'](_0x6c75('0x1c'),_0x27446c,_0x1f0aa4[_0x6c75('0x1d')]);if(_0x1af68f[_0x6c75('0x2c')]==_0x6c75('0x2d')){_0x32bffc[_0x6c75('0x2a')]();}else{_0x32bffc[_0x6c75('0x23')]();}})['catch'](function(_0x22173f){logger['error']('[%s][AMAZONLEX]\x20%s',_0x27446c,JSON[_0x6c75('0x20')](_0x22173f));_0x32bffc[_0x6c75('0x2a')]();});}else{_0x32bffc['next']();}});}}catch(_0x433fef){logger[_0x6c75('0x1f')](_0x6c75('0x1c'),_0x27446c,JSON['stringify'](_0x433fef));_0x32bffc['stop']();}};};