dee9204ecc6d2f73bcaa4ad29ad02da611394b9e
[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 _0x8be8=['error','lodash','moment','apiai-promise','md5','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/smsMessage','../../rpc/whatsappMessage','isNil','interaction','UserId','[%s][DIALOGFLOW]\x20%s','next','contact','YYYY-MM-DD\x20HH:mm:ss','out','channel','phone','chat','ChatWebsiteId','account','upperFirst','AccountId','InteractionId','isEmpty','getMustacheRender','Message','create','then','info','body','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','textRequest','message','dialogflow','result','fulfillment','speech','providerResponse','stringify','metadata','endConversation','catch'];(function(_0x138feb,_0x9ab7e9){var _0x3742b6=function(_0x44806f){while(--_0x44806f){_0x138feb['push'](_0x138feb['shift']());}};_0x3742b6(++_0x9ab7e9);}(_0x8be8,0xf6));var _0x88be=function(_0x419018,_0x23a46c){_0x419018=_0x419018-0x0;var _0x2197ef=_0x8be8[_0x419018];return _0x2197ef;};'use strict';var _=require(_0x88be('0x0'));var moment=require(_0x88be('0x1'));var apiai=require(_0x88be('0x2'));var md5=require(_0x88be('0x3'));var utils=require(_0x88be('0x4'));var logger=require(_0x88be('0x5'))(_0x88be('0x6'));var rpc={'chatMessage':require(_0x88be('0x7')),'openchannelMessage':require(_0x88be('0x8')),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require(_0x88be('0x9')),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require(_0x88be('0xa'))};exports['consequence']=function(_0xe98d35,_0x50fc6e){return function(_0xb5d944){try{if(!_[_0x88be('0xb')](this[_0x88be('0xc')][_0x88be('0xd')])){logger['info'](_0x88be('0xe'),_0xe98d35,'Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.');return _0xb5d944[_0x88be('0xf')]();}var _0x2f6fb0={'ContactId':this[_0x88be('0x10')]['id'],'sentAt':moment()['format'](_0x88be('0x11')),'direction':_0x88be('0x12')};if(this[_0x88be('0x13')]==='sms'||this[_0x88be('0x13')]==='whatsapp'){_0x2f6fb0[_0x88be('0x14')]=this['interaction']['phone'];}var _0x3cacc3=this[_0x88be('0x13')];if(_0x3cacc3===_0x88be('0x15')){_0x2f6fb0[_0x88be('0x16')]=this[_0x88be('0x17')]['id'];}else{_0x2f6fb0[_[_0x88be('0x18')](_0x3cacc3)+_0x88be('0x19')]=this[_0x88be('0x17')]['id'];}_0x2f6fb0[_['upperFirst'](_0x3cacc3)+_0x88be('0x1a')]=this[_0x88be('0xc')]['id'];if(this[_0x88be('0xc')]['created']){var _0x5658e4=_0x50fc6e[0x2];if(!_[_0x88be('0x1b')](_0x5658e4)){_0x2f6fb0['body']=utils[_0x88be('0x1c')](_0x5658e4,this);return rpc[_0x3cacc3+_0x88be('0x1d')][_0x88be('0x1e')](_0x2f6fb0)[_0x88be('0x1f')](function(_0x152918){logger[_0x88be('0x20')](_0x88be('0xe'),_0xe98d35,_0x2f6fb0[_0x88be('0x21')]);})['catch'](function(_0x3d83b0){logger['error'](_0x88be('0xe'),_0xe98d35,JSON['stringify'](_0x3d83b0));})['finally'](function(){logger[_0x88be('0x20')](_0x88be('0x22'),_0xe98d35);_0xb5d944[_0x88be('0x23')]();});}else{logger['info'](_0x88be('0x24'),_0xe98d35);_0xb5d944[_0x88be('0x23')]();}}else{var _0x1d0414=this;var _0x213580=apiai(_0x50fc6e[0x0],{'language':_0x50fc6e[0x1]||'en'});return _0x213580[_0x88be('0x25')](this[_0x88be('0x26')][_0x88be('0x21')],{'sessionId':md5(this[_0x88be('0xc')]['id'])})[_0x88be('0x1f')](function(_0x215024){_0x1d0414[_0x88be('0x21')][_0x88be('0x27')]=_0x215024;_0x2f6fb0[_0x88be('0x21')]=_0x215024[_0x88be('0x28')][_0x88be('0x29')][_0x88be('0x2a')];_0x2f6fb0['providerName']=_0x88be('0x27');_0x2f6fb0[_0x88be('0x2b')]=JSON[_0x88be('0x2c')](_0x215024);return rpc[_0x3cacc3+'Message'][_0x88be('0x1e')](_0x2f6fb0)[_0x88be('0x1f')](function(_0x1ca77c){logger[_0x88be('0x20')](_0x88be('0xe'),_0xe98d35,_0x2f6fb0['body']);if(_0x215024[_0x88be('0x28')][_0x88be('0x2d')][_0x88be('0x2e')]){_0xb5d944['next']();}else{_0xb5d944[_0x88be('0x23')]();}})[_0x88be('0x2f')](function(_0x1af670){logger[_0x88be('0x30')](_0x88be('0xe'),_0xe98d35,JSON[_0x88be('0x2c')](_0x1af670));_0xb5d944[_0x88be('0xf')]();});})[_0x88be('0x2f')](function(_0x1de831){logger['error'](_0x88be('0xe'),_0xe98d35,_0x1de831[_0x88be('0x26')]);_0xb5d944[_0x88be('0xf')]();});}}catch(_0x23ccbe){logger[_0x88be('0x30')](_0x88be('0xe'),_0xe98d35,JSON[_0x88be('0x2c')](_0x23ccbe));_0xb5d944[_0x88be('0x23')]();}};};