Built motion from commit 85328c08.|2.5.50
[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 _0xa49e=['dialogflow','result','fulfillment','providerName','providerResponse','metadata','endConversation','next','catch','error','lodash','moment','apiai-promise','md5','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','consequence','isNil','UserId','[%s][DIALOGFLOW]\x20%s','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','channel','sms','whatsapp','phone','interaction','chat','ChatWebsiteId','account','AccountId','InteractionId','created','body','Message','create','then','info','stringify','finally','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','textRequest','message'];(function(_0x365009,_0x215c27){var _0x19fc0c=function(_0x30963f){while(--_0x30963f){_0x365009['push'](_0x365009['shift']());}};_0x19fc0c(++_0x215c27);}(_0xa49e,0x1de));var _0xea49=function(_0x597bf3,_0x3a2bd8){_0x597bf3=_0x597bf3-0x0;var _0x4db0db=_0xa49e[_0x597bf3];return _0x4db0db;};'use strict';var _=require(_0xea49('0x0'));var moment=require(_0xea49('0x1'));var apiai=require(_0xea49('0x2'));var md5=require(_0xea49('0x3'));var utils=require(_0xea49('0x4'));var logger=require(_0xea49('0x5'))(_0xea49('0x6'));var rpc={'chatMessage':require(_0xea49('0x7')),'openchannelMessage':require('../../rpc/openchannelMessage'),'mailMessage':require(_0xea49('0x8')),'smsMessage':require(_0xea49('0x9')),'faxMessage':require(_0xea49('0xa')),'whatsappMessage':require('../../rpc/whatsappMessage')};exports[_0xea49('0xb')]=function(_0x184e00,_0xc682a){return function(_0x35c89e){try{if(!_[_0xea49('0xc')](this['interaction'][_0xea49('0xd')])){logger['info'](_0xea49('0xe'),_0x184e00,'Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.');return _0x35c89e['next']();}var _0x5a3eb6={'ContactId':this[_0xea49('0xf')]['id'],'sentAt':moment()[_0xea49('0x10')](_0xea49('0x11')),'direction':_0xea49('0x12')};if(this[_0xea49('0x13')]===_0xea49('0x14')||this[_0xea49('0x13')]===_0xea49('0x15')){_0x5a3eb6[_0xea49('0x16')]=this[_0xea49('0x17')][_0xea49('0x16')];}var _0x5095b6=this[_0xea49('0x13')];if(_0x5095b6===_0xea49('0x18')){_0x5a3eb6[_0xea49('0x19')]=this[_0xea49('0x1a')]['id'];}else{_0x5a3eb6[_['upperFirst'](_0x5095b6)+_0xea49('0x1b')]=this[_0xea49('0x1a')]['id'];}_0x5a3eb6[_['upperFirst'](_0x5095b6)+_0xea49('0x1c')]=this[_0xea49('0x17')]['id'];if(this[_0xea49('0x17')][_0xea49('0x1d')]){var _0x5265a3=_0xc682a[0x2];if(!_['isEmpty'](_0x5265a3)){_0x5a3eb6[_0xea49('0x1e')]=utils['getMustacheRender'](_0x5265a3,this);return rpc[_0x5095b6+_0xea49('0x1f')][_0xea49('0x20')](_0x5a3eb6)[_0xea49('0x21')](function(_0x5f2984){logger[_0xea49('0x22')](_0xea49('0xe'),_0x184e00,_0x5a3eb6[_0xea49('0x1e')]);})['catch'](function(_0x8c7b9e){logger['error'](_0xea49('0xe'),_0x184e00,JSON[_0xea49('0x23')](_0x8c7b9e));})[_0xea49('0x24')](function(){logger[_0xea49('0x22')](_0xea49('0x25'),_0x184e00);_0x35c89e[_0xea49('0x26')]();});}else{logger[_0xea49('0x22')](_0xea49('0x27'),_0x184e00);_0x35c89e['stop']();}}else{var _0x9f1fc2=this;var _0x544cbb=apiai(_0xc682a[0x0],{'language':_0xc682a[0x1]||'en'});return _0x544cbb[_0xea49('0x28')](this[_0xea49('0x29')][_0xea49('0x1e')],{'sessionId':md5(this[_0xea49('0x17')]['id'])})[_0xea49('0x21')](function(_0x4b22d8){_0x9f1fc2[_0xea49('0x1e')][_0xea49('0x2a')]=_0x4b22d8;_0x5a3eb6[_0xea49('0x1e')]=_0x4b22d8[_0xea49('0x2b')][_0xea49('0x2c')]['speech'];_0x5a3eb6[_0xea49('0x2d')]=_0xea49('0x2a');_0x5a3eb6[_0xea49('0x2e')]=JSON[_0xea49('0x23')](_0x4b22d8);return rpc[_0x5095b6+'Message'][_0xea49('0x20')](_0x5a3eb6)[_0xea49('0x21')](function(_0x2c5f8d){logger[_0xea49('0x22')](_0xea49('0xe'),_0x184e00,_0x5a3eb6['body']);if(_0x4b22d8[_0xea49('0x2b')][_0xea49('0x2f')][_0xea49('0x30')]){_0x35c89e[_0xea49('0x31')]();}else{_0x35c89e[_0xea49('0x26')]();}})[_0xea49('0x32')](function(_0x437fe8){logger[_0xea49('0x33')](_0xea49('0xe'),_0x184e00,JSON['stringify'](_0x437fe8));_0x35c89e['next']();});})[_0xea49('0x32')](function(_0x268266){logger[_0xea49('0x33')]('[%s][DIALOGFLOW]\x20%s',_0x184e00,_0x268266[_0xea49('0x29')]);_0x35c89e['next']();});}}catch(_0x4e7bd6){logger[_0xea49('0x33')](_0xea49('0xe'),_0x184e00,JSON['stringify'](_0x4e7bd6));_0x35c89e[_0xea49('0x26')]();}};};