アクセスいただきありがとうございます。こちらのページは現在英語のみのご用意となっております。順次日本語化を進めてまいりますので、ご理解のほどよろしくお願いいたします。

Alexa.Health.Sleep Interface

The Alexa.Health.Sleep interface describes messages that you can use to develop Alexa skills for your sleep tracking apps and devices. You can develop your skill as a stand-alone skill, or you can integrate it with a device, such as a wearable wrist device. Your customers can track sleep for themselves, their children, and other family members. For an overview of the Alexa.Health interface, see Understand the Baby Activity Skill API.

Utterances

When you use the Alexa.Health.Sleep interface, the voice interaction model is already built for you. The following examples show some customer utterances:

Alexa, record sleep for thirty minutes.
Alexa, record sleep for my baby from three pm to five-thirty pm today.
Alexa, when did my baby start sleeping?
Alexa, how many hours has Jane slept for today?

After the customer says one of these utterances, Alexa sends a corresponding directive to your skill. You identify which directives you support, and for which customers, in the user profile report. You handle the directive and send a response event back to Alexa.

Before you submit your skill for certification, verify that you correctly handle the utterances in the testing guide.

User profile report

When a customer enables your Alexa skill, post a profile report message to Alexa. Your customers create their profiles in your app, and you create an identifier to track them in your app. Send the same identifier to Alexa as profileId in the profile report. If a customer adds, updates, or deletes a profile in your app, post a new profile report message to Alexa.

Identify the directives that your skill supports for each profile as supportedOperations in the profile report. The Get directive is always required. Requirements for other directives are specified in the Directives section.

You can send multiple profiles and multiple capabilities in the profile report. For more information, see User Profiles.

User profile report example

{
  "report": {
    "messageId": "<message id>",
    "profiles": [
      {
        "profileId": "<profile id>",
        "name": {
          "firstName": "Baby",
          "lastName": "Doe",
          "nickNames": ["Baby", "Junior"]
        },
        "capabilities": [
          {
            "name": "Alexa.Health.Sleep",
            "type": "AlexaInterface",
            "version": "1",
            "supportedOperations": ["Add", "Get"]
          }
        ]
      }
    ]
  }
}

The sleepMeasurement object

The Alexa.Health.Sleep interface uses the sleepMeasurement object as the primary data object.

Sleep measurement details

Field Description Type Required
startTime The time that sleep started, specified in UTC. A string in ISO 8601 format, YYYY-MM-DDThh:mm:ssZ. Yes
endTime The time that sleep ended, specified in UTC. A string in ISO 8601 format, YYYY-MM-DDThh:mm:ssZ. Yes
sleep The duration of the sleep session. Duration might not equal the difference between the end time and the start time, for example if the sleep was paused interrupted. A sleep object that contains a duration string. Yes

Sleep measurement example

{
  "sleepMeasurement": {
    "startTime": "2018-03-14T22:30Z",
    "endTime": "2018-03-15T06:30Z",
    "sleep": {
      "duration": "PT8H"
    }
  }
}

Directives

Add directive

Support the Add directive so that customers can log a sleep session. The Add directive is optional if voice interaction is not required. For example, a wearable device that tracks sleep based on movement can record sleep without voice interaction.

The following example shows a customer utterance:

Alexa, record sleep at ten am.

Add directive payload details

Field Description Type Required
sleepMeasurement The sleep measurement to add. A sleepMeasurement object. Yes

Add directive example

{
  "directive": {
    "header": {
      "namespace": "Alexa.Health.Sleep",
      "name": "Add",
      "messageId": "<message id>",
      "payloadVersion": "1"
    },
    "profile": {
      "scope": {
        "token": "<an OAuth2 bearer token>"
      },
      "profileId": "<the identifier for the profile to associate with the sleep session>"
    },
    "payload": {
      "sleepMeasurement": {
        "startTime": "2018-03-14T22:30Z",
        "endTime": "2018-03-15T06:30Z",
        "sleep": {
          "duration": "PT8H"
        }
      }
    }
  }
}

