Built motion from commit f7863d46.|2.5.41
[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 _0x687f=['whatsapp','phone','ChatWebsiteId','account','upperFirst','AccountId','interaction','created','isEmpty','body','getMustacheRender','Message','then','info','[%s][AMAZONLEX]\x20%s','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','message','toString','postText','amazonlex','providerName','providerResponse','create','dialogState','Failed','next','catch','moment','aws-sdk','./utils','../../../../config/logger','routing','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','UserId','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','contact','YYYY-MM-DD\x20HH:mm:ss','out','channel','sms'];(function(_0x22cb10,_0x20db4f){var _0x38a6f8=function(_0xdb4b16){while(--_0xdb4b16){_0x22cb10['push'](_0x22cb10['shift']());}};_0x38a6f8(++_0x20db4f);}(_0x687f,0x1da));var _0xf687=function(_0x187ee1,_0x3fd1e6){_0x187ee1=_0x187ee1-0x0;var _0x388160=_0x687f[_0x187ee1];return _0x388160;};'use strict';var _=require('lodash');var moment=require(_0xf687('0x0'));var AWS=require(_0xf687('0x1'));var utils=require(_0xf687('0x2'));var logger=require(_0xf687('0x3'))(_0xf687('0x4'));var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require(_0xf687('0x5')),'mailMessage':require(_0xf687('0x6')),'smsMessage':require(_0xf687('0x7')),'faxMessage':require(_0xf687('0x8')),'whatsappMessage':require('../../rpc/whatsappMessage')};exports['consequence']=function(_0x187db0,_0x2b212f){return function(_0x286de8){try{if(!_['isNil'](this['interaction'][_0xf687('0x9')])){logger['info']('[%s][AMAZONLEX]\x20%s',_0x187db0,_0xf687('0xa'));return _0x286de8['next']();}var _0x497fcf={'ContactId':this[_0xf687('0xb')]['id'],'sentAt':moment()['format'](_0xf687('0xc')),'direction':_0xf687('0xd')};if(this[_0xf687('0xe')]===_0xf687('0xf')||this[_0xf687('0xe')]===_0xf687('0x10')){_0x497fcf[_0xf687('0x11')]=this['interaction']['phone'];}var _0x2222f0=this[_0xf687('0xe')];if(_0x2222f0==='chat'){_0x497fcf[_0xf687('0x12')]=this[_0xf687('0x13')]['id'];}else{_0x497fcf[_[_0xf687('0x14')](_0x2222f0)+_0xf687('0x15')]=this[_0xf687('0x13')]['id'];}_0x497fcf[_[_0xf687('0x14')](_0x2222f0)+'InteractionId']=this['interaction']['id'];if(this[_0xf687('0x16')][_0xf687('0x17')]){var _0xfbe4b7=_0x2b212f[0x4];if(!_[_0xf687('0x18')](_0xfbe4b7)){_0x497fcf[_0xf687('0x19')]=utils[_0xf687('0x1a')](_0xfbe4b7,this);return rpc[_0x2222f0+_0xf687('0x1b')]['create'](_0x497fcf)[_0xf687('0x1c')](function(_0xff02d4){logger[_0xf687('0x1d')](_0xf687('0x1e'),_0x187db0,_0x497fcf['body']);})['catch'](function(_0x4bba7b){logger[_0xf687('0x1f')](_0xf687('0x1e'),_0x187db0,JSON[_0xf687('0x20')](_0x4bba7b));})[_0xf687('0x21')](function(){logger[_0xf687('0x1d')](_0xf687('0x22'),_0x187db0);_0x286de8[_0xf687('0x23')]();});}else{logger['info'](_0xf687('0x24'),_0x187db0);_0x286de8[_0xf687('0x23')]();}}else{var _0x591e52=this;var _0x22a58c=new AWS['LexRuntime']({'accessKeyId':_0x2b212f[0x0],'secretAccessKey':_0x2b212f[0x1],'region':_0x2b212f[0x2]});var _0x4b683c={'botAlias':_0xf687('0x25'),'botName':_0x2b212f[0x3],'inputText':this[_0xf687('0x26')][_0xf687('0x19')],'userId':this['channel']+':'+this[_0xf687('0x16')]['id'][_0xf687('0x27')]()};_0x22a58c[_0xf687('0x28')](_0x4b683c,function(_0x2fedb1,_0x34a854){if(_0x2fedb1){logger['error'](_0xf687('0x1e'),_0x187db0,_0x2fedb1['message']);_0x286de8['next']();}else if(_0x34a854&&_0x34a854['message']){_0x591e52['body'][_0xf687('0x29')]=_0x34a854;_0x497fcf[_0xf687('0x19')]=_0x34a854[_0xf687('0x26')];_0x497fcf[_0xf687('0x2a')]=_0xf687('0x29');_0x497fcf[_0xf687('0x2b')]=JSON['stringify'](_0x34a854);return rpc[_0x2222f0+_0xf687('0x1b')][_0xf687('0x2c')](_0x497fcf)['then'](function(_0x51497c){logger['info'](_0xf687('0x1e'),_0x187db0,_0x497fcf[_0xf687('0x19')]);if(_0x34a854[_0xf687('0x2d')]==_0xf687('0x2e')){_0x286de8[_0xf687('0x2f')]();}else{_0x286de8['stop']();}})[_0xf687('0x30')](function(_0xea5ac2){logger['error'](_0xf687('0x1e'),_0x187db0,JSON['stringify'](_0xea5ac2));_0x286de8['next']();});}else{_0x286de8['next']();}});}}catch(_0x1b3e2f){logger['error'](_0xf687('0x1e'),_0x187db0,JSON[_0xf687('0x20')](_0x1b3e2f));_0x286de8[_0xf687('0x23')]();}};};