Built motion from commit ffdca78c.|2.6.24
[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 _0xf816=['whatsapp','phone','chat','ChatWebsiteId','account','upperFirst','AccountId','InteractionId','body','getMustacheRender','Message','create','then','info','catch','error','stringify','[%s][AMAZONLEX]\x20Welcome\x20Message\x20has\x20been\x20sent!','[%s][AMAZONLEX]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','stop','LexRuntime','$LATEST','message','toString','next','amazonlex','providerName','providerResponse','dialogState','Failed','lodash','moment','aws-sdk','./utils','routing','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/whatsappMessage','consequence','isNil','interaction','UserId','[%s][AMAZONLEX]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','channel','sms'];(function(_0xc7fbc0,_0x41c0be){var _0x21c34c=function(_0x5f0c97){while(--_0x5f0c97){_0xc7fbc0['push'](_0xc7fbc0['shift']());}};_0x21c34c(++_0x41c0be);}(_0xf816,0x11d));var _0x6f81=function(_0x51c610,_0x2c5cb2){_0x51c610=_0x51c610-0x0;var _0x587d1b=_0xf816[_0x51c610];return _0x587d1b;};'use strict';var _=require(_0x6f81('0x0'));var moment=require(_0x6f81('0x1'));var AWS=require(_0x6f81('0x2'));var utils=require(_0x6f81('0x3'));var logger=require('../../../../config/logger')(_0x6f81('0x4'));var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require(_0x6f81('0x5')),'mailMessage':require(_0x6f81('0x6')),'smsMessage':require(_0x6f81('0x7')),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require(_0x6f81('0x8'))};exports[_0x6f81('0x9')]=function(_0x292b4d,_0x5a13a2){return function(_0x466e09){try{if(!_[_0x6f81('0xa')](this[_0x6f81('0xb')][_0x6f81('0xc')])){logger['info'](_0x6f81('0xd'),_0x292b4d,_0x6f81('0xe'));return _0x466e09['next']();}var _0x5bf827={'ContactId':this[_0x6f81('0xf')]['id'],'sentAt':moment()[_0x6f81('0x10')](_0x6f81('0x11')),'direction':_0x6f81('0x12')};if(this[_0x6f81('0x13')]===_0x6f81('0x14')||this[_0x6f81('0x13')]===_0x6f81('0x15')){_0x5bf827['phone']=this[_0x6f81('0xb')][_0x6f81('0x16')];}var _0x5e2ab6=this[_0x6f81('0x13')];if(_0x5e2ab6===_0x6f81('0x17')){_0x5bf827[_0x6f81('0x18')]=this[_0x6f81('0x19')]['id'];}else{_0x5bf827[_[_0x6f81('0x1a')](_0x5e2ab6)+_0x6f81('0x1b')]=this['account']['id'];}_0x5bf827[_[_0x6f81('0x1a')](_0x5e2ab6)+_0x6f81('0x1c')]=this[_0x6f81('0xb')]['id'];if(this['interaction']['created']){var _0x262e09=_0x5a13a2[0x4];if(!_['isEmpty'](_0x262e09)){_0x5bf827[_0x6f81('0x1d')]=utils[_0x6f81('0x1e')](_0x262e09,this);return rpc[_0x5e2ab6+_0x6f81('0x1f')][_0x6f81('0x20')](_0x5bf827)[_0x6f81('0x21')](function(_0x222400){logger[_0x6f81('0x22')](_0x6f81('0xd'),_0x292b4d,_0x5bf827[_0x6f81('0x1d')]);})[_0x6f81('0x23')](function(_0x36c01d){logger[_0x6f81('0x24')](_0x6f81('0xd'),_0x292b4d,JSON[_0x6f81('0x25')](_0x36c01d));})['finally'](function(){logger[_0x6f81('0x22')](_0x6f81('0x26'),_0x292b4d);_0x466e09['stop']();});}else{logger['info'](_0x6f81('0x27'),_0x292b4d);_0x466e09[_0x6f81('0x28')]();}}else{var _0x2658f3=this;var _0x5d07b8=new AWS[(_0x6f81('0x29'))]({'accessKeyId':_0x5a13a2[0x0],'secretAccessKey':_0x5a13a2[0x1],'region':_0x5a13a2[0x2]});var _0x5450a6={'botAlias':_0x6f81('0x2a'),'botName':_0x5a13a2[0x3],'inputText':this[_0x6f81('0x2b')]['body'],'userId':this[_0x6f81('0x13')]+':'+this['interaction']['id'][_0x6f81('0x2c')]()};_0x5d07b8['postText'](_0x5450a6,function(_0x5bd008,_0xa4420c){if(_0x5bd008){logger[_0x6f81('0x24')](_0x6f81('0xd'),_0x292b4d,_0x5bd008[_0x6f81('0x2b')]);_0x466e09[_0x6f81('0x2d')]();}else if(_0xa4420c&&_0xa4420c[_0x6f81('0x2b')]){_0x2658f3[_0x6f81('0x1d')][_0x6f81('0x2e')]=_0xa4420c;_0x5bf827[_0x6f81('0x1d')]=_0xa4420c[_0x6f81('0x2b')];_0x5bf827[_0x6f81('0x2f')]=_0x6f81('0x2e');_0x5bf827[_0x6f81('0x30')]=JSON[_0x6f81('0x25')](_0xa4420c);return rpc[_0x5e2ab6+_0x6f81('0x1f')][_0x6f81('0x20')](_0x5bf827)[_0x6f81('0x21')](function(_0x26cd42){logger[_0x6f81('0x22')](_0x6f81('0xd'),_0x292b4d,_0x5bf827[_0x6f81('0x1d')]);if(_0xa4420c[_0x6f81('0x31')]==_0x6f81('0x32')){_0x466e09[_0x6f81('0x2d')]();}else{_0x466e09['stop']();}})[_0x6f81('0x23')](function(_0x387944){logger['error'](_0x6f81('0xd'),_0x292b4d,JSON[_0x6f81('0x25')](_0x387944));_0x466e09[_0x6f81('0x2d')]();});}else{_0x466e09[_0x6f81('0x2d')]();}});}}catch(_0x34f25f){logger['error']('[%s][AMAZONLEX]\x20%s',_0x292b4d,JSON[_0x6f81('0x25')](_0x34f25f));_0x466e09[_0x6f81('0x28')]();}};};