Built motion from commit 4e7c323b.|2.5.34
[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 _0x2f74=['account','upperFirst','AccountId','InteractionId','created','isEmpty','body','getMustacheRender','Message','then','[%s][DIALOGFLOW]\x20%s','catch','error','stringify','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','stop','textRequest','message','dialogflow','result','providerName','providerResponse','create','metadata','endConversation','lodash','apiai-promise','md5','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','consequence','isNil','interaction','UserId','info','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','contact','format','YYYY-MM-DD\x20HH:mm:ss','channel','sms','whatsapp','phone','ChatWebsiteId'];(function(_0x3cd270,_0x494b6b){var _0x11297d=function(_0x3914b0){while(--_0x3914b0){_0x3cd270['push'](_0x3cd270['shift']());}};_0x11297d(++_0x494b6b);}(_0x2f74,0x7b));var _0x42f7=function(_0x1b9d97,_0x19159b){_0x1b9d97=_0x1b9d97-0x0;var _0x1d7a29=_0x2f74[_0x1b9d97];return _0x1d7a29;};'use strict';var _=require(_0x42f7('0x0'));var moment=require('moment');var apiai=require(_0x42f7('0x1'));var md5=require(_0x42f7('0x2'));var utils=require(_0x42f7('0x3'));var logger=require(_0x42f7('0x4'))(_0x42f7('0x5'));var rpc={'chatMessage':require(_0x42f7('0x6')),'openchannelMessage':require(_0x42f7('0x7')),'mailMessage':require(_0x42f7('0x8')),'smsMessage':require('../../rpc/smsMessage'),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require('../../rpc/whatsappMessage')};exports[_0x42f7('0x9')]=function(_0x1cb6e0,_0x20ff46){return function(_0x36b55e){try{if(!_[_0x42f7('0xa')](this[_0x42f7('0xb')][_0x42f7('0xc')])){logger[_0x42f7('0xd')]('[%s][DIALOGFLOW]\x20%s',_0x1cb6e0,_0x42f7('0xe'));return _0x36b55e[_0x42f7('0xf')]();}var _0x106807={'ContactId':this[_0x42f7('0x10')]['id'],'sentAt':moment()[_0x42f7('0x11')](_0x42f7('0x12')),'direction':'out'};if(this[_0x42f7('0x13')]===_0x42f7('0x14')||this[_0x42f7('0x13')]===_0x42f7('0x15')){_0x106807[_0x42f7('0x16')]=this[_0x42f7('0xb')][_0x42f7('0x16')];}var _0x1601ed=this['channel'];if(_0x1601ed==='chat'){_0x106807[_0x42f7('0x17')]=this[_0x42f7('0x18')]['id'];}else{_0x106807[_[_0x42f7('0x19')](_0x1601ed)+_0x42f7('0x1a')]=this[_0x42f7('0x18')]['id'];}_0x106807[_['upperFirst'](_0x1601ed)+_0x42f7('0x1b')]=this['interaction']['id'];if(this[_0x42f7('0xb')][_0x42f7('0x1c')]){var _0x16d842=_0x20ff46[0x2];if(!_[_0x42f7('0x1d')](_0x16d842)){_0x106807[_0x42f7('0x1e')]=utils[_0x42f7('0x1f')](_0x16d842,this);return rpc[_0x1601ed+_0x42f7('0x20')]['create'](_0x106807)[_0x42f7('0x21')](function(_0x29f472){logger[_0x42f7('0xd')](_0x42f7('0x22'),_0x1cb6e0,_0x106807[_0x42f7('0x1e')]);})[_0x42f7('0x23')](function(_0x503313){logger[_0x42f7('0x24')]('[%s][DIALOGFLOW]\x20%s',_0x1cb6e0,JSON[_0x42f7('0x25')](_0x503313));})['finally'](function(){logger[_0x42f7('0xd')]('[%s][DIALOGFLOW]\x20Welcome\x20Message\x20has\x20been\x20sent!',_0x1cb6e0);_0x36b55e['stop']();});}else{logger['info'](_0x42f7('0x26'),_0x1cb6e0);_0x36b55e[_0x42f7('0x27')]();}}else{var _0x3a04db=this;var _0x2a755a=apiai(_0x20ff46[0x0],{'language':_0x20ff46[0x1]||'en'});return _0x2a755a[_0x42f7('0x28')](this[_0x42f7('0x29')][_0x42f7('0x1e')],{'sessionId':md5(this[_0x42f7('0xb')]['id'])})[_0x42f7('0x21')](function(_0x372709){_0x3a04db[_0x42f7('0x1e')][_0x42f7('0x2a')]=_0x372709;_0x106807[_0x42f7('0x1e')]=_0x372709[_0x42f7('0x2b')]['fulfillment']['speech'];_0x106807[_0x42f7('0x2c')]=_0x42f7('0x2a');_0x106807[_0x42f7('0x2d')]=JSON[_0x42f7('0x25')](_0x372709);return rpc[_0x1601ed+_0x42f7('0x20')][_0x42f7('0x2e')](_0x106807)[_0x42f7('0x21')](function(_0x64859){logger[_0x42f7('0xd')](_0x42f7('0x22'),_0x1cb6e0,_0x106807['body']);if(_0x372709['result'][_0x42f7('0x2f')][_0x42f7('0x30')]){_0x36b55e[_0x42f7('0xf')]();}else{_0x36b55e['stop']();}})[_0x42f7('0x23')](function(_0x2eed6c){logger['error']('[%s][DIALOGFLOW]\x20%s',_0x1cb6e0,JSON[_0x42f7('0x25')](_0x2eed6c));_0x36b55e[_0x42f7('0xf')]();});})[_0x42f7('0x23')](function(_0xf6664c){logger[_0x42f7('0x24')](_0x42f7('0x22'),_0x1cb6e0,_0xf6664c[_0x42f7('0x29')]);_0x36b55e[_0x42f7('0xf')]();});}}catch(_0x3322d2){logger['error'](_0x42f7('0x22'),_0x1cb6e0,JSON[_0x42f7('0x25')](_0x3322d2));_0x36b55e[_0x42f7('0x27')]();}};};