ec5d00ea996835e48fb3174e2108e2db21cec5c5
[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 _0xf322=['YYYY-MM-DD\x20HH:mm:ss','channel','sms','whatsapp','phone','account','AccountId','InteractionId','created','isEmpty','body','Message','create','then','catch','finally','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','textRequest','dialogflow','result','fulfillment','speech','providerName','providerResponse','stringify','metadata','endConversation','message','error','lodash','moment','apiai-promise','./utils','../../../../config/logger','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','consequence','isNil','interaction','UserId','info','[%s][DIALOGFLOW]\x20%s','next'];(function(_0x4cf98e,_0xba4b79){var _0x1623ac=function(_0x459bc0){while(--_0x459bc0){_0x4cf98e['push'](_0x4cf98e['shift']());}};_0x1623ac(++_0xba4b79);}(_0xf322,0xac));var _0x2f32=function(_0x50641e,_0x3bc2fe){_0x50641e=_0x50641e-0x0;var _0x426fa1=_0xf322[_0x50641e];return _0x426fa1;};'use strict';var _=require(_0x2f32('0x0'));var moment=require(_0x2f32('0x1'));var apiai=require(_0x2f32('0x2'));var md5=require('md5');var utils=require(_0x2f32('0x3'));var logger=require(_0x2f32('0x4'))('routing');var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require('../../rpc/openchannelMessage'),'mailMessage':require(_0x2f32('0x5')),'smsMessage':require(_0x2f32('0x6')),'faxMessage':require(_0x2f32('0x7')),'whatsappMessage':require(_0x2f32('0x8'))};exports[_0x2f32('0x9')]=function(_0x4eb81f,_0x4d3ccf){return function(_0x1e25d1){try{if(!_[_0x2f32('0xa')](this[_0x2f32('0xb')][_0x2f32('0xc')])){logger[_0x2f32('0xd')](_0x2f32('0xe'),_0x4eb81f,'Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.');return _0x1e25d1[_0x2f32('0xf')]();}var _0x280c24={'ContactId':this['contact']['id'],'sentAt':moment()['format'](_0x2f32('0x10')),'direction':'out'};if(this[_0x2f32('0x11')]===_0x2f32('0x12')||this[_0x2f32('0x11')]===_0x2f32('0x13')){_0x280c24[_0x2f32('0x14')]=this[_0x2f32('0xb')]['phone'];}var _0x8e4e47=this[_0x2f32('0x11')];if(_0x8e4e47==='chat'){_0x280c24['ChatWebsiteId']=this[_0x2f32('0x15')]['id'];}else{_0x280c24[_['upperFirst'](_0x8e4e47)+_0x2f32('0x16')]=this[_0x2f32('0x15')]['id'];}_0x280c24[_['upperFirst'](_0x8e4e47)+_0x2f32('0x17')]=this['interaction']['id'];if(this['interaction'][_0x2f32('0x18')]){var _0x2f949d=_0x4d3ccf[0x2];if(!_[_0x2f32('0x19')](_0x2f949d)){_0x280c24[_0x2f32('0x1a')]=utils['getMustacheRender'](_0x2f949d,this);return rpc[_0x8e4e47+_0x2f32('0x1b')][_0x2f32('0x1c')](_0x280c24)[_0x2f32('0x1d')](function(_0xa9650c){logger[_0x2f32('0xd')](_0x2f32('0xe'),_0x4eb81f,_0x280c24['body']);})[_0x2f32('0x1e')](function(_0x363725){logger['error'](_0x2f32('0xe'),_0x4eb81f,JSON['stringify'](_0x363725));})[_0x2f32('0x1f')](function(){logger[_0x2f32('0xd')](_0x2f32('0x20'),_0x4eb81f);_0x1e25d1[_0x2f32('0x21')]();});}else{logger[_0x2f32('0xd')](_0x2f32('0x22'),_0x4eb81f);_0x1e25d1['stop']();}}else{var _0x182f56=this;var _0xb5be70=apiai(_0x4d3ccf[0x0],{'language':_0x4d3ccf[0x1]||'en'});return _0xb5be70[_0x2f32('0x23')](this['message']['body'],{'sessionId':md5(this[_0x2f32('0xb')]['id'])})['then'](function(_0x43ae57){_0x182f56[_0x2f32('0x1a')][_0x2f32('0x24')]=_0x43ae57;_0x280c24[_0x2f32('0x1a')]=_0x43ae57[_0x2f32('0x25')][_0x2f32('0x26')][_0x2f32('0x27')];_0x280c24[_0x2f32('0x28')]='dialogflow';_0x280c24[_0x2f32('0x29')]=JSON[_0x2f32('0x2a')](_0x43ae57);return rpc[_0x8e4e47+_0x2f32('0x1b')][_0x2f32('0x1c')](_0x280c24)[_0x2f32('0x1d')](function(_0xdda3ad){logger[_0x2f32('0xd')](_0x2f32('0xe'),_0x4eb81f,_0x280c24[_0x2f32('0x1a')]);if(_0x43ae57[_0x2f32('0x25')][_0x2f32('0x2b')][_0x2f32('0x2c')]){_0x1e25d1[_0x2f32('0xf')]();}else{_0x1e25d1[_0x2f32('0x21')]();}})['catch'](function(_0x207e18){logger['error'](_0x2f32('0xe'),_0x4eb81f,JSON[_0x2f32('0x2a')](_0x207e18));_0x1e25d1[_0x2f32('0xf')]();});})[_0x2f32('0x1e')](function(_0x34277b){logger['error']('[%s][DIALOGFLOW]\x20%s',_0x4eb81f,_0x34277b[_0x2f32('0x2d')]);_0x1e25d1[_0x2f32('0xf')]();});}}catch(_0x33a190){logger[_0x2f32('0x2e')](_0x2f32('0xe'),_0x4eb81f,JSON[_0x2f32('0x2a')](_0x33a190));_0x1e25d1['stop']();}};};