bf256c459cca98a080ec3859411e0714345461a9
[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 _0xc74a=['providerResponse','dialogState','Failed','lodash','moment','aws-sdk','./utils','../../../../config/logger','routing','../../rpc/openchannelMessage','../../rpc/smsMessage','../../rpc/faxMessage','consequence','interaction','UserId','[%s][AMAZONLEX]\x20%s','next','out','channel','sms','phone','chat','ChatWebsiteId','upperFirst','AccountId','account','InteractionId','created','isEmpty','getMustacheRender','Message','create','then','info','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!','$LATEST','body','toString','postText','message','amazonlex'];(function(_0x19721a,_0x49890e){var _0x9d6984=function(_0x1d40b3){while(--_0x1d40b3){_0x19721a['push'](_0x19721a['shift']());}};_0x9d6984(++_0x49890e);}(_0xc74a,0x17b));var _0xac74=function(_0x1607e0,_0x262e19){_0x1607e0=_0x1607e0-0x0;var _0x20ef44=_0xc74a[_0x1607e0];return _0x20ef44;};'use strict';var _=require(_0xac74('0x0'));var moment=require(_0xac74('0x1'));var AWS=require(_0xac74('0x2'));var utils=require(_0xac74('0x3'));var logger=require(_0xac74('0x4'))(_0xac74('0x5'));var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require(_0xac74('0x6')),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require(_0xac74('0x7')),'faxMessage':require(_0xac74('0x8')),'whatsappMessage':require('../../rpc/whatsappMessage')};exports[_0xac74('0x9')]=function(_0x254e2c,_0x3dd898){return function(_0x4c8357){try{if(!_['isNil'](this[_0xac74('0xa')][_0xac74('0xb')])){logger['info'](_0xac74('0xc'),_0x254e2c,'Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.');return _0x4c8357[_0xac74('0xd')]();}var _0x12d831={'ContactId':this['contact']['id'],'sentAt':moment()['format']('YYYY-MM-DD\x20HH:mm:ss'),'direction':_0xac74('0xe')};if(this[_0xac74('0xf')]===_0xac74('0x10')||this['channel']==='whatsapp'){_0x12d831['phone']=this['interaction'][_0xac74('0x11')];}var _0xa281fe=this[_0xac74('0xf')];if(_0xa281fe===_0xac74('0x12')){_0x12d831[_0xac74('0x13')]=this['account']['id'];}else{_0x12d831[_[_0xac74('0x14')](_0xa281fe)+_0xac74('0x15')]=this[_0xac74('0x16')]['id'];}_0x12d831[_[_0xac74('0x14')](_0xa281fe)+_0xac74('0x17')]=this[_0xac74('0xa')]['id'];if(this[_0xac74('0xa')][_0xac74('0x18')]){var _0x24ba49=_0x3dd898[0x4];if(!_[_0xac74('0x19')](_0x24ba49)){_0x12d831['body']=utils[_0xac74('0x1a')](_0x24ba49,this);return rpc[_0xa281fe+_0xac74('0x1b')][_0xac74('0x1c')](_0x12d831)[_0xac74('0x1d')](function(_0x5fb762){logger[_0xac74('0x1e')](_0xac74('0xc'),_0x254e2c,_0x12d831['body']);})[_0xac74('0x1f')](function(_0x9f064f){logger[_0xac74('0x20')](_0xac74('0xc'),_0x254e2c,JSON[_0xac74('0x21')](_0x9f064f));})[_0xac74('0x22')](function(){logger['info'](_0xac74('0x23'),_0x254e2c);_0x4c8357[_0xac74('0x24')]();});}else{logger[_0xac74('0x1e')](_0xac74('0x25'),_0x254e2c);_0x4c8357[_0xac74('0x24')]();}}else{var _0x4e6ce6=this;var _0x2655a7=new AWS['LexRuntime']({'accessKeyId':_0x3dd898[0x0],'secretAccessKey':_0x3dd898[0x1],'region':_0x3dd898[0x2]});var _0x4d0f36={'botAlias':_0xac74('0x26'),'botName':_0x3dd898[0x3],'inputText':this['message'][_0xac74('0x27')],'userId':this['channel']+':'+this[_0xac74('0xa')]['id'][_0xac74('0x28')]()};_0x2655a7[_0xac74('0x29')](_0x4d0f36,function(_0x1ad736,_0x2fefc6){if(_0x1ad736){logger['error'](_0xac74('0xc'),_0x254e2c,_0x1ad736[_0xac74('0x2a')]);_0x4c8357[_0xac74('0xd')]();}else if(_0x2fefc6&&_0x2fefc6[_0xac74('0x2a')]){_0x4e6ce6[_0xac74('0x27')][_0xac74('0x2b')]=_0x2fefc6;_0x12d831[_0xac74('0x27')]=_0x2fefc6['message'];_0x12d831['providerName']='amazonlex';_0x12d831[_0xac74('0x2c')]=JSON[_0xac74('0x21')](_0x2fefc6);return rpc[_0xa281fe+_0xac74('0x1b')][_0xac74('0x1c')](_0x12d831)[_0xac74('0x1d')](function(_0x18144d){logger[_0xac74('0x1e')](_0xac74('0xc'),_0x254e2c,_0x12d831[_0xac74('0x27')]);if(_0x2fefc6[_0xac74('0x2d')]==_0xac74('0x2e')){_0x4c8357[_0xac74('0xd')]();}else{_0x4c8357[_0xac74('0x24')]();}})[_0xac74('0x1f')](function(_0x2a4f1c){logger['error'](_0xac74('0xc'),_0x254e2c,JSON[_0xac74('0x21')](_0x2a4f1c));_0x4c8357['next']();});}else{_0x4c8357[_0xac74('0xd')]();}});}}catch(_0x8d1dd6){logger['error']('[%s][AMAZONLEX]\x20%s',_0x254e2c,JSON[_0xac74('0x21')](_0x8d1dd6));_0x4c8357[_0xac74('0x24')]();}};};