Add response event

If you handle an Add directive successfully, respond with an AddResponse event.

AddResponse event payload details

Field Description Type Required
entryId Your identifier for the record that you added. String Yes

AddResponse event example

{
  "event": {
    "header": {
      "namespace": "Alexa.Health.Sleep",
      "name": "AddResponse",
      "messageId": "<message id>",
      "payloadVersion": "1",
    },
    "payload": {
      "entryId": "<entry id>"
    }
  }
}

Add directive error handling

If you can't handle an Add directive successfully, respond with an Alexa.Health.ErrorResponse event.

Get directive

Support the Get directive so that customers can retrieve one or more sleep measurements. The Get directive is required.

The following examples show customer utterances:

Alexa, how long did my baby sleep yesterday?
Alexa, how many hours has Jane slept for today?

Get directive payload details

Field Description Type Required
maxResults The maximum number of results to return in the current page of results. Results beyond this number are paginated. Specify a number greater than zero. Integer Yes
nextToken A token to retrieve additional results if the results are paginated and there are more results. String No
filterParameters An array of filter parameter objects that filters the results of the query. Use "startTime" for the fieldName in your filter parameters when you retrieve sleep measurements. Array No
sortParameters An array of sort parameter objects that sorts the results of the query. Array No

Get directive example

{
  "directive": {
    "header": {
      "namespace": "Alexa.Health.Sleep",
      "name": "Get",
      "messageId": "<message id>",
      "payloadVersion": "1"
    },
    "profile": {
      "scope": {
        "token": "<an OAuth2 bearer token>"
      },
      "profileId": "<the identifier for the profile associated with the sleep measurements>"
    },
    "payload": {
      "queryParameters": {
        "maxResults": "3",
        "nextToken": "<token indicating starting offset for next paginated result>",
        "filterParameters": [
          {
            "fieldName": "startTime",
            "comparisonOperator": "GTE",
            "value": "2018-05-30T00:00:00Z"
          }
        ],
        "sortParameters": [
          {
            "fieldName": "startTime",
            "order": "ASC"
          }
        ]
      }
    }
  }
}

Get response event

If you handle a Get directive successfully, respond with a GetResponse event.

GetResponse event payload details

Field Description Type Required
nextToken A token to retrieve additional results if the results are paginated and there are more results. String No
sleepMeasurements The results of the query. An array of sleepMeasurement objects. Yes

GetResponse event example

{
  "event": {
    "header": {
      "namespace": "Alexa.Health.Sleep",
      "name": "GetResponse",
      "messageId": "<message id>",
      "payloadVersion": "1"
    },
    "payload":{
      "nextToken": "4",
      "sleepMeasurements": [
        {
          "startTime": "2018-05-30T22:00Z",
          "endTime": "2018-05-31T06:00Z",
          "sleep": {
            "duration": "PT8H"
          }
        },
        {
          "startTime": "2018-05-31T14:00Z",
          "endTime": "2018-05-31T14:30Z",
          "sleep": {
            "duration": "PT30M"
          }
      },
        {
          "startTime": "2018-05-31T22:30Z",
          "endTime": "2018-06-01T06:30Z",
          "sleep": {
            "duration": "PT8H"
          }
        }
      ]
    }
  }
}

Get directive error handling

If you can't handle a Get directive successfully, respond with an Alexa.Health.ErrorResponse event. Use the INVALID_NEXT_TOKEN error type if the nextToken is inconsistent with the filter and sort parameters. For more information, see Paginating Results.

Interface Description
Alexa.Health.Weight Describes messages for tracking weight measurements.
Alexa.Health.InfantFeeding Describes messages for tracking and timing infant feeding.
Alexa.Health.DiaperChange Describes messages for tracking diaper changes.