171f0af27f0f11d3d585ea49d493acc03a047e15
[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 _0xc308=['./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','consequence','isNil','interaction','info','[%s][AMAZONLEX]\x20%s','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','channel','sms','whatsapp','phone','chat','ChatWebsiteId','upperFirst','AccountId','account','created','getMustacheRender','Message','create','then','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','providerName','providerResponse','dialogState','Failed','aws-sdk'];(function(_0x3a74b1,_0x421f68){var _0x514388=function(_0x1b1a9d){while(--_0x1b1a9d){_0x3a74b1['push'](_0x3a74b1['shift']());}};_0x514388(++_0x421f68);}(_0xc308,0x9b));var _0x8c30=function(_0x1c518c,_0x383352){_0x1c518c=_0x1c518c-0x0;var _0x2650cb=_0xc308[_0x1c518c];return _0x2650cb;};'use strict';var _=require('lodash');var moment=require('moment');var AWS=require(_0x8c30('0x0'));var utils=require(_0x8c30('0x1'));var logger=require(_0x8c30('0x2'))(_0x8c30('0x3'));var rpc={'chatMessage':require(_0x8c30('0x4')),'openchannelMessage':require(_0x8c30('0x5')),'mailMessage':require(_0x8c30('0x6')),'smsMessage':require(_0x8c30('0x7')),'faxMessage':require(_0x8c30('0x8')),'whatsappMessage':require(_0x8c30('0x9'))};exports[_0x8c30('0xa')]=function(_0x34385f,_0x17e026){return function(_0x33bb5e){try{if(!_[_0x8c30('0xb')](this[_0x8c30('0xc')]['UserId'])){logger[_0x8c30('0xd')](_0x8c30('0xe'),_0x34385f,'Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.');return _0x33bb5e['next']();}var _0x5f3534={'ContactId':this[_0x8c30('0xf')]['id'],'sentAt':moment()[_0x8c30('0x10')](_0x8c30('0x11')),'direction':_0x8c30('0x12')};if(this[_0x8c30('0x13')]===_0x8c30('0x14')||this['channel']===_0x8c30('0x15')){_0x5f3534[_0x8c30('0x16')]=this[_0x8c30('0xc')]['phone'];}var _0x35fecc=this[_0x8c30('0x13')];if(_0x35fecc===_0x8c30('0x17')){_0x5f3534[_0x8c30('0x18')]=this['account']['id'];}else{_0x5f3534[_[_0x8c30('0x19')](_0x35fecc)+_0x8c30('0x1a')]=this[_0x8c30('0x1b')]['id'];}_0x5f3534[_[_0x8c30('0x19')](_0x35fecc)+'InteractionId']=this[_0x8c30('0xc')]['id'];if(this['interaction'][_0x8c30('0x1c')]){var _0x11cfaa=_0x17e026[0x4];if(!_['isEmpty'](_0x11cfaa)){_0x5f3534['body']=utils[_0x8c30('0x1d')](_0x11cfaa,this);return rpc[_0x35fecc+_0x8c30('0x1e')][_0x8c30('0x1f')](_0x5f3534)[_0x8c30('0x20')](function(_0x43e474){logger['info'](_0x8c30('0xe'),_0x34385f,_0x5f3534[_0x8c30('0x21')]);})[_0x8c30('0x22')](function(_0x283e5e){logger[_0x8c30('0x23')](_0x8c30('0xe'),_0x34385f,JSON[_0x8c30('0x24')](_0x283e5e));})[_0x8c30('0x25')](function(){logger[_0x8c30('0xd')](_0x8c30('0x26'),_0x34385f);_0x33bb5e[_0x8c30('0x27')]();});}else{logger[_0x8c30('0xd')](_0x8c30('0x28'),_0x34385f);_0x33bb5e[_0x8c30('0x27')]();}}else{var _0x249b35=this;var _0x15348f=new AWS[(_0x8c30('0x29'))]({'accessKeyId':_0x17e026[0x0],'secretAccessKey':_0x17e026[0x1],'region':_0x17e026[0x2]});var _0x1d9001={'botAlias':_0x8c30('0x2a'),'botName':_0x17e026[0x3],'inputText':this[_0x8c30('0x2b')][_0x8c30('0x21')],'userId':this[_0x8c30('0x13')]+':'+this[_0x8c30('0xc')]['id'][_0x8c30('0x2c')]()};_0x15348f[_0x8c30('0x2d')](_0x1d9001,function(_0x39f1c0,_0x3aa870){if(_0x39f1c0){logger['error'](_0x8c30('0xe'),_0x34385f,_0x39f1c0[_0x8c30('0x2b')]);_0x33bb5e[_0x8c30('0x2e')]();}else if(_0x3aa870&&_0x3aa870[_0x8c30('0x2b')]){_0x249b35[_0x8c30('0x21')][_0x8c30('0x2f')]=_0x3aa870;_0x5f3534[_0x8c30('0x21')]=_0x3aa870[_0x8c30('0x2b')];_0x5f3534[_0x8c30('0x30')]='amazonlex';_0x5f3534[_0x8c30('0x31')]=JSON[_0x8c30('0x24')](_0x3aa870);return rpc[_0x35fecc+_0x8c30('0x1e')][_0x8c30('0x1f')](_0x5f3534)[_0x8c30('0x20')](function(_0x181041){logger[_0x8c30('0xd')](_0x8c30('0xe'),_0x34385f,_0x5f3534[_0x8c30('0x21')]);if(_0x3aa870[_0x8c30('0x32')]==_0x8c30('0x33')){_0x33bb5e['next']();}else{_0x33bb5e['stop']();}})['catch'](function(_0x58533a){logger[_0x8c30('0x23')](_0x8c30('0xe'),_0x34385f,JSON[_0x8c30('0x24')](_0x58533a));_0x33bb5e[_0x8c30('0x2e')]();});}else{_0x33bb5e['next']();}});}}catch(_0x49c0ba){logger['error'](_0x8c30('0xe'),_0x34385f,JSON[_0x8c30('0x24')](_0x49c0ba));_0x33bb5e[_0x8c30('0x27')]();}};};