Built motion from commit (unavailable).|2.5.3
[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 _0xed79=['../../rpc/smsMessage','../../rpc/faxMessage','consequence','isNil','interaction','UserId','info','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','contact','format','out','channel','chat','account','upperFirst','isEmpty','body','Message','create','[%s][DIALOGFLOW]\x20%s','catch','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','then','dialogflow','speech','result','metadata','endConversation','moment','apiai-promise','md5','./utils','routing'];(function(_0x105ae1,_0x331ca5){var _0x28baea=function(_0x5dce9d){while(--_0x5dce9d){_0x105ae1['push'](_0x105ae1['shift']());}};_0x28baea(++_0x331ca5);}(_0xed79,0xc8));var _0x9ed7=function(_0x59a116,_0x317409){_0x59a116=_0x59a116-0x0;var _0x1a764d=_0xed79[_0x59a116];return _0x1a764d;};'use strict';var _=require('lodash');var moment=require(_0x9ed7('0x0'));var apiai=require(_0x9ed7('0x1'));var md5=require(_0x9ed7('0x2'));var utils=require(_0x9ed7('0x3'));var logger=require('../../../../config/logger')(_0x9ed7('0x4'));var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require('../../rpc/openchannelMessage'),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require(_0x9ed7('0x5')),'faxMessage':require(_0x9ed7('0x6')),'whatsappMessage':require('../../rpc/whatsappMessage')};exports[_0x9ed7('0x7')]=function(_0x262238,_0x529979){return function(_0x1d968f){try{if(!_[_0x9ed7('0x8')](this[_0x9ed7('0x9')][_0x9ed7('0xa')])){logger[_0x9ed7('0xb')]('[%s][DIALOGFLOW]\x20%s',_0x262238,_0x9ed7('0xc'));return _0x1d968f[_0x9ed7('0xd')]();}var _0x30efbd={'ContactId':this[_0x9ed7('0xe')]['id'],'sentAt':moment()[_0x9ed7('0xf')]('YYYY-MM-DD\x20HH:mm:ss'),'direction':_0x9ed7('0x10')};var _0x4fce41=this[_0x9ed7('0x11')];if(_0x4fce41===_0x9ed7('0x12')){_0x30efbd['ChatWebsiteId']=this[_0x9ed7('0x13')]['id'];}else{_0x30efbd[_['upperFirst'](_0x4fce41)+'AccountId']=this[_0x9ed7('0x13')]['id'];}_0x30efbd[_[_0x9ed7('0x14')](_0x4fce41)+'InteractionId']=this[_0x9ed7('0x9')]['id'];if(this[_0x9ed7('0x9')]['created']){var _0x3a5558=_0x529979[0x2];if(!_[_0x9ed7('0x15')](_0x3a5558)){_0x30efbd[_0x9ed7('0x16')]=utils['getMustacheRender'](_0x3a5558,this);return rpc[_0x4fce41+_0x9ed7('0x17')][_0x9ed7('0x18')](_0x30efbd)['then'](function(_0x54b48d){logger['info'](_0x9ed7('0x19'),_0x262238,_0x30efbd['body']);})[_0x9ed7('0x1a')](function(_0x1bd3ee){logger[_0x9ed7('0x1b')](_0x9ed7('0x19'),_0x262238,JSON[_0x9ed7('0x1c')](_0x1bd3ee));})[_0x9ed7('0x1d')](function(){logger[_0x9ed7('0xb')](_0x9ed7('0x1e'),_0x262238);_0x1d968f[_0x9ed7('0x1f')]();});}else{logger['info'](_0x9ed7('0x20'),_0x262238);_0x1d968f['stop']();}}else{var _0x1f19d5=this;var _0x4df1e0=apiai(_0x529979[0x0],{'language':_0x529979[0x1]||'en'});return _0x4df1e0[_0x9ed7('0x21')](this[_0x9ed7('0x22')][_0x9ed7('0x16')],{'sessionId':md5(this['interaction']['id'])})[_0x9ed7('0x23')](function(_0x954244){_0x1f19d5[_0x9ed7('0x16')][_0x9ed7('0x24')]=_0x954244;_0x30efbd['body']=_0x954244['result']['fulfillment'][_0x9ed7('0x25')];return rpc[_0x4fce41+'Message'][_0x9ed7('0x18')](_0x30efbd)[_0x9ed7('0x23')](function(_0x511baf){logger[_0x9ed7('0xb')](_0x9ed7('0x19'),_0x262238,_0x30efbd[_0x9ed7('0x16')]);if(_0x954244[_0x9ed7('0x26')][_0x9ed7('0x27')][_0x9ed7('0x28')]){_0x1d968f[_0x9ed7('0xd')]();}else{_0x1d968f[_0x9ed7('0x1f')]();}})[_0x9ed7('0x1a')](function(_0x552c09){logger['error']('[%s][DIALOGFLOW]\x20%s',_0x262238,JSON['stringify'](_0x552c09));_0x1d968f[_0x9ed7('0xd')]();});})[_0x9ed7('0x1a')](function(_0x42c73d){logger['error']('[%s][DIALOGFLOW]\x20%s',_0x262238,_0x42c73d[_0x9ed7('0x22')]);_0x1d968f[_0x9ed7('0xd')]();});}}catch(_0x1bba2b){logger[_0x9ed7('0x1b')](_0x9ed7('0x19'),_0x262238,JSON[_0x9ed7('0x1c')](_0x1bba2b));_0x1d968f['stop']();}};};