2a9d70a7eeaf1b133568149849021547ccbf0fd2
[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 _0xa07e=['stop','textRequest','message','dialogflow','result','speech','providerName','providerResponse','metadata','endConversation','lodash','moment','apiai-promise','md5','../../../../config/logger','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','consequence','isNil','interaction','UserId','info','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','contact','format','YYYY-MM-DD\x20HH:mm:ss','channel','sms','phone','chat','ChatWebsiteId','account','upperFirst','AccountId','InteractionId','created','isEmpty','getMustacheRender','Message','create','then','body','catch','error','[%s][DIALOGFLOW]\x20%s','stringify','finally','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!'];(function(_0x9e4ec1,_0x54b428){var _0x2d1df4=function(_0x44f925){while(--_0x44f925){_0x9e4ec1['push'](_0x9e4ec1['shift']());}};_0x2d1df4(++_0x54b428);}(_0xa07e,0xda));var _0xea07=function(_0x157933,_0x520db2){_0x157933=_0x157933-0x0;var _0x3b9282=_0xa07e[_0x157933];return _0x3b9282;};'use strict';var _=require(_0xea07('0x0'));var moment=require(_0xea07('0x1'));var apiai=require(_0xea07('0x2'));var md5=require(_0xea07('0x3'));var utils=require('./utils');var logger=require(_0xea07('0x4'))('routing');var rpc={'chatMessage':require(_0xea07('0x5')),'openchannelMessage':require(_0xea07('0x6')),'mailMessage':require(_0xea07('0x7')),'smsMessage':require('../../rpc/smsMessage'),'faxMessage':require(_0xea07('0x8')),'whatsappMessage':require(_0xea07('0x9'))};exports[_0xea07('0xa')]=function(_0x34b809,_0x30ec45){return function(_0x18f8ce){try{if(!_[_0xea07('0xb')](this[_0xea07('0xc')][_0xea07('0xd')])){logger[_0xea07('0xe')]('[%s][DIALOGFLOW]\x20%s',_0x34b809,_0xea07('0xf'));return _0x18f8ce[_0xea07('0x10')]();}var _0x46dd73={'ContactId':this[_0xea07('0x11')]['id'],'sentAt':moment()[_0xea07('0x12')](_0xea07('0x13')),'direction':'out'};if(this[_0xea07('0x14')]===_0xea07('0x15')||this['channel']==='whatsapp'){_0x46dd73[_0xea07('0x16')]=this[_0xea07('0xc')][_0xea07('0x16')];}var _0x4a8a18=this['channel'];if(_0x4a8a18===_0xea07('0x17')){_0x46dd73[_0xea07('0x18')]=this[_0xea07('0x19')]['id'];}else{_0x46dd73[_[_0xea07('0x1a')](_0x4a8a18)+_0xea07('0x1b')]=this[_0xea07('0x19')]['id'];}_0x46dd73[_[_0xea07('0x1a')](_0x4a8a18)+_0xea07('0x1c')]=this[_0xea07('0xc')]['id'];if(this[_0xea07('0xc')][_0xea07('0x1d')]){var _0x34c1dd=_0x30ec45[0x2];if(!_[_0xea07('0x1e')](_0x34c1dd)){_0x46dd73['body']=utils[_0xea07('0x1f')](_0x34c1dd,this);return rpc[_0x4a8a18+_0xea07('0x20')][_0xea07('0x21')](_0x46dd73)[_0xea07('0x22')](function(_0x2a40a0){logger[_0xea07('0xe')]('[%s][DIALOGFLOW]\x20%s',_0x34b809,_0x46dd73[_0xea07('0x23')]);})[_0xea07('0x24')](function(_0xf2e662){logger[_0xea07('0x25')](_0xea07('0x26'),_0x34b809,JSON[_0xea07('0x27')](_0xf2e662));})[_0xea07('0x28')](function(){logger[_0xea07('0xe')]('[%s][DIALOGFLOW]\x20Welcome\x20Message\x20has\x20been\x20sent!',_0x34b809);_0x18f8ce['stop']();});}else{logger[_0xea07('0xe')](_0xea07('0x29'),_0x34b809);_0x18f8ce[_0xea07('0x2a')]();}}else{var _0xd3a1aa=this;var _0x5267b3=apiai(_0x30ec45[0x0],{'language':_0x30ec45[0x1]||'en'});return _0x5267b3[_0xea07('0x2b')](this[_0xea07('0x2c')][_0xea07('0x23')],{'sessionId':md5(this[_0xea07('0xc')]['id'])})[_0xea07('0x22')](function(_0x469461){_0xd3a1aa[_0xea07('0x23')][_0xea07('0x2d')]=_0x469461;_0x46dd73[_0xea07('0x23')]=_0x469461[_0xea07('0x2e')]['fulfillment'][_0xea07('0x2f')];_0x46dd73[_0xea07('0x30')]='dialogflow';_0x46dd73[_0xea07('0x31')]=JSON[_0xea07('0x27')](_0x469461);return rpc[_0x4a8a18+_0xea07('0x20')]['create'](_0x46dd73)[_0xea07('0x22')](function(_0x2d3903){logger[_0xea07('0xe')](_0xea07('0x26'),_0x34b809,_0x46dd73[_0xea07('0x23')]);if(_0x469461[_0xea07('0x2e')][_0xea07('0x32')][_0xea07('0x33')]){_0x18f8ce[_0xea07('0x10')]();}else{_0x18f8ce[_0xea07('0x2a')]();}})[_0xea07('0x24')](function(_0x3cc35d){logger['error'](_0xea07('0x26'),_0x34b809,JSON[_0xea07('0x27')](_0x3cc35d));_0x18f8ce['next']();});})['catch'](function(_0x5bcdeb){logger[_0xea07('0x25')]('[%s][DIALOGFLOW]\x20%s',_0x34b809,_0x5bcdeb[_0xea07('0x2c')]);_0x18f8ce['next']();});}}catch(_0x498627){logger[_0xea07('0x25')](_0xea07('0x26'),_0x34b809,JSON[_0xea07('0x27')](_0x498627));_0x18f8ce[_0xea07('0x2a')]();}};};