830294214cf88f620f8478bcb2ee1376805a10a4
[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 _0x59e5=['stop','message','result','speech','providerName','dialogflow','providerResponse','metadata','endConversation','catch','error','lodash','moment','apiai-promise','md5','./utils','routing','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/whatsappMessage','consequence','isNil','UserId','info','[%s][DIALOGFLOW]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','contact','YYYY-MM-DD\x20HH:mm:ss','channel','whatsapp','phone','interaction','chat','account','upperFirst','AccountId','created','isEmpty','body','Message','create','then','stringify','finally','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!'];(function(_0x26b226,_0x189d87){var _0x4e282d=function(_0x1699ef){while(--_0x1699ef){_0x26b226['push'](_0x26b226['shift']());}};_0x4e282d(++_0x189d87);}(_0x59e5,0x14d));var _0x559e=function(_0x475799,_0x585f19){_0x475799=_0x475799-0x0;var _0xca44a0=_0x59e5[_0x475799];return _0xca44a0;};'use strict';var _=require(_0x559e('0x0'));var moment=require(_0x559e('0x1'));var apiai=require(_0x559e('0x2'));var md5=require(_0x559e('0x3'));var utils=require(_0x559e('0x4'));var logger=require('../../../../config/logger')(_0x559e('0x5'));var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require('../../rpc/openchannelMessage'),'mailMessage':require(_0x559e('0x6')),'smsMessage':require(_0x559e('0x7')),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require(_0x559e('0x8'))};exports[_0x559e('0x9')]=function(_0x391862,_0x24d95d){return function(_0x43dbe8){try{if(!_[_0x559e('0xa')](this['interaction'][_0x559e('0xb')])){logger[_0x559e('0xc')](_0x559e('0xd'),_0x391862,_0x559e('0xe'));return _0x43dbe8[_0x559e('0xf')]();}var _0x5ea406={'ContactId':this[_0x559e('0x10')]['id'],'sentAt':moment()['format'](_0x559e('0x11')),'direction':'out'};if(this[_0x559e('0x12')]==='sms'||this['channel']===_0x559e('0x13')){_0x5ea406[_0x559e('0x14')]=this[_0x559e('0x15')][_0x559e('0x14')];}var _0x3eae8d=this[_0x559e('0x12')];if(_0x3eae8d===_0x559e('0x16')){_0x5ea406['ChatWebsiteId']=this[_0x559e('0x17')]['id'];}else{_0x5ea406[_[_0x559e('0x18')](_0x3eae8d)+_0x559e('0x19')]=this[_0x559e('0x17')]['id'];}_0x5ea406[_[_0x559e('0x18')](_0x3eae8d)+'InteractionId']=this[_0x559e('0x15')]['id'];if(this[_0x559e('0x15')][_0x559e('0x1a')]){var _0x219b66=_0x24d95d[0x2];if(!_[_0x559e('0x1b')](_0x219b66)){_0x5ea406[_0x559e('0x1c')]=utils['getMustacheRender'](_0x219b66,this);return rpc[_0x3eae8d+_0x559e('0x1d')][_0x559e('0x1e')](_0x5ea406)[_0x559e('0x1f')](function(_0x4e7bc0){logger[_0x559e('0xc')](_0x559e('0xd'),_0x391862,_0x5ea406[_0x559e('0x1c')]);})['catch'](function(_0xb2407a){logger['error'](_0x559e('0xd'),_0x391862,JSON[_0x559e('0x20')](_0xb2407a));})[_0x559e('0x21')](function(){logger[_0x559e('0xc')]('[%s][DIALOGFLOW]\x20Welcome\x20Message\x20has\x20been\x20sent!',_0x391862);_0x43dbe8['stop']();});}else{logger[_0x559e('0xc')](_0x559e('0x22'),_0x391862);_0x43dbe8[_0x559e('0x23')]();}}else{var _0x2eb700=this;var _0x35de1d=apiai(_0x24d95d[0x0],{'language':_0x24d95d[0x1]||'en'});return _0x35de1d['textRequest'](this[_0x559e('0x24')][_0x559e('0x1c')],{'sessionId':md5(this[_0x559e('0x15')]['id'])})[_0x559e('0x1f')](function(_0x154e7a){_0x2eb700[_0x559e('0x1c')]['dialogflow']=_0x154e7a;_0x5ea406[_0x559e('0x1c')]=_0x154e7a[_0x559e('0x25')]['fulfillment'][_0x559e('0x26')];_0x5ea406[_0x559e('0x27')]=_0x559e('0x28');_0x5ea406[_0x559e('0x29')]=JSON['stringify'](_0x154e7a);return rpc[_0x3eae8d+'Message'][_0x559e('0x1e')](_0x5ea406)['then'](function(_0x4356d5){logger[_0x559e('0xc')](_0x559e('0xd'),_0x391862,_0x5ea406[_0x559e('0x1c')]);if(_0x154e7a[_0x559e('0x25')][_0x559e('0x2a')][_0x559e('0x2b')]){_0x43dbe8[_0x559e('0xf')]();}else{_0x43dbe8['stop']();}})[_0x559e('0x2c')](function(_0x20740a){logger[_0x559e('0x2d')](_0x559e('0xd'),_0x391862,JSON[_0x559e('0x20')](_0x20740a));_0x43dbe8[_0x559e('0xf')]();});})[_0x559e('0x2c')](function(_0x5ec168){logger[_0x559e('0x2d')](_0x559e('0xd'),_0x391862,_0x5ec168[_0x559e('0x24')]);_0x43dbe8[_0x559e('0xf')]();});}}catch(_0x223c4e){logger[_0x559e('0x2d')]('[%s][DIALOGFLOW]\x20%s',_0x391862,JSON['stringify'](_0x223c4e));_0x43dbe8[_0x559e('0x23')]();}};};