How to use the actions-on-google.ApiAiAssistant function in actions-on-google

To help you get started, we’ve selected a few actions-on-google examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github androidthings / photobooth / firebase / functions / index.js View on Github external
exports.photoboothAssistantApp = functions.https.onRequest((req, res) => {
  const app = new Assistant({request: req, response: res});
  console.log('Request headers: ' + JSON.stringify(req.headers));
  console.log('Request body: ' + JSON.stringify(req.body));

  const actionMap = new Map([
    // Starting the interaction, asking if the user likes it, picture retakes
    [APIAI.action.START, handle.start],
    [APIAI.action.PICTURE_DENIED, handle.takePicture],
    // asking if the user wants style to their selected photo
    [APIAI.action.PICTURE_APPROVED, handle.stylePictureInquiry],
    // asking the user if they want to upload/print their photo
    [APIAI.action.STYLE_PICTURE_APPROVED, handle.sharePhotoInquiryStall],
    [APIAI.action.STYLE_PICTURE_DENIED, handle.sharePhotoInquiry],
    // Uploading the picture
    [APIAI.action.PICTURE_UPLOAD_APPROVED, handle.photoShared],
    [APIAI.action.PICTURE_UPLOAD_DENIED, handle.photoNotShared],
    // Fallback and other actions
github voxable-labs / actions-on-google-api-ai-boilerplate / server.js View on Github external'/', function(req, res, next) {
  // Log the request headers and body, to aide in debugging. You'll be able to view the
  // webhook requests coming from API.AI by clicking the Logs button the sidebar.
  logObject('Request headers: ', req.headers);
  logObject('Request body: ', req.body);
  // Instantiate a new API.AI assistant object.
  const assistant = new ApiAiAssistant({request: req, response: res});

  // Declare constants for your action and parameter names
  const ASK_WEATHER_ACTION = 'askWeather';  // The action name from the API.AI intent
  const CITY_PARAMETER = 'geo-city'; // An parameter name

  // Create functions to handle intents here
  function getWeather(assistant) {
    console.log('Handling action: ' + ASK_WEATHER_ACTION);
    let city = assistant.getArgument(CITY_PARAMETER);
    // Make an API call to fetch the current weather in the requested city.
    // See
    let weatherRequestURL = "*%20from%20weather.forecast" +
        "%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22" +
        encodeURIComponent(city) +
github circuit / circuit-google-assistant / sessionHandler.js View on Github external
return function(req, res, next) {
    const sessionId = req.body.sessionId;
    const assistant = new ApiAiAssistant({request: req, response: res});
    const isDev = process.env.NODE_ENV === 'development';
    let circuit;

    if (!sessions[sessionId]) {
      // Create session and logon to Circuit while welcome intent is running
      const user = isDev ? {} : assistant.getUser();
      assert(user, `Running in production mode without OAuth linking enabled`);
      circuit = new CircuitClient(isDev ? : {client_id: config.oauth});
        .then(() => {
          sessions[sessionId] = {
            circuit: circuit,
            timer: setTimeout(clearSession.bind(null, sessionId), SESSION_TIMEOUT)
        .catch(err => log.error(`Unable to logon to Circuit`, err));
github googlearchive / assistant-codelab / project / functions / index.js View on Github external
exports.assistantcodelab = functions.https.onRequest((request, response) => {
    console.log('headers: ' + JSON.stringify(request.headers));
    console.log('body: ' + JSON.stringify(request.body));

    const assistant = new Assistant({request: request, response: response});

    let actionMap = new Map();
    actionMap.set(PLAY_INTENT, play);
    actionMap.set(NO_INTENT, discriminate);
    actionMap.set(YES_INTENT, discriminate);
    actionMap.set(GIVEUP_INTENT, giveUp);
    actionMap.set(LEARN_THING_INTENT, learnThing);
    actionMap.set(LEARN_DISCRIM_INTENT, learnDiscrimination);

    function play(assistant) {
        const first_ref = know.child('first');
        first_ref.once('value', snap => {
            const first = snap.val();
            console.log(`First: ${first}`);