Encapsulates all intent request and response objects.

Index

Type aliases

ExecuteErrors

ExecuteErrors: string

For a list of the supported EXECUTE error codes, see Errors and exceptions

ExecuteHandler

ExecuteHandler: IntentHandler<ExecuteRequest, ExecuteResponse>

Callback registered with the App via App.onExecute to process requests to update device state.

To support local execution, the local home platform must first establish a local execution path. For more details, see the developer guide.

const executeHandler = (request: IntentFlow.ExecuteRequest):
  Promise<IntentFlow.ExecuteResponse> => {

    // Extract command(s) and device target(s) from request
    const command = request.inputs[0].payload.commands[0];
    const execution = command.execution[0];

    const response = new Execute.Response.Builder()
      .setRequestId(request.requestId);

    const result = command.devices.map((device) => {
      // Construct a local device command
      const deviceCommand = new DataFlow.TcpRequestData();
      // ...

      // Send command to the local device
      return localHomeApp.getDeviceManager()
        .send(deviceCommand)
        .then((result) => {
          response.setSuccessState(result.deviceId, state);
        })
        .catch((err: IntentFlow.HandlerError) => {
          err.errorCode = err.errorCode || "invalid_request";
          response.setErrorState(device.id, err.errorCode);
        });
    });

    // Respond once all commands complete
    return Promise.all(result)
      .then(() => response.build());
  };

ExecuteRequest

ExecuteRequest: CloudRequest<ExecuteRequestPayload>

Request passed to the application's EXECUTE intent handler, containing a list of commands and target device IDs to be updated.

ExecuteResponse

ExecuteResponse: CloudResponse<ExecutePayload>

Container for the status of the commands that the local app received in an EXECUTE intent.

Use Response.Builder to create an ExecuteResponse instance and set the corresponding status for each target device ID present in the ExecuteRequest.

const response = new Execute.Response.Builder()
    .setRequestId(request.requestId);

const result = localHomeApp.getDeviceManager()
  .send(deviceCommand)
  .then((result) => {
    // Handle command success
    response.setSuccessState(device.id, state);
  })
  .catch((err: IntentFlow.HandlerError) => {
    // Handle command error
    response.setErrorState(device.id, err.errorCode);
  });

return result.then(() => response.build());

ExecuteStatus

ExecuteStatus: "SUCCESS" | "PENDING" | "OFFLINE" | "ERROR" | "EXCEPTIONS"

Response status codes for EXECUTE intent requests.

IdentifyHandler

IdentifyHandler: IntentHandler<IdentifyRequest, IdentifyResponse>

Callback registered with the App via App.onIdentify to process incoming device discovery requests.

To support local execution, the local home platform sends an IDENTIFY intent to discover what devices are present locally, then uses the SYNC intent to verify with the provider's cloud service that the device is available for local execution.

To learn more about how the platform establishes a local execution path, see the developer guide.

const identifyHandler = (request: IntentFlow.IdentifyRequest):
  IntentFlow.IdentifyResponse => {

    // Obtain scan data from protocol defined in your scan config
    const device = request.inputs[0].payload.device;
    const scanData = device.udpScanData;

    // Decode scan data to obtain metadata about local device
    const verificationId = "local-device-id";

    // Return a response
    const response: IntentFlow.IdentifyResponse = {
      intent: Intents.IDENTIFY,
      requestId: request.requestId,
      payload: {
        device: {
          id: device.id || "",
          verificationId, // Must match otherDeviceIds in SYNC response
        },
      },
    };
    return response;
  };

IdentifyRequest

IdentifyRequest: RequestInterface<LocalIdentifiedDevice>

Request passed to the application's IDENTIFY intent handler, containing a LocalIdentifiedDevice detected by the local scan configuration.

IdentifyResponse

IdentifyResponse: ResponseInterface<IdentifyResponsePayload>

Response returned by the application's IDENTIFY intent handler to describe the locally discovered device.

ReachableDevicesHandler

ReachableDevicesHandler: IntentHandler<ReachableDevicesRequest, ReachableDevicesResponse>

Callback registered with the App via App.onReachableDevices to discover additional devices connected to a proxy or hub.

When a device that is discovered by the IdentifyHandler is a proxy which enables indirect access to other devices (identified by the isProxy flag in the IdentifyResponse), the local home platform sends a REACHABLE_DEVICES intent to discover the additional devices visible to the proxy.

To learn more about how the platform verifies reachable devices, see the developer guide.

const devicesHandler = (request: IntentFlow.ReachableDevicesRequest):
  IntentFlow.ReachableDevicesResponse => {

    // Reference to the local proxy device
    const proxyDevice = request.inputs[0].payload.device.proxyDevice;

    // Query local proxy device for additional visible ids
    // ...
    const reachableDevices = [
      // Each verificationId must match one of the otherDeviceIds
      // in the SYNC response
      { verificationId: "local-device-id-1" },
      { verificationId: "local-device-id-2" },
    ];

    // Return a response
    const response: IntentFlow.ReachableDevicesResponse = {
      intent: Intents.REACHABLE_DEVICES,
      requestId: request.requestId,
      payload: {
        devices: reachableDevices,
      },
    };
    return response;
  };

ReachableDevicesRequest

ReachableDevicesRequest: RequestInterface<LocalIdentifiedDevice>

Request passed to the application's REACHABLE_DEVICES intent handler, containing a LocalIdentifiedDevice successfully identified as a proxy or hub.

ReachableDevicesResponse

ReachableDevicesResponse: ResponseInterface<ReachableDevicesPayload>

Response returned by the application's REACHABLE_DEVICES intent handler to describe additional devices visible to the proxy device.