96ae4da12d3c4b38a718859f9ee92d9e45f9f380
[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 _0x6acd=['interaction','UserId','info','[%s][AMAZONLEX]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','channel','sms','whatsapp','phone','chat','account','AccountId','InteractionId','created','isEmpty','body','Message','create','then','catch','stringify','[%s][AMAZONLEX]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','[%s][AMAZONLEX]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','LexRuntime','$LATEST','toString','postText','error','message','amazonlex','providerName','dialogState','Failed','lodash','moment','aws-sdk','./utils','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','consequence'];(function(_0xd0758d,_0x4f18ce){var _0x4cb907=function(_0x3c2edd){while(--_0x3c2edd){_0xd0758d['push'](_0xd0758d['shift']());}};_0x4cb907(++_0x4f18ce);}(_0x6acd,0x1bf));var _0xd6ac=function(_0x4a9fb1,_0x273043){_0x4a9fb1=_0x4a9fb1-0x0;var _0x348672=_0x6acd[_0x4a9fb1];return _0x348672;};'use strict';var _=require(_0xd6ac('0x0'));var moment=require(_0xd6ac('0x1'));var AWS=require(_0xd6ac('0x2'));var utils=require(_0xd6ac('0x3'));var logger=require('../../../../config/logger')(_0xd6ac('0x4'));var rpc={'chatMessage':require(_0xd6ac('0x5')),'openchannelMessage':require(_0xd6ac('0x6')),'mailMessage':require(_0xd6ac('0x7')),'smsMessage':require(_0xd6ac('0x8')),'faxMessage':require(_0xd6ac('0x9')),'whatsappMessage':require(_0xd6ac('0xa'))};exports[_0xd6ac('0xb')]=function(_0x5b7a07,_0x2c9a7a){return function(_0x5e3460){try{if(!_['isNil'](this[_0xd6ac('0xc')][_0xd6ac('0xd')])){logger[_0xd6ac('0xe')](_0xd6ac('0xf'),_0x5b7a07,_0xd6ac('0x10'));return _0x5e3460[_0xd6ac('0x11')]();}var _0x362dc5={'ContactId':this[_0xd6ac('0x12')]['id'],'sentAt':moment()[_0xd6ac('0x13')](_0xd6ac('0x14')),'direction':_0xd6ac('0x15')};if(this[_0xd6ac('0x16')]===_0xd6ac('0x17')||this['channel']===_0xd6ac('0x18')){_0x362dc5[_0xd6ac('0x19')]=this['interaction'][_0xd6ac('0x19')];}var _0x2fc80c=this[_0xd6ac('0x16')];if(_0x2fc80c===_0xd6ac('0x1a')){_0x362dc5['ChatWebsiteId']=this[_0xd6ac('0x1b')]['id'];}else{_0x362dc5[_['upperFirst'](_0x2fc80c)+_0xd6ac('0x1c')]=this['account']['id'];}_0x362dc5[_['upperFirst'](_0x2fc80c)+_0xd6ac('0x1d')]=this[_0xd6ac('0xc')]['id'];if(this['interaction'][_0xd6ac('0x1e')]){var _0x4d22b1=_0x2c9a7a[0x4];if(!_[_0xd6ac('0x1f')](_0x4d22b1)){_0x362dc5[_0xd6ac('0x20')]=utils['getMustacheRender'](_0x4d22b1,this);return rpc[_0x2fc80c+_0xd6ac('0x21')][_0xd6ac('0x22')](_0x362dc5)[_0xd6ac('0x23')](function(_0x474c52){logger['info'](_0xd6ac('0xf'),_0x5b7a07,_0x362dc5[_0xd6ac('0x20')]);})[_0xd6ac('0x24')](function(_0x306a85){logger['error'](_0xd6ac('0xf'),_0x5b7a07,JSON[_0xd6ac('0x25')](_0x306a85));})['finally'](function(){logger[_0xd6ac('0xe')](_0xd6ac('0x26'),_0x5b7a07);_0x5e3460[_0xd6ac('0x27')]();});}else{logger[_0xd6ac('0xe')](_0xd6ac('0x28'),_0x5b7a07);_0x5e3460[_0xd6ac('0x27')]();}}else{var _0x2aa848=this;var _0x323682=new AWS[(_0xd6ac('0x29'))]({'accessKeyId':_0x2c9a7a[0x0],'secretAccessKey':_0x2c9a7a[0x1],'region':_0x2c9a7a[0x2]});var _0xd7a6fd={'botAlias':_0xd6ac('0x2a'),'botName':_0x2c9a7a[0x3],'inputText':this['message']['body'],'userId':this[_0xd6ac('0x16')]+':'+this['interaction']['id'][_0xd6ac('0x2b')]()};_0x323682[_0xd6ac('0x2c')](_0xd7a6fd,function(_0x112350,_0x381f7f){if(_0x112350){logger[_0xd6ac('0x2d')](_0xd6ac('0xf'),_0x5b7a07,_0x112350['message']);_0x5e3460[_0xd6ac('0x11')]();}else if(_0x381f7f&&_0x381f7f[_0xd6ac('0x2e')]){_0x2aa848[_0xd6ac('0x20')][_0xd6ac('0x2f')]=_0x381f7f;_0x362dc5[_0xd6ac('0x20')]=_0x381f7f['message'];_0x362dc5[_0xd6ac('0x30')]=_0xd6ac('0x2f');_0x362dc5['providerResponse']=JSON[_0xd6ac('0x25')](_0x381f7f);return rpc[_0x2fc80c+_0xd6ac('0x21')][_0xd6ac('0x22')](_0x362dc5)['then'](function(_0x106d9f){logger['info'](_0xd6ac('0xf'),_0x5b7a07,_0x362dc5[_0xd6ac('0x20')]);if(_0x381f7f[_0xd6ac('0x31')]==_0xd6ac('0x32')){_0x5e3460[_0xd6ac('0x11')]();}else{_0x5e3460['stop']();}})['catch'](function(_0x12f662){logger[_0xd6ac('0x2d')](_0xd6ac('0xf'),_0x5b7a07,JSON[_0xd6ac('0x25')](_0x12f662));_0x5e3460[_0xd6ac('0x11')]();});}else{_0x5e3460[_0xd6ac('0x11')]();}});}}catch(_0x42d27e){logger['error'](_0xd6ac('0xf'),_0x5b7a07,JSON[_0xd6ac('0x25')](_0x42d27e));_0x5e3460[_0xd6ac('0x27')]();}};};