Handle guest users

Try it in Dialogflow

Click Continue to deploy and test our Guest Users sample in Dialogflow. Just follow the steps below.

  1. Enter an agent name to create a new Dialogflow agent or select an existing agent to overwrite it with this sample.
  2. Click Create agent from template.
  3. After the agent is done importing, click Go to agent.
  4. Click Fulfillment in the left navigation menu.
  5. Enable the Inline Editor and click Deploy. The editor contains the code from this page.
  6. Click Integrations in the left navigation menu.
  7. Click Google Assistant and enable Auto-preview changes.
  8. Click Test to open the Actions simulator and enter "Talk to my test app" to test the sample!
Continue

To provide the best user experience, you might want to save state across multiple conversations with a user or access user data in one of the following ways:

  • userStorage is an opaque token that you can persist across multiple conversational sessions with a particular user.
  • Account Linking with the sign-in helper lets you link the user's Google account with your own account management backend. This gives you the most control in storing user information and preferences.

However, these features won't work unless Google can verify the user.

  • For user storage, storing data or retrieving data doesn't work if the status is GUEST.
  • For account linking, the sign-in helper won't work if the user verification status is GUEST.

This page explains how to determine whether a user is verified or a guest, and how to handle the conversation for guest users.

How we determine user verification status

At the start of each conversation, we set the user's verification status based on a variety of indicators when the conversation starts, such as:

  • The user has personal results turned off.
  • The user disabled their Web & App Activity. Keep in mind that some users may have this setting disabled at the domain level.
  • If a device has Voice Match enabled, and the match fails or the user invokes the Assistant without using their voice (such as a long press on a Google Home).
  • The user isn't signed in.

Handle user verification status

The user verification status returns a value of GUEST or VERIFIED. You should always check this status before storing data with user storage or starting an account linking flow, to prevent guest users from interacting with a feature that will fail for them.

The following code checks the user's verification status before asking them about storing their location, and pivots the conversation if they're a GUEST:

Dialogflow Node.js
app.intent('Save Preference', (conv, {color}) => {
  if (conv.user.verification === 'VERIFIED') {
    conv.user.storage.favoriteColor = color;
    conv.close(`Alright, I'll remember that you like ${color}. See you!`);
  } else {
    conv.close(`${color} is my favorite too! I can't save that right now ` +
      `but you can tell me again next time!`);
  }
});
Dialogflow Java
@ForIntent("Save Preference")
public ActionResponse save(ActionRequest request) {
  String color = (String) request.getParameter("color");
  ResponseBuilder responseBuilder = getResponseBuilder(request);
  String verificationStatus = request.getUser().getUserVerificationStatus();
  if (verificationStatus.equals("VERIFIED")) {
    responseBuilder.getUserStorage().put("favoriteColor", color);
    responseBuilder.add("Alright I'll remember that you like " + color + ". See you!");
  } else {
    responseBuilder.add(color + " is my favorite too! I can't " +
      "save that right now but you can tell me again next time!");
  }
  responseBuilder.endConversation();
  return responseBuilder.build();
}
Actions SDK Node.js
app.intent('actions.intent.TEXT', (conv, input) => {
  if (conv.user.verification === 'VERIFIED') {
    conv.user.storage.favoriteColor = input;
    conv.close(`Alright, I'll remember that you like ${input}. See you!`);
  } else {
    conv.close(`${input} is my favorite too! I can't save that right now ` +
      `but you can tell me again next time!`);
  }
});
Actions SDK Java
@ForIntent("actions.intent.TEXT")
public ActionResponse fallback(ActionRequest request) {
  String color = request.getRawInput().getQuery();
  ResponseBuilder responseBuilder = getResponseBuilder(request);
  String verificationStatus = request.getUser().getUserVerificationStatus();
  if (verificationStatus.equals("VERIFIED")) {
    responseBuilder.getUserStorage().put("favoriteColor", color);
    responseBuilder.add("Alright I'll remember that you like " + color + ". See you!");
  } else {
    responseBuilder.add(color + " is my favorite too! I can't " +
      "save that right now but you can tell me again next time!");
  }
  responseBuilder.endConversation();
  return responseBuilder.build();
}
Dialogflow JSON

Note that the JSON below describes a webhook request.

