Built motion from commit (unavailable).|2.5.4
[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 _0x618c=['fulfillment','speech','result','metadata','endConversation','catch','lodash','apiai-promise','md5','./utils','../../../../config/logger','routing','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','[%s][DIALOGFLOW]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','contact','format','out','channel','chat','account','upperFirst','AccountId','InteractionId','interaction','created','isEmpty','body','Message','create','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!','textRequest','message','dialogflow'];(function(_0x289f18,_0x1cf988){var _0x2bff81=function(_0x235b46){while(--_0x235b46){_0x289f18['push'](_0x289f18['shift']());}};_0x2bff81(++_0x1cf988);}(_0x618c,0x148));var _0xc618=function(_0x505c66,_0x2fa004){_0x505c66=_0x505c66-0x0;var _0x4868df=_0x618c[_0x505c66];return _0x4868df;};'use strict';var _=require(_0xc618('0x0'));var moment=require('moment');var apiai=require(_0xc618('0x1'));var md5=require(_0xc618('0x2'));var utils=require(_0xc618('0x3'));var logger=require(_0xc618('0x4'))(_0xc618('0x5'));var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require(_0xc618('0x6')),'mailMessage':require(_0xc618('0x7')),'smsMessage':require(_0xc618('0x8')),'faxMessage':require(_0xc618('0x9')),'whatsappMessage':require(_0xc618('0xa'))};exports['consequence']=function(_0x3fd2eb,_0x32da05){return function(_0x11255b){try{if(!_['isNil'](this['interaction']['UserId'])){logger['info'](_0xc618('0xb'),_0x3fd2eb,_0xc618('0xc'));return _0x11255b[_0xc618('0xd')]();}var _0x21a57c={'ContactId':this[_0xc618('0xe')]['id'],'sentAt':moment()[_0xc618('0xf')]('YYYY-MM-DD\x20HH:mm:ss'),'direction':_0xc618('0x10')};var _0x2e95fc=this[_0xc618('0x11')];if(_0x2e95fc===_0xc618('0x12')){_0x21a57c['ChatWebsiteId']=this[_0xc618('0x13')]['id'];}else{_0x21a57c[_[_0xc618('0x14')](_0x2e95fc)+_0xc618('0x15')]=this[_0xc618('0x13')]['id'];}_0x21a57c[_[_0xc618('0x14')](_0x2e95fc)+_0xc618('0x16')]=this['interaction']['id'];if(this[_0xc618('0x17')][_0xc618('0x18')]){var _0x252d10=_0x32da05[0x2];if(!_[_0xc618('0x19')](_0x252d10)){_0x21a57c[_0xc618('0x1a')]=utils['getMustacheRender'](_0x252d10,this);return rpc[_0x2e95fc+_0xc618('0x1b')][_0xc618('0x1c')](_0x21a57c)[_0xc618('0x1d')](function(_0x4b325b){logger[_0xc618('0x1e')]('[%s][DIALOGFLOW]\x20%s',_0x3fd2eb,_0x21a57c[_0xc618('0x1a')]);})['catch'](function(_0xf58086){logger[_0xc618('0x1f')]('[%s][DIALOGFLOW]\x20%s',_0x3fd2eb,JSON[_0xc618('0x20')](_0xf58086));})[_0xc618('0x21')](function(){logger['info'](_0xc618('0x22'),_0x3fd2eb);_0x11255b[_0xc618('0x23')]();});}else{logger[_0xc618('0x1e')](_0xc618('0x24'),_0x3fd2eb);_0x11255b[_0xc618('0x23')]();}}else{var _0x378d59=this;var _0x1079b8=apiai(_0x32da05[0x0],{'language':_0x32da05[0x1]||'en'});return _0x1079b8[_0xc618('0x25')](this[_0xc618('0x26')]['body'],{'sessionId':md5(this['interaction']['id'])})[_0xc618('0x1d')](function(_0x57fa3b){_0x378d59[_0xc618('0x1a')][_0xc618('0x27')]=_0x57fa3b;_0x21a57c[_0xc618('0x1a')]=_0x57fa3b['result'][_0xc618('0x28')][_0xc618('0x29')];return rpc[_0x2e95fc+_0xc618('0x1b')]['create'](_0x21a57c)[_0xc618('0x1d')](function(_0x15d52b){logger['info']('[%s][DIALOGFLOW]\x20%s',_0x3fd2eb,_0x21a57c[_0xc618('0x1a')]);if(_0x57fa3b[_0xc618('0x2a')][_0xc618('0x2b')][_0xc618('0x2c')]){_0x11255b[_0xc618('0xd')]();}else{_0x11255b['stop']();}})['catch'](function(_0x481873){logger[_0xc618('0x1f')](_0xc618('0xb'),_0x3fd2eb,JSON['stringify'](_0x481873));_0x11255b[_0xc618('0xd')]();});})[_0xc618('0x2d')](function(_0x37f57a){logger[_0xc618('0x1f')](_0xc618('0xb'),_0x3fd2eb,_0x37f57a[_0xc618('0x26')]);_0x11255b['next']();});}}catch(_0x5ee01b){logger[_0xc618('0x1f')]('[%s][DIALOGFLOW]\x20%s',_0x3fd2eb,JSON['stringify'](_0x5ee01b));_0x11255b[_0xc618('0x23')]();}};};