firebase/functions/index.js
// Function to send correctly formatted Google Assistant responses to Dialogflow which are then sent to the user
Function to send correctly formatted Google Assistant responses to Dialogflow which are then sent to the user
Function to send correctly formatted Google Assistant responses to Dialogflow which are then sent to the user
function sendGoogleResponse (responseToUser) {
    if (typeof responseToUser === 'string') {
      app.ask(responseToUser); 
    } else {
      let googleResponse = app.buildRichResponse().addSimpleResponse({
        speech: responseToUser.speech || responseToUser.text,
        displayText: responseToUser.text || responseToUser.speech
      });
      if (responseToUser.googleRichResponse) {
        googleResponse = responseToUser.googleRichResponse;
      }
      if (responseToUser.googleOutputContexts) {
        app.setContext(...responseToUser.googleOutputContexts);
      }
      console.log('Response to Dialogflow (AoG): ' + JSON.stringify(googleResponse));
      app.ask({
        speech: responseToUser.speech || responseToUser.text,
        displayText: responseToUser.text || responseToUser.speech
      });
    }
  }
function sendGoogleResponse ( responseToUser ) { if ( typeof responseToUser === 'string' ) { app . ask ( responseToUser ) ; } else { let googleResponse = app . buildRichResponse ( ) . addSimpleResponse ( { speech : responseToUser . speech || responseToUser . text , displayText : responseToUser . text || responseToUser . speech } ) ; if ( responseToUser . googleRichResponse ) { googleResponse = responseToUser . googleRichResponse ; } if ( responseToUser . googleOutputContexts ) { app . setContext ( ... responseToUser . googleOutputContexts ) ; } console . log ( 'Response to Dialogflow (AoG): ' + JSON . stringify ( googleResponse ) ) ; app . ask ( { speech : responseToUser . speech || responseToUser . text , displayText : responseToUser . text || responseToUser . speech } ) ; } }
Function to send correctly formatted Google Assistant responses to Dialogflow which are then sent to the user
Function to send correctly formatted Google Assistant responses to Dialogflow which are then sent to the user
// Google Assistant response // If speech or displayText is defined use it to respond // Optional: Overwrite previous response with rich response // Optional: add contexts (https://dialogflow.com/docs/contexts) //app.ask(googleResponse); // Send response to Dialogflow and Google Assistant