Built motion from commit ff426b3f.|2.6.29
[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 _0xc319=['fulfillment','speech','providerName','providerResponse','metadata','endConversation','next','error','lodash','moment','apiai-promise','./utils','../../../../config/logger','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/whatsappMessage','consequence','isNil','interaction','UserId','info','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','sms','channel','whatsapp','phone','chat','upperFirst','InteractionId','created','isEmpty','body','Message','then','catch','[%s][DIALOGFLOW]\x20%s','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'];(function(_0x124499,_0x13ee4e){var _0x382b23=function(_0x21047d){while(--_0x21047d){_0x124499['push'](_0x124499['shift']());}};_0x382b23(++_0x13ee4e);}(_0xc319,0x12e));var _0x9c31=function(_0x5e1803,_0x4024cd){_0x5e1803=_0x5e1803-0x0;var _0x521bdb=_0xc319[_0x5e1803];return _0x521bdb;};'use strict';var _=require(_0x9c31('0x0'));var moment=require(_0x9c31('0x1'));var apiai=require(_0x9c31('0x2'));var md5=require('md5');var utils=require(_0x9c31('0x3'));var logger=require(_0x9c31('0x4'))('routing');var rpc={'chatMessage':require(_0x9c31('0x5')),'openchannelMessage':require(_0x9c31('0x6')),'mailMessage':require(_0x9c31('0x7')),'smsMessage':require(_0x9c31('0x8')),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require(_0x9c31('0x9'))};exports[_0x9c31('0xa')]=function(_0x348e09,_0x2bdff2){return function(_0x3aa031){try{if(!_[_0x9c31('0xb')](this[_0x9c31('0xc')][_0x9c31('0xd')])){logger[_0x9c31('0xe')]('[%s][DIALOGFLOW]\x20%s',_0x348e09,'Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.');return _0x3aa031['next']();}var _0x1d8b8b={'ContactId':this[_0x9c31('0xf')]['id'],'sentAt':moment()[_0x9c31('0x10')](_0x9c31('0x11')),'direction':_0x9c31('0x12')};if(this['channel']===_0x9c31('0x13')||this[_0x9c31('0x14')]===_0x9c31('0x15')){_0x1d8b8b['phone']=this[_0x9c31('0xc')][_0x9c31('0x16')];}var _0x16632c=this[_0x9c31('0x14')];if(_0x16632c===_0x9c31('0x17')){_0x1d8b8b['ChatWebsiteId']=this['account']['id'];}else{_0x1d8b8b[_['upperFirst'](_0x16632c)+'AccountId']=this['account']['id'];}_0x1d8b8b[_[_0x9c31('0x18')](_0x16632c)+_0x9c31('0x19')]=this['interaction']['id'];if(this[_0x9c31('0xc')][_0x9c31('0x1a')]){var _0x262d24=_0x2bdff2[0x2];if(!_[_0x9c31('0x1b')](_0x262d24)){_0x1d8b8b[_0x9c31('0x1c')]=utils['getMustacheRender'](_0x262d24,this);return rpc[_0x16632c+_0x9c31('0x1d')]['create'](_0x1d8b8b)[_0x9c31('0x1e')](function(_0x4aacad){logger[_0x9c31('0xe')]('[%s][DIALOGFLOW]\x20%s',_0x348e09,_0x1d8b8b[_0x9c31('0x1c')]);})[_0x9c31('0x1f')](function(_0x2ebafa){logger['error'](_0x9c31('0x20'),_0x348e09,JSON[_0x9c31('0x21')](_0x2ebafa));})[_0x9c31('0x22')](function(){logger['info'](_0x9c31('0x23'),_0x348e09);_0x3aa031[_0x9c31('0x24')]();});}else{logger['info'](_0x9c31('0x25'),_0x348e09);_0x3aa031[_0x9c31('0x24')]();}}else{var _0x316917=this;var _0x9fb534=apiai(_0x2bdff2[0x0],{'language':_0x2bdff2[0x1]||'en'});return _0x9fb534['textRequest'](this[_0x9c31('0x26')][_0x9c31('0x1c')],{'sessionId':md5(this[_0x9c31('0xc')]['id'])})[_0x9c31('0x1e')](function(_0x3cfeba){_0x316917[_0x9c31('0x1c')][_0x9c31('0x27')]=_0x3cfeba;_0x1d8b8b['body']=_0x3cfeba[_0x9c31('0x28')][_0x9c31('0x29')][_0x9c31('0x2a')];_0x1d8b8b[_0x9c31('0x2b')]=_0x9c31('0x27');_0x1d8b8b[_0x9c31('0x2c')]=JSON['stringify'](_0x3cfeba);return rpc[_0x16632c+_0x9c31('0x1d')]['create'](_0x1d8b8b)['then'](function(_0x24325c){logger[_0x9c31('0xe')](_0x9c31('0x20'),_0x348e09,_0x1d8b8b[_0x9c31('0x1c')]);if(_0x3cfeba['result'][_0x9c31('0x2d')][_0x9c31('0x2e')]){_0x3aa031[_0x9c31('0x2f')]();}else{_0x3aa031[_0x9c31('0x24')]();}})[_0x9c31('0x1f')](function(_0x8f7f55){logger[_0x9c31('0x30')]('[%s][DIALOGFLOW]\x20%s',_0x348e09,JSON[_0x9c31('0x21')](_0x8f7f55));_0x3aa031[_0x9c31('0x2f')]();});})[_0x9c31('0x1f')](function(_0x44a8b0){logger[_0x9c31('0x30')](_0x9c31('0x20'),_0x348e09,_0x44a8b0[_0x9c31('0x26')]);_0x3aa031[_0x9c31('0x2f')]();});}}catch(_0x27d442){logger[_0x9c31('0x30')](_0x9c31('0x20'),_0x348e09,JSON[_0x9c31('0x21')](_0x27d442));_0x3aa031[_0x9c31('0x24')]();}};};