7eddaac4196f8370ab42a7448d4bac2565f9f609
[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 _0x276c=['account','body','getMustacheRender','Message','create','then','error','stringify','finally','[%s][AMAZONLEX]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','LexRuntime','message','postText','next','amazonlex','providerName','dialogState','lodash','moment','./utils','../../../../config/logger','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','consequence','isNil','interaction','UserId','info','[%s][AMAZONLEX]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','contact','YYYY-MM-DD\x20HH:mm:ss','out','channel','sms','whatsapp','phone','upperFirst','AccountId'];(function(_0x126558,_0x143c9a){var _0x1f6d14=function(_0x2b0eea){while(--_0x2b0eea){_0x126558['push'](_0x126558['shift']());}};_0x1f6d14(++_0x143c9a);}(_0x276c,0xee));var _0xc276=function(_0x491f87,_0x18f826){_0x491f87=_0x491f87-0x0;var _0x4e696f=_0x276c[_0x491f87];return _0x4e696f;};'use strict';var _=require(_0xc276('0x0'));var moment=require(_0xc276('0x1'));var AWS=require('aws-sdk');var utils=require(_0xc276('0x2'));var logger=require(_0xc276('0x3'))('routing');var rpc={'chatMessage':require(_0xc276('0x4')),'openchannelMessage':require(_0xc276('0x5')),'mailMessage':require(_0xc276('0x6')),'smsMessage':require(_0xc276('0x7')),'faxMessage':require(_0xc276('0x8')),'whatsappMessage':require(_0xc276('0x9'))};exports[_0xc276('0xa')]=function(_0x2adec3,_0x66217d){return function(_0x2d8e7a){try{if(!_[_0xc276('0xb')](this[_0xc276('0xc')][_0xc276('0xd')])){logger[_0xc276('0xe')](_0xc276('0xf'),_0x2adec3,_0xc276('0x10'));return _0x2d8e7a['next']();}var _0x2ad0a1={'ContactId':this[_0xc276('0x11')]['id'],'sentAt':moment()['format'](_0xc276('0x12')),'direction':_0xc276('0x13')};if(this[_0xc276('0x14')]===_0xc276('0x15')||this[_0xc276('0x14')]===_0xc276('0x16')){_0x2ad0a1[_0xc276('0x17')]=this[_0xc276('0xc')][_0xc276('0x17')];}var _0x1ab99a=this[_0xc276('0x14')];if(_0x1ab99a==='chat'){_0x2ad0a1['ChatWebsiteId']=this['account']['id'];}else{_0x2ad0a1[_[_0xc276('0x18')](_0x1ab99a)+_0xc276('0x19')]=this[_0xc276('0x1a')]['id'];}_0x2ad0a1[_['upperFirst'](_0x1ab99a)+'InteractionId']=this[_0xc276('0xc')]['id'];if(this['interaction']['created']){var _0xd7cd25=_0x66217d[0x4];if(!_['isEmpty'](_0xd7cd25)){_0x2ad0a1[_0xc276('0x1b')]=utils[_0xc276('0x1c')](_0xd7cd25,this);return rpc[_0x1ab99a+_0xc276('0x1d')][_0xc276('0x1e')](_0x2ad0a1)[_0xc276('0x1f')](function(_0x4d38f0){logger[_0xc276('0xe')](_0xc276('0xf'),_0x2adec3,_0x2ad0a1[_0xc276('0x1b')]);})['catch'](function(_0x4bb838){logger[_0xc276('0x20')](_0xc276('0xf'),_0x2adec3,JSON[_0xc276('0x21')](_0x4bb838));})[_0xc276('0x22')](function(){logger[_0xc276('0xe')](_0xc276('0x23'),_0x2adec3);_0x2d8e7a[_0xc276('0x24')]();});}else{logger[_0xc276('0xe')]('[%s][AMAZONLEX]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!',_0x2adec3);_0x2d8e7a[_0xc276('0x24')]();}}else{var _0x54e3f9=this;var _0x17fae8=new AWS[(_0xc276('0x25'))]({'accessKeyId':_0x66217d[0x0],'secretAccessKey':_0x66217d[0x1],'region':_0x66217d[0x2]});var _0x551732={'botAlias':'$LATEST','botName':_0x66217d[0x3],'inputText':this[_0xc276('0x26')][_0xc276('0x1b')],'userId':this['channel']+':'+this[_0xc276('0xc')]['id']['toString']()};_0x17fae8[_0xc276('0x27')](_0x551732,function(_0x414f7a,_0x1880ae){if(_0x414f7a){logger[_0xc276('0x20')](_0xc276('0xf'),_0x2adec3,_0x414f7a[_0xc276('0x26')]);_0x2d8e7a[_0xc276('0x28')]();}else if(_0x1880ae&&_0x1880ae[_0xc276('0x26')]){_0x54e3f9[_0xc276('0x1b')][_0xc276('0x29')]=_0x1880ae;_0x2ad0a1[_0xc276('0x1b')]=_0x1880ae[_0xc276('0x26')];_0x2ad0a1[_0xc276('0x2a')]=_0xc276('0x29');_0x2ad0a1['providerResponse']=JSON[_0xc276('0x21')](_0x1880ae);return rpc[_0x1ab99a+_0xc276('0x1d')][_0xc276('0x1e')](_0x2ad0a1)[_0xc276('0x1f')](function(_0x76495f){logger[_0xc276('0xe')]('[%s][AMAZONLEX]\x20%s',_0x2adec3,_0x2ad0a1[_0xc276('0x1b')]);if(_0x1880ae[_0xc276('0x2b')]=='Failed'){_0x2d8e7a['next']();}else{_0x2d8e7a[_0xc276('0x24')]();}})['catch'](function(_0x597e0d){logger['error']('[%s][AMAZONLEX]\x20%s',_0x2adec3,JSON['stringify'](_0x597e0d));_0x2d8e7a[_0xc276('0x28')]();});}else{_0x2d8e7a[_0xc276('0x28')]();}});}}catch(_0x3fd4e0){logger[_0xc276('0x20')](_0xc276('0xf'),_0x2adec3,JSON['stringify'](_0x3fd4e0));_0x2d8e7a[_0xc276('0x24')]();}};};