Built motion from commit (unavailable).|2.4.21
[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 _0xbb3d=['moment','md5','./utils','../../../../config/logger','routing','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','consequence','interaction','UserId','info','[%s][DIALOGFLOW]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','format','out','channel','account','upperFirst','InteractionId','created','body','create','error','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','textRequest','then','result','fulfillment','speech','metadata','catch','stringify','message','lodash'];(function(_0x444cd2,_0xd8a7fd){var _0x1cc07f=function(_0x3487dd){while(--_0x3487dd){_0x444cd2['push'](_0x444cd2['shift']());}};_0x1cc07f(++_0xd8a7fd);}(_0xbb3d,0x71));var _0xdbb3=function(_0x1f75d4,_0x183581){_0x1f75d4=_0x1f75d4-0x0;var _0x72f2ca=_0xbb3d[_0x1f75d4];return _0x72f2ca;};'use strict';var _=require(_0xdbb3('0x0'));var moment=require(_0xdbb3('0x1'));var apiai=require('apiai-promise');var md5=require(_0xdbb3('0x2'));var utils=require(_0xdbb3('0x3'));var logger=require(_0xdbb3('0x4'))(_0xdbb3('0x5'));var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require(_0xdbb3('0x6')),'mailMessage':require(_0xdbb3('0x7')),'smsMessage':require(_0xdbb3('0x8')),'faxMessage':require('../../rpc/faxMessage')};exports[_0xdbb3('0x9')]=function(_0x1de197,_0xaa486c){return function(_0x21a0fc){try{if(!_['isNil'](this[_0xdbb3('0xa')][_0xdbb3('0xb')])){logger[_0xdbb3('0xc')](_0xdbb3('0xd'),_0x1de197,_0xdbb3('0xe'));return _0x21a0fc[_0xdbb3('0xf')]();}var _0x43bc68={'ContactId':this['contact']['id'],'sentAt':moment()[_0xdbb3('0x10')]('YYYY-MM-DD\x20HH:mm:ss'),'direction':_0xdbb3('0x11')};var _0x34a4d2=this[_0xdbb3('0x12')];if(_0x34a4d2==='chat'){_0x43bc68['ChatWebsiteId']=this['account']['id'];}else{_0x43bc68[_['upperFirst'](_0x34a4d2)+'AccountId']=this[_0xdbb3('0x13')]['id'];}_0x43bc68[_[_0xdbb3('0x14')](_0x34a4d2)+_0xdbb3('0x15')]=this[_0xdbb3('0xa')]['id'];if(this[_0xdbb3('0xa')][_0xdbb3('0x16')]){var _0x16a2a3=_0xaa486c[0x2];if(!_['isEmpty'](_0x16a2a3)){_0x43bc68[_0xdbb3('0x17')]=utils['getMustacheRender'](_0x16a2a3,this);return rpc[_0x34a4d2+'Message'][_0xdbb3('0x18')](_0x43bc68)['then'](function(_0x2b5243){logger[_0xdbb3('0xc')](_0xdbb3('0xd'),_0x1de197,_0x43bc68['body']);})['catch'](function(_0x2ee9a3){logger[_0xdbb3('0x19')]('[%s][DIALOGFLOW]\x20%s',_0x1de197,JSON['stringify'](_0x2ee9a3));})['finally'](function(){logger[_0xdbb3('0xc')](_0xdbb3('0x1a'),_0x1de197);_0x21a0fc[_0xdbb3('0x1b')]();});}else{logger[_0xdbb3('0xc')](_0xdbb3('0x1c'),_0x1de197);_0x21a0fc['stop']();}}else{var _0x11c9ba=this;var _0x4847=apiai(_0xaa486c[0x0],{'language':_0xaa486c[0x1]||'en'});return _0x4847[_0xdbb3('0x1d')](this['message']['body'],{'sessionId':md5(this[_0xdbb3('0xa')]['id'])})[_0xdbb3('0x1e')](function(_0x32126a){_0x11c9ba[_0xdbb3('0x17')]['dialogflow']=_0x32126a;_0x43bc68['body']=_0x32126a[_0xdbb3('0x1f')][_0xdbb3('0x20')][_0xdbb3('0x21')];return rpc[_0x34a4d2+'Message']['create'](_0x43bc68)[_0xdbb3('0x1e')](function(_0x17b5ed){logger[_0xdbb3('0xc')](_0xdbb3('0xd'),_0x1de197,_0x43bc68[_0xdbb3('0x17')]);if(_0x32126a[_0xdbb3('0x1f')][_0xdbb3('0x22')]['endConversation']){_0x21a0fc[_0xdbb3('0xf')]();}else{_0x21a0fc[_0xdbb3('0x1b')]();}})[_0xdbb3('0x23')](function(_0x28a7fd){logger['error'](_0xdbb3('0xd'),_0x1de197,JSON[_0xdbb3('0x24')](_0x28a7fd));_0x21a0fc['next']();});})[_0xdbb3('0x23')](function(_0x4e91ca){logger['error'](_0xdbb3('0xd'),_0x1de197,_0x4e91ca[_0xdbb3('0x25')]);_0x21a0fc[_0xdbb3('0xf')]();});}}catch(_0x314d88){logger[_0xdbb3('0x19')]('[%s][DIALOGFLOW]\x20%s',_0x1de197,JSON[_0xdbb3('0x24')](_0x314d88));_0x21a0fc[_0xdbb3('0x1b')]();}};};