2a693958f5be2b2f7ea732e8cfcb4b631debd88b
[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 _0xfc4d=['getMustacheRender','create','then','body','error','stringify','stop','[%s][AMAZONLEX]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','LexRuntime','$LATEST','message','toString','amazonlex','providerName','providerResponse','Message','dialogState','Failed','catch','lodash','moment','aws-sdk','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/whatsappMessage','consequence','isNil','interaction','UserId','info','[%s][AMAZONLEX]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','contact','format','out','sms','whatsapp','phone','channel','chat','ChatWebsiteId','account','upperFirst','InteractionId','isEmpty'];(function(_0x497123,_0x14b6a8){var _0x5e5f40=function(_0x425605){while(--_0x425605){_0x497123['push'](_0x497123['shift']());}};_0x5e5f40(++_0x14b6a8);}(_0xfc4d,0x79));var _0xdfc4=function(_0x386b69,_0x5d9360){_0x386b69=_0x386b69-0x0;var _0x476415=_0xfc4d[_0x386b69];return _0x476415;};'use strict';var _=require(_0xdfc4('0x0'));var moment=require(_0xdfc4('0x1'));var AWS=require(_0xdfc4('0x2'));var utils=require(_0xdfc4('0x3'));var logger=require(_0xdfc4('0x4'))(_0xdfc4('0x5'));var rpc={'chatMessage':require(_0xdfc4('0x6')),'openchannelMessage':require(_0xdfc4('0x7')),'mailMessage':require(_0xdfc4('0x8')),'smsMessage':require(_0xdfc4('0x9')),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require(_0xdfc4('0xa'))};exports[_0xdfc4('0xb')]=function(_0x2848a9,_0x1500a4){return function(_0x5e2c1f){try{if(!_[_0xdfc4('0xc')](this[_0xdfc4('0xd')][_0xdfc4('0xe')])){logger[_0xdfc4('0xf')](_0xdfc4('0x10'),_0x2848a9,_0xdfc4('0x11'));return _0x5e2c1f[_0xdfc4('0x12')]();}var _0x140a08={'ContactId':this[_0xdfc4('0x13')]['id'],'sentAt':moment()[_0xdfc4('0x14')]('YYYY-MM-DD\x20HH:mm:ss'),'direction':_0xdfc4('0x15')};if(this['channel']===_0xdfc4('0x16')||this['channel']===_0xdfc4('0x17')){_0x140a08[_0xdfc4('0x18')]=this[_0xdfc4('0xd')][_0xdfc4('0x18')];}var _0x52ae9f=this[_0xdfc4('0x19')];if(_0x52ae9f===_0xdfc4('0x1a')){_0x140a08[_0xdfc4('0x1b')]=this[_0xdfc4('0x1c')]['id'];}else{_0x140a08[_[_0xdfc4('0x1d')](_0x52ae9f)+'AccountId']=this[_0xdfc4('0x1c')]['id'];}_0x140a08[_['upperFirst'](_0x52ae9f)+_0xdfc4('0x1e')]=this[_0xdfc4('0xd')]['id'];if(this[_0xdfc4('0xd')]['created']){var _0x41d962=_0x1500a4[0x4];if(!_[_0xdfc4('0x1f')](_0x41d962)){_0x140a08['body']=utils[_0xdfc4('0x20')](_0x41d962,this);return rpc[_0x52ae9f+'Message'][_0xdfc4('0x21')](_0x140a08)[_0xdfc4('0x22')](function(_0x211e3f){logger[_0xdfc4('0xf')]('[%s][AMAZONLEX]\x20%s',_0x2848a9,_0x140a08[_0xdfc4('0x23')]);})['catch'](function(_0x3063a4){logger[_0xdfc4('0x24')]('[%s][AMAZONLEX]\x20%s',_0x2848a9,JSON[_0xdfc4('0x25')](_0x3063a4));})['finally'](function(){logger[_0xdfc4('0xf')]('[%s][AMAZONLEX]\x20Welcome\x20Message\x20has\x20been\x20sent!',_0x2848a9);_0x5e2c1f[_0xdfc4('0x26')]();});}else{logger['info'](_0xdfc4('0x27'),_0x2848a9);_0x5e2c1f[_0xdfc4('0x26')]();}}else{var _0x58f78f=this;var _0x4a8921=new AWS[(_0xdfc4('0x28'))]({'accessKeyId':_0x1500a4[0x0],'secretAccessKey':_0x1500a4[0x1],'region':_0x1500a4[0x2]});var _0x3df092={'botAlias':_0xdfc4('0x29'),'botName':_0x1500a4[0x3],'inputText':this[_0xdfc4('0x2a')][_0xdfc4('0x23')],'userId':this[_0xdfc4('0x19')]+':'+this['interaction']['id'][_0xdfc4('0x2b')]()};_0x4a8921['postText'](_0x3df092,function(_0x2774c8,_0x4f7a92){if(_0x2774c8){logger[_0xdfc4('0x24')](_0xdfc4('0x10'),_0x2848a9,_0x2774c8[_0xdfc4('0x2a')]);_0x5e2c1f[_0xdfc4('0x12')]();}else if(_0x4f7a92&&_0x4f7a92[_0xdfc4('0x2a')]){_0x58f78f['body'][_0xdfc4('0x2c')]=_0x4f7a92;_0x140a08[_0xdfc4('0x23')]=_0x4f7a92[_0xdfc4('0x2a')];_0x140a08[_0xdfc4('0x2d')]=_0xdfc4('0x2c');_0x140a08[_0xdfc4('0x2e')]=JSON[_0xdfc4('0x25')](_0x4f7a92);return rpc[_0x52ae9f+_0xdfc4('0x2f')][_0xdfc4('0x21')](_0x140a08)[_0xdfc4('0x22')](function(_0x5db606){logger[_0xdfc4('0xf')]('[%s][AMAZONLEX]\x20%s',_0x2848a9,_0x140a08[_0xdfc4('0x23')]);if(_0x4f7a92[_0xdfc4('0x30')]==_0xdfc4('0x31')){_0x5e2c1f[_0xdfc4('0x12')]();}else{_0x5e2c1f[_0xdfc4('0x26')]();}})[_0xdfc4('0x32')](function(_0x186546){logger[_0xdfc4('0x24')](_0xdfc4('0x10'),_0x2848a9,JSON[_0xdfc4('0x25')](_0x186546));_0x5e2c1f['next']();});}else{_0x5e2c1f['next']();}});}}catch(_0x374d25){logger['error'](_0xdfc4('0x10'),_0x2848a9,JSON[_0xdfc4('0x25')](_0x374d25));_0x5e2c1f[_0xdfc4('0x26')]();}};};