{
  "responseId": "41beca0a-86f0-43a4-8537-716062a2207d-712767ed",
  "queryResult": {
    "queryText": "blue",
    "parameters": {
      "color": "blue"
    },
    "allRequiredParamsPresent": true,
    "fulfillmentText": "Webhook failed for intent: Save Preference",
    "fulfillmentMessages": [
      {
        "text": {
          "text": [
            "Webhook failed for intent: Save Preference"
          ]
        }
      }
    ],
    "outputContexts": [
      {
        "name": "projects/df-guests-kohler/agent/sessions/ABwppHHKDYEEk-cSYty-G83y8F4kV0PPlfuxG_DyvI7F1PlcBibR7CbyifqQz_eh-INDy5PM6pR_k9yCEG_S2A/contexts/actions_capability_media_response_audio",
        "parameters": {
          "color": "blue",
          "color.original": "blue"
        }
      },
      {
        "name": "projects/df-guests-kohler/agent/sessions/ABwppHHKDYEEk-cSYty-G83y8F4kV0PPlfuxG_DyvI7F1PlcBibR7CbyifqQz_eh-INDy5PM6pR_k9yCEG_S2A/contexts/actions_capability_audio_output",
        "parameters": {
          "color": "blue",
          "color.original": "blue"
        }
      },
      {
        "name": "projects/df-guests-kohler/agent/sessions/ABwppHHKDYEEk-cSYty-G83y8F4kV0PPlfuxG_DyvI7F1PlcBibR7CbyifqQz_eh-INDy5PM6pR_k9yCEG_S2A/contexts/actions_capability_account_linking",
        "parameters": {
          "color": "blue",
          "color.original": "blue"
        }
      },
      {
        "name": "projects/df-guests-kohler/agent/sessions/ABwppHHKDYEEk-cSYty-G83y8F4kV0PPlfuxG_DyvI7F1PlcBibR7CbyifqQz_eh-INDy5PM6pR_k9yCEG_S2A/contexts/actions_capability_web_browser",
        "parameters": {
          "color": "blue",
          "color.original": "blue"
        }
      },
      {
        "name": "projects/df-guests-kohler/agent/sessions/ABwppHHKDYEEk-cSYty-G83y8F4kV0PPlfuxG_DyvI7F1PlcBibR7CbyifqQz_eh-INDy5PM6pR_k9yCEG_S2A/contexts/actions_capability_screen_output",
        "parameters": {
          "color": "blue",
          "color.original": "blue"
        }
      },
      {
        "name": "projects/df-guests-kohler/agent/sessions/ABwppHHKDYEEk-cSYty-G83y8F4kV0PPlfuxG_DyvI7F1PlcBibR7CbyifqQz_eh-INDy5PM6pR_k9yCEG_S2A/contexts/google_assistant_input_type_keyboard",
        "parameters": {
          "color": "blue",
          "color.original": "blue"
        }
      }
    ],
    "intent": {
      "name": "projects/df-guests-kohler/agent/intents/3486a76b-5a7e-4872-b392-32f1a80044ad",
      "displayName": "Save Preference"
    },
    "intentDetectionConfidence": 1,
    "languageCode": "en"
  },
  "originalDetectIntentRequest": {
    "source": "google",
    "version": "2",
    "payload": {
      "user": {
        "locale": "en-US",
        "userVerificationStatus": "VERIFIED"
      },
      "conversation": {
        "conversationId": "ABwppHHKDYEEk-cSYty-G83y8F4kV0PPlfuxG_DyvI7F1PlcBibR7CbyifqQz_eh-INDy5PM6pR_k9yCEG_S2A",
        "type": "ACTIVE",
        "conversationToken": "[]"
      },
      "inputs": [
        {
          "intent": "actions.intent.TEXT",
          "rawInputs": [
            {
              "inputType": "KEYBOARD",
              "query": "blue"
            }
          ],
          "arguments": [
            {
              "name": "text",
              "rawText": "blue",
              "textValue": "blue"
            }
          ]
        }
      ],
      "surface": {
        "capabilities": [
          {
            "name": "actions.capability.MEDIA_RESPONSE_AUDIO"
          },
          {
            "name": "actions.capability.AUDIO_OUTPUT"
          },
          {
            "name": "actions.capability.ACCOUNT_LINKING"
          },
          {
            "name": "actions.capability.WEB_BROWSER"
          },
          {
            "name": "actions.capability.SCREEN_OUTPUT"
          }
        ]
      },
      "availableSurfaces": [
        {
          "capabilities": [
            {
              "name": "actions.capability.AUDIO_OUTPUT"
            },
            {
              "name": "actions.capability.SCREEN_OUTPUT"
            },
            {
              "name": "actions.capability.WEB_BROWSER"
            }
          ]
        }
      ]
    }
  },
  "session": "projects/df-guests-kohler/agent/sessions/ABwppHHKDYEEk-cSYty-G83y8F4kV0PPlfuxG_DyvI7F1PlcBibR7CbyifqQz_eh-INDy5PM6pR_k9yCEG_S2A"
}
Actions SDK JSON

Note that the JSON below describes a webhook request.

{
  "user": {
    "locale": "en-US",
    "userVerificationStatus": "VERIFIED"
  },
  "conversation": {
    "conversationId": "ABwppHGVu4a9e8dl0SpY-mE-XVPzhH7ZgaHp6g_EHOVSNOhEWfGRlHptwncig7mWupvH98QaqQ_PytIdYDb4ieNb",
    "type": "NEW"
  },
  "inputs": [
    {
      "intent": "actions.intent.TEXT",
      "rawInputs": [
        {
          "inputType": "KEYBOARD",
          "query": "blue"
        }
      ],
      "arguments": [
        {
          "name": "text",
          "rawText": "blue",
          "textValue": "blue"
        }
      ]
    }
  ],
  "surface": {
    "capabilities": [
      {
        "name": "actions.capability.MEDIA_RESPONSE_AUDIO"
      },
      {
        "name": "actions.capability.SCREEN_OUTPUT"
      },
      {
        "name": "actions.capability.WEB_BROWSER"
      },
      {
        "name": "actions.capability.ACCOUNT_LINKING"
      },
      {
        "name": "actions.capability.AUDIO_OUTPUT"
      }
    ]
  },
  "availableSurfaces": [
    {
      "capabilities": [
        {
          "name": "actions.capability.AUDIO_OUTPUT"
        },
        {
          "name": "actions.capability.SCREEN_OUTPUT"
        },
        {
          "name": "actions.capability.WEB_BROWSER"
        }
      ]
    }
  ]
}