Built motion from commit da24aabd.|2.6.20
[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 _0xad40=['textRequest','message','then','dialogflow','result','providerName','stringify','metadata','endConversation','error','lodash','moment','apiai-promise','md5','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','consequence','isNil','interaction','UserId','[%s][DIALOGFLOW]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','contact','format','YYYY-MM-DD\x20HH:mm:ss','channel','sms','whatsapp','phone','chat','account','AccountId','upperFirst','created','isEmpty','body','Message','create','info','catch','stop','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!'];(function(_0x1a08cc,_0x1ff763){var _0x2ce2ec=function(_0x4c28a9){while(--_0x4c28a9){_0x1a08cc['push'](_0x1a08cc['shift']());}};_0x2ce2ec(++_0x1ff763);}(_0xad40,0xfa));var _0x0ad4=function(_0x31e29a,_0x349c9b){_0x31e29a=_0x31e29a-0x0;var _0x32d892=_0xad40[_0x31e29a];return _0x32d892;};'use strict';var _=require(_0x0ad4('0x0'));var moment=require(_0x0ad4('0x1'));var apiai=require(_0x0ad4('0x2'));var md5=require(_0x0ad4('0x3'));var utils=require('./utils');var logger=require(_0x0ad4('0x4'))(_0x0ad4('0x5'));var rpc={'chatMessage':require(_0x0ad4('0x6')),'openchannelMessage':require(_0x0ad4('0x7')),'mailMessage':require(_0x0ad4('0x8')),'smsMessage':require(_0x0ad4('0x9')),'faxMessage':require(_0x0ad4('0xa')),'whatsappMessage':require('../../rpc/whatsappMessage')};exports[_0x0ad4('0xb')]=function(_0x1ad5fc,_0x1fa7ac){return function(_0x3e738d){try{if(!_[_0x0ad4('0xc')](this[_0x0ad4('0xd')][_0x0ad4('0xe')])){logger['info'](_0x0ad4('0xf'),_0x1ad5fc,_0x0ad4('0x10'));return _0x3e738d[_0x0ad4('0x11')]();}var _0x2c5757={'ContactId':this[_0x0ad4('0x12')]['id'],'sentAt':moment()[_0x0ad4('0x13')](_0x0ad4('0x14')),'direction':'out'};if(this[_0x0ad4('0x15')]===_0x0ad4('0x16')||this[_0x0ad4('0x15')]===_0x0ad4('0x17')){_0x2c5757[_0x0ad4('0x18')]=this[_0x0ad4('0xd')][_0x0ad4('0x18')];}var _0x67f340=this[_0x0ad4('0x15')];if(_0x67f340===_0x0ad4('0x19')){_0x2c5757['ChatWebsiteId']=this[_0x0ad4('0x1a')]['id'];}else{_0x2c5757[_['upperFirst'](_0x67f340)+_0x0ad4('0x1b')]=this['account']['id'];}_0x2c5757[_[_0x0ad4('0x1c')](_0x67f340)+'InteractionId']=this[_0x0ad4('0xd')]['id'];if(this['interaction'][_0x0ad4('0x1d')]){var _0x5a611f=_0x1fa7ac[0x2];if(!_[_0x0ad4('0x1e')](_0x5a611f)){_0x2c5757[_0x0ad4('0x1f')]=utils['getMustacheRender'](_0x5a611f,this);return rpc[_0x67f340+_0x0ad4('0x20')][_0x0ad4('0x21')](_0x2c5757)['then'](function(_0x196d75){logger[_0x0ad4('0x22')](_0x0ad4('0xf'),_0x1ad5fc,_0x2c5757[_0x0ad4('0x1f')]);})[_0x0ad4('0x23')](function(_0x5a3460){logger['error'](_0x0ad4('0xf'),_0x1ad5fc,JSON['stringify'](_0x5a3460));})['finally'](function(){logger[_0x0ad4('0x22')]('[%s][DIALOGFLOW]\x20Welcome\x20Message\x20has\x20been\x20sent!',_0x1ad5fc);_0x3e738d[_0x0ad4('0x24')]();});}else{logger[_0x0ad4('0x22')](_0x0ad4('0x25'),_0x1ad5fc);_0x3e738d[_0x0ad4('0x24')]();}}else{var _0x34810e=this;var _0x327bf8=apiai(_0x1fa7ac[0x0],{'language':_0x1fa7ac[0x1]||'en'});return _0x327bf8[_0x0ad4('0x26')](this[_0x0ad4('0x27')][_0x0ad4('0x1f')],{'sessionId':md5(this[_0x0ad4('0xd')]['id'])})[_0x0ad4('0x28')](function(_0x2bd3f2){_0x34810e[_0x0ad4('0x1f')][_0x0ad4('0x29')]=_0x2bd3f2;_0x2c5757['body']=_0x2bd3f2[_0x0ad4('0x2a')]['fulfillment']['speech'];_0x2c5757[_0x0ad4('0x2b')]=_0x0ad4('0x29');_0x2c5757['providerResponse']=JSON[_0x0ad4('0x2c')](_0x2bd3f2);return rpc[_0x67f340+_0x0ad4('0x20')][_0x0ad4('0x21')](_0x2c5757)[_0x0ad4('0x28')](function(_0x53af91){logger[_0x0ad4('0x22')](_0x0ad4('0xf'),_0x1ad5fc,_0x2c5757[_0x0ad4('0x1f')]);if(_0x2bd3f2[_0x0ad4('0x2a')][_0x0ad4('0x2d')][_0x0ad4('0x2e')]){_0x3e738d['next']();}else{_0x3e738d[_0x0ad4('0x24')]();}})[_0x0ad4('0x23')](function(_0x529826){logger['error'](_0x0ad4('0xf'),_0x1ad5fc,JSON['stringify'](_0x529826));_0x3e738d['next']();});})[_0x0ad4('0x23')](function(_0x4df804){logger[_0x0ad4('0x2f')](_0x0ad4('0xf'),_0x1ad5fc,_0x4df804[_0x0ad4('0x27')]);_0x3e738d['next']();});}}catch(_0x2e8fed){logger[_0x0ad4('0x2f')](_0x0ad4('0xf'),_0x1ad5fc,JSON[_0x0ad4('0x2c')](_0x2e8fed));_0x3e738d[_0x0ad4('0x24')]();}};};