a9eab1dabe92ceb2f4305759d7d0cc4d84a94e05
[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 _0xf1f9=['account','isEmpty','body','getMustacheRender','Message','catch','error','[%s][AMAZONLEX]\x20%s','stringify','finally','[%s][AMAZONLEX]\x20Welcome\x20Message\x20has\x20been\x20sent!','[%s][AMAZONLEX]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','stop','$LATEST','toString','message','next','providerName','amazonlex','providerResponse','create','then','Failed','lodash','aws-sdk','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/mailMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','consequence','interaction','info','contact','format','channel','sms','whatsapp','chat','ChatWebsiteId','upperFirst','AccountId'];(function(_0x59733d,_0x51d466){var _0x16e692=function(_0x4ca8cd){while(--_0x4ca8cd){_0x59733d['push'](_0x59733d['shift']());}};_0x16e692(++_0x51d466);}(_0xf1f9,0x6f));var _0x9f1f=function(_0x46a926,_0x4154b6){_0x46a926=_0x46a926-0x0;var _0x3018d0=_0xf1f9[_0x46a926];return _0x3018d0;};'use strict';var _=require(_0x9f1f('0x0'));var moment=require('moment');var AWS=require(_0x9f1f('0x1'));var utils=require(_0x9f1f('0x2'));var logger=require(_0x9f1f('0x3'))(_0x9f1f('0x4'));var rpc={'chatMessage':require(_0x9f1f('0x5')),'openchannelMessage':require('../../rpc/openchannelMessage'),'mailMessage':require(_0x9f1f('0x6')),'smsMessage':require('../../rpc/smsMessage'),'faxMessage':require(_0x9f1f('0x7')),'whatsappMessage':require(_0x9f1f('0x8'))};exports[_0x9f1f('0x9')]=function(_0xca258c,_0x37ec52){return function(_0xfa3db){try{if(!_['isNil'](this[_0x9f1f('0xa')]['UserId'])){logger[_0x9f1f('0xb')]('[%s][AMAZONLEX]\x20%s',_0xca258c,'Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.');return _0xfa3db['next']();}var _0x2ae81a={'ContactId':this[_0x9f1f('0xc')]['id'],'sentAt':moment()[_0x9f1f('0xd')]('YYYY-MM-DD\x20HH:mm:ss'),'direction':'out'};if(this[_0x9f1f('0xe')]===_0x9f1f('0xf')||this['channel']===_0x9f1f('0x10')){_0x2ae81a['phone']=this[_0x9f1f('0xa')]['phone'];}var _0x13d363=this[_0x9f1f('0xe')];if(_0x13d363===_0x9f1f('0x11')){_0x2ae81a[_0x9f1f('0x12')]=this['account']['id'];}else{_0x2ae81a[_[_0x9f1f('0x13')](_0x13d363)+_0x9f1f('0x14')]=this[_0x9f1f('0x15')]['id'];}_0x2ae81a[_['upperFirst'](_0x13d363)+'InteractionId']=this[_0x9f1f('0xa')]['id'];if(this[_0x9f1f('0xa')]['created']){var _0x38f9a2=_0x37ec52[0x4];if(!_[_0x9f1f('0x16')](_0x38f9a2)){_0x2ae81a[_0x9f1f('0x17')]=utils[_0x9f1f('0x18')](_0x38f9a2,this);return rpc[_0x13d363+_0x9f1f('0x19')]['create'](_0x2ae81a)['then'](function(_0xc09d77){logger[_0x9f1f('0xb')]('[%s][AMAZONLEX]\x20%s',_0xca258c,_0x2ae81a['body']);})[_0x9f1f('0x1a')](function(_0x35c535){logger[_0x9f1f('0x1b')](_0x9f1f('0x1c'),_0xca258c,JSON[_0x9f1f('0x1d')](_0x35c535));})[_0x9f1f('0x1e')](function(){logger['info'](_0x9f1f('0x1f'),_0xca258c);_0xfa3db['stop']();});}else{logger[_0x9f1f('0xb')](_0x9f1f('0x20'),_0xca258c);_0xfa3db[_0x9f1f('0x21')]();}}else{var _0x3ba88b=this;var _0x4796aa=new AWS['LexRuntime']({'accessKeyId':_0x37ec52[0x0],'secretAccessKey':_0x37ec52[0x1],'region':_0x37ec52[0x2]});var _0x23a738={'botAlias':_0x9f1f('0x22'),'botName':_0x37ec52[0x3],'inputText':this['message']['body'],'userId':this[_0x9f1f('0xe')]+':'+this[_0x9f1f('0xa')]['id'][_0x9f1f('0x23')]()};_0x4796aa['postText'](_0x23a738,function(_0xd95ee5,_0x3b96a7){if(_0xd95ee5){logger[_0x9f1f('0x1b')](_0x9f1f('0x1c'),_0xca258c,_0xd95ee5[_0x9f1f('0x24')]);_0xfa3db[_0x9f1f('0x25')]();}else if(_0x3b96a7&&_0x3b96a7[_0x9f1f('0x24')]){_0x3ba88b[_0x9f1f('0x17')]['amazonlex']=_0x3b96a7;_0x2ae81a[_0x9f1f('0x17')]=_0x3b96a7['message'];_0x2ae81a[_0x9f1f('0x26')]=_0x9f1f('0x27');_0x2ae81a[_0x9f1f('0x28')]=JSON[_0x9f1f('0x1d')](_0x3b96a7);return rpc[_0x13d363+_0x9f1f('0x19')][_0x9f1f('0x29')](_0x2ae81a)[_0x9f1f('0x2a')](function(_0x24b071){logger[_0x9f1f('0xb')](_0x9f1f('0x1c'),_0xca258c,_0x2ae81a[_0x9f1f('0x17')]);if(_0x3b96a7['dialogState']==_0x9f1f('0x2b')){_0xfa3db[_0x9f1f('0x25')]();}else{_0xfa3db[_0x9f1f('0x21')]();}})[_0x9f1f('0x1a')](function(_0x33cbff){logger['error'](_0x9f1f('0x1c'),_0xca258c,JSON['stringify'](_0x33cbff));_0xfa3db[_0x9f1f('0x25')]();});}else{_0xfa3db['next']();}});}}catch(_0x37678b){logger[_0x9f1f('0x1b')](_0x9f1f('0x1c'),_0xca258c,JSON['stringify'](_0x37678b));_0xfa3db[_0x9f1f('0x21')]();}};};