1343b03b002946105425885514973a7129d96c71
[motion2.git] / server / services / routing / server / applications / dialogflow.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 _0x7111=['then','info','error','stringify','finally','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','message','dialogflow','result','fulfillment','speech','providerName','providerResponse','endConversation','next','catch','lodash','moment','md5','./utils','../../../../config/logger','routing','../../rpc/openchannelMessage','../../rpc/smsMessage','../../rpc/whatsappMessage','consequence','[%s][DIALOGFLOW]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','contact','YYYY-MM-DD\x20HH:mm:ss','out','sms','channel','whatsapp','phone','interaction','chat','ChatWebsiteId','account','upperFirst','AccountId','InteractionId','isEmpty','body','getMustacheRender','Message','create'];(function(_0x509932,_0x5713d1){var _0x277817=function(_0x2e94e8){while(--_0x2e94e8){_0x509932['push'](_0x509932['shift']());}};_0x277817(++_0x5713d1);}(_0x7111,0x19a));var _0x1711=function(_0x57d13b,_0x52d8cb){_0x57d13b=_0x57d13b-0x0;var _0x467696=_0x7111[_0x57d13b];return _0x467696;};'use strict';var _=require(_0x1711('0x0'));var moment=require(_0x1711('0x1'));var apiai=require('apiai-promise');var md5=require(_0x1711('0x2'));var utils=require(_0x1711('0x3'));var logger=require(_0x1711('0x4'))(_0x1711('0x5'));var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require(_0x1711('0x6')),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require(_0x1711('0x7')),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require(_0x1711('0x8'))};exports[_0x1711('0x9')]=function(_0x33d31e,_0x112e06){return function(_0x34d897){try{if(!_['isNil'](this['interaction']['UserId'])){logger['info'](_0x1711('0xa'),_0x33d31e,_0x1711('0xb'));return _0x34d897['next']();}var _0x347eab={'ContactId':this[_0x1711('0xc')]['id'],'sentAt':moment()['format'](_0x1711('0xd')),'direction':_0x1711('0xe')};if(this['channel']===_0x1711('0xf')||this[_0x1711('0x10')]===_0x1711('0x11')){_0x347eab[_0x1711('0x12')]=this[_0x1711('0x13')]['phone'];}var _0x1958e3=this['channel'];if(_0x1958e3===_0x1711('0x14')){_0x347eab[_0x1711('0x15')]=this[_0x1711('0x16')]['id'];}else{_0x347eab[_[_0x1711('0x17')](_0x1958e3)+_0x1711('0x18')]=this[_0x1711('0x16')]['id'];}_0x347eab[_['upperFirst'](_0x1958e3)+_0x1711('0x19')]=this['interaction']['id'];if(this[_0x1711('0x13')]['created']){var _0x13045a=_0x112e06[0x2];if(!_[_0x1711('0x1a')](_0x13045a)){_0x347eab[_0x1711('0x1b')]=utils[_0x1711('0x1c')](_0x13045a,this);return rpc[_0x1958e3+_0x1711('0x1d')][_0x1711('0x1e')](_0x347eab)[_0x1711('0x1f')](function(_0x4621d0){logger[_0x1711('0x20')]('[%s][DIALOGFLOW]\x20%s',_0x33d31e,_0x347eab[_0x1711('0x1b')]);})['catch'](function(_0x434b14){logger[_0x1711('0x21')]('[%s][DIALOGFLOW]\x20%s',_0x33d31e,JSON[_0x1711('0x22')](_0x434b14));})[_0x1711('0x23')](function(){logger[_0x1711('0x20')](_0x1711('0x24'),_0x33d31e);_0x34d897[_0x1711('0x25')]();});}else{logger['info'](_0x1711('0x26'),_0x33d31e);_0x34d897[_0x1711('0x25')]();}}else{var _0x412ed8=this;var _0x3e8807=apiai(_0x112e06[0x0],{'language':_0x112e06[0x1]||'en'});return _0x3e8807['textRequest'](this[_0x1711('0x27')][_0x1711('0x1b')],{'sessionId':md5(this['interaction']['id'])})[_0x1711('0x1f')](function(_0xd14bcd){_0x412ed8[_0x1711('0x1b')][_0x1711('0x28')]=_0xd14bcd;_0x347eab[_0x1711('0x1b')]=_0xd14bcd[_0x1711('0x29')][_0x1711('0x2a')][_0x1711('0x2b')];_0x347eab[_0x1711('0x2c')]=_0x1711('0x28');_0x347eab[_0x1711('0x2d')]=JSON[_0x1711('0x22')](_0xd14bcd);return rpc[_0x1958e3+_0x1711('0x1d')][_0x1711('0x1e')](_0x347eab)[_0x1711('0x1f')](function(_0x36ac2d){logger[_0x1711('0x20')]('[%s][DIALOGFLOW]\x20%s',_0x33d31e,_0x347eab[_0x1711('0x1b')]);if(_0xd14bcd[_0x1711('0x29')]['metadata'][_0x1711('0x2e')]){_0x34d897['next']();}else{_0x34d897['stop']();}})['catch'](function(_0x54df73){logger['error'](_0x1711('0xa'),_0x33d31e,JSON[_0x1711('0x22')](_0x54df73));_0x34d897[_0x1711('0x2f')]();});})[_0x1711('0x30')](function(_0x5c7934){logger[_0x1711('0x21')](_0x1711('0xa'),_0x33d31e,_0x5c7934[_0x1711('0x27')]);_0x34d897[_0x1711('0x2f')]();});}}catch(_0x1d4437){logger['error'](_0x1711('0xa'),_0x33d31e,JSON[_0x1711('0x22')](_0x1d4437));_0x34d897['stop']();}};};