9a2e3661f1140a7d190fb5630676b280a06bd9e3
[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 _0xb4c7=['providerName','providerResponse','metadata','endConversation','lodash','moment','apiai-promise','md5','./utils','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/whatsappMessage','consequence','isNil','UserId','info','[%s][DIALOGFLOW]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','channel','whatsapp','phone','interaction','chat','ChatWebsiteId','account','AccountId','upperFirst','InteractionId','created','body','getMustacheRender','Message','create','catch','error','stringify','[%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','result','fulfillment','speech'];(function(_0xe77565,_0x2aaa7c){var _0x8ee878=function(_0x256bb7){while(--_0x256bb7){_0xe77565['push'](_0xe77565['shift']());}};_0x8ee878(++_0x2aaa7c);}(_0xb4c7,0x1ea));var _0x7b4c=function(_0x1e5399,_0x245ae4){_0x1e5399=_0x1e5399-0x0;var _0x42157b=_0xb4c7[_0x1e5399];return _0x42157b;};'use strict';var _=require(_0x7b4c('0x0'));var moment=require(_0x7b4c('0x1'));var apiai=require(_0x7b4c('0x2'));var md5=require(_0x7b4c('0x3'));var utils=require(_0x7b4c('0x4'));var logger=require('../../../../config/logger')(_0x7b4c('0x5'));var rpc={'chatMessage':require(_0x7b4c('0x6')),'openchannelMessage':require(_0x7b4c('0x7')),'mailMessage':require(_0x7b4c('0x8')),'smsMessage':require(_0x7b4c('0x9')),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require(_0x7b4c('0xa'))};exports[_0x7b4c('0xb')]=function(_0x2dd5c7,_0x4bf85d){return function(_0x2d7b7e){try{if(!_[_0x7b4c('0xc')](this['interaction'][_0x7b4c('0xd')])){logger[_0x7b4c('0xe')](_0x7b4c('0xf'),_0x2dd5c7,_0x7b4c('0x10'));return _0x2d7b7e[_0x7b4c('0x11')]();}var _0x93d013={'ContactId':this[_0x7b4c('0x12')]['id'],'sentAt':moment()[_0x7b4c('0x13')](_0x7b4c('0x14')),'direction':_0x7b4c('0x15')};if(this['channel']==='sms'||this[_0x7b4c('0x16')]===_0x7b4c('0x17')){_0x93d013[_0x7b4c('0x18')]=this[_0x7b4c('0x19')][_0x7b4c('0x18')];}var _0x341d36=this[_0x7b4c('0x16')];if(_0x341d36===_0x7b4c('0x1a')){_0x93d013[_0x7b4c('0x1b')]=this[_0x7b4c('0x1c')]['id'];}else{_0x93d013[_['upperFirst'](_0x341d36)+_0x7b4c('0x1d')]=this[_0x7b4c('0x1c')]['id'];}_0x93d013[_[_0x7b4c('0x1e')](_0x341d36)+_0x7b4c('0x1f')]=this[_0x7b4c('0x19')]['id'];if(this[_0x7b4c('0x19')][_0x7b4c('0x20')]){var _0x22c409=_0x4bf85d[0x2];if(!_['isEmpty'](_0x22c409)){_0x93d013[_0x7b4c('0x21')]=utils[_0x7b4c('0x22')](_0x22c409,this);return rpc[_0x341d36+_0x7b4c('0x23')][_0x7b4c('0x24')](_0x93d013)['then'](function(_0x3ce10c){logger[_0x7b4c('0xe')](_0x7b4c('0xf'),_0x2dd5c7,_0x93d013[_0x7b4c('0x21')]);})[_0x7b4c('0x25')](function(_0x1363b4){logger[_0x7b4c('0x26')](_0x7b4c('0xf'),_0x2dd5c7,JSON[_0x7b4c('0x27')](_0x1363b4));})['finally'](function(){logger[_0x7b4c('0xe')](_0x7b4c('0x28'),_0x2dd5c7);_0x2d7b7e[_0x7b4c('0x29')]();});}else{logger[_0x7b4c('0xe')](_0x7b4c('0x2a'),_0x2dd5c7);_0x2d7b7e[_0x7b4c('0x29')]();}}else{var _0x176704=this;var _0x3d4826=apiai(_0x4bf85d[0x0],{'language':_0x4bf85d[0x1]||'en'});return _0x3d4826[_0x7b4c('0x2b')](this[_0x7b4c('0x2c')]['body'],{'sessionId':md5(this[_0x7b4c('0x19')]['id'])})[_0x7b4c('0x2d')](function(_0x276271){_0x176704[_0x7b4c('0x21')][_0x7b4c('0x2e')]=_0x276271;_0x93d013[_0x7b4c('0x21')]=_0x276271[_0x7b4c('0x2f')][_0x7b4c('0x30')][_0x7b4c('0x31')];_0x93d013[_0x7b4c('0x32')]=_0x7b4c('0x2e');_0x93d013[_0x7b4c('0x33')]=JSON[_0x7b4c('0x27')](_0x276271);return rpc[_0x341d36+'Message'][_0x7b4c('0x24')](_0x93d013)[_0x7b4c('0x2d')](function(_0x1fe0f5){logger[_0x7b4c('0xe')](_0x7b4c('0xf'),_0x2dd5c7,_0x93d013[_0x7b4c('0x21')]);if(_0x276271[_0x7b4c('0x2f')][_0x7b4c('0x34')][_0x7b4c('0x35')]){_0x2d7b7e[_0x7b4c('0x11')]();}else{_0x2d7b7e[_0x7b4c('0x29')]();}})[_0x7b4c('0x25')](function(_0x3544bc){logger[_0x7b4c('0x26')](_0x7b4c('0xf'),_0x2dd5c7,JSON[_0x7b4c('0x27')](_0x3544bc));_0x2d7b7e[_0x7b4c('0x11')]();});})[_0x7b4c('0x25')](function(_0x9d3d31){logger['error']('[%s][DIALOGFLOW]\x20%s',_0x2dd5c7,_0x9d3d31['message']);_0x2d7b7e[_0x7b4c('0x11')]();});}}catch(_0x2efff3){logger[_0x7b4c('0x26')](_0x7b4c('0xf'),_0x2dd5c7,JSON['stringify'](_0x2efff3));_0x2d7b7e[_0x7b4c('0x29')]();}};};