Search code examples
node.jsactions-on-google

Actions on Google check for available mobile phone


I am currently creating a multi surface action using the actions on google SDK. In this action my users need to enter a code, if they fail to enter the code 3 times I want to check if the user has a mobile phone available so that they can enter the code via the phones keyboard.

I already tried playing around with the surface capabilities, but I noticed that there isn't a check for a specific device category. Instead the check is done based on capabilities.

What I would like to achieve is, if a user fails to enter the code by voice, if they are on a device without a keyboard ( Google Home or Google Nest Hub ) and they have a mobile phone available, they should be prompted to move the conversation to their mobile device.

I currently use the following code to determine if the user has a mobile and isn't on a mobile device already:

    const hasOtherDeviceWithScreen = conv.available.surfaces.capabilities.has("actions.capability.SCREEN_OUTPUT");
    const hasOtherDeviceWithBrowser = conv.available.surfaces.capabilities.has("actions.capability.WEB_BROWSER");

    const hasAvailableMobileDevice = (hasOtherDeviceWithScreen === true && hasOtherDeviceWithBrowser === true);
    const currentDeviceHasScreen = conv.screen;
    const currentDeviceHasBrowser = conv.surface.capabilities.has("actions.capability.WEB_BROWSER");

    const handOverAvailable = (hasAvailableMobileDevice === true && currentDeviceHasBrowser === false);

I know that handovers can only be done with IOS & Android phones, so a check for screen + internet should detect a phone, but I am not sure how this works if more than 1 other device is available.

Does checking for a screen device and browser device guarantee that the user has a single device with these capabilities or is it possible that it returns true when the users has multiple devices?


Solution

  • The conv.surface.capabilities is an array of all the capabilities for a particular device, while conv.available.surfaces.capabilities is an array of all the capabilities that the user across all of their devices.

    When you are transitioning from something like a smart speaker to something like a phone, you would get a notification on every valid surface. Basically, your phone.

    Checking for a web browser & screen should in general match with a mobile device, although the capability framework was designed specifically so that you wouldn't need to have direct device type checks.