{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "oneOf": [
    {
      "type": "object",
      "properties": {
        "version": {
          "type": "number",
          "const": 1
        },
        "type": {
          "type": "string",
          "const": "note.created"
        },
        "timestamp": {
          "type": "string",
          "format": "date-time",
          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$",
          "description": "When Relay stored what this message holds."
        },
        "data": {
          "type": "object",
          "properties": {
            "note": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "description": "The note's id: a UUID, the same in every message about this note."
                },
                "source": {
                  "type": "string",
                  "enum": [
                    "ring",
                    "typed"
                  ]
                },
                "text": {
                  "type": "string",
                  "description": "The words: a typed note, or a ring note's transcription."
                },
                "recorded_at": {
                  "type": "string",
                  "format": "date-time",
                  "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$",
                  "description": "A time in ISO 8601, UTC."
                },
                "created_at": {
                  "type": "string",
                  "format": "date-time",
                  "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$",
                  "description": "When Relay stored it."
                },
                "device": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "The device key's id in Relay."
                    },
                    "name": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "id",
                    "name"
                  ],
                  "additionalProperties": false,
                  "description": "The phone or Pebble app that sent the item."
                },
                "place": {
                  "anyOf": [
                    {
                      "type": "object",
                      "properties": {
                        "lat": {
                          "type": "number"
                        },
                        "lon": {
                          "type": "number"
                        },
                        "accuracy": {
                          "anyOf": [
                            {
                              "type": "number"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "In meters."
                        },
                        "name": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "The place's name from the phone's address lookup, such as a street."
                        },
                        "from": {
                          "type": "string",
                          "enum": [
                            "phone",
                            "history"
                          ],
                          "description": "phone: where a typed note was written. history: the location point nearest a ring note."
                        }
                      },
                      "required": [
                        "lat",
                        "lon",
                        "accuracy",
                        "name",
                        "from"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "audio": {
                  "anyOf": [
                    {
                      "type": "object",
                      "properties": {
                        "content_type": {
                          "type": "string",
                          "const": "audio/mp4"
                        },
                        "base64": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "content_type",
                        "base64"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "null"
                    }
                  ],
                  "description": "A ring note's recording, or null for a typed note or a ring note with words only."
                }
              },
              "required": [
                "id",
                "source",
                "text",
                "recorded_at",
                "created_at",
                "device",
                "place",
                "audio"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "note"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "version",
        "type",
        "timestamp",
        "data"
      ],
      "additionalProperties": false,
      "description": "A note reached Relay."
    },
    {
      "type": "object",
      "properties": {
        "version": {
          "type": "number",
          "const": 1
        },
        "type": {
          "type": "string",
          "const": "note.updated"
        },
        "timestamp": {
          "type": "string",
          "format": "date-time",
          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$",
          "description": "When Relay stored what this message holds."
        },
        "data": {
          "type": "object",
          "properties": {
            "note": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "description": "The note's id: a UUID, the same in every message about this note."
                },
                "source": {
                  "type": "string",
                  "enum": [
                    "ring",
                    "typed"
                  ]
                },
                "text": {
                  "type": "string",
                  "description": "The words: a typed note, or a ring note's transcription."
                },
                "recorded_at": {
                  "type": "string",
                  "format": "date-time",
                  "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$",
                  "description": "A time in ISO 8601, UTC."
                },
                "created_at": {
                  "type": "string",
                  "format": "date-time",
                  "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$",
                  "description": "When Relay stored it."
                },
                "device": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "The device key's id in Relay."
                    },
                    "name": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "id",
                    "name"
                  ],
                  "additionalProperties": false,
                  "description": "The phone or Pebble app that sent the item."
                },
                "place": {
                  "anyOf": [
                    {
                      "type": "object",
                      "properties": {
                        "lat": {
                          "type": "number"
                        },
                        "lon": {
                          "type": "number"
                        },
                        "accuracy": {
                          "anyOf": [
                            {
                              "type": "number"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "In meters."
                        },
                        "name": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "The place's name from the phone's address lookup, such as a street."
                        },
                        "from": {
                          "type": "string",
                          "enum": [
                            "phone",
                            "history"
                          ],
                          "description": "phone: where a typed note was written. history: the location point nearest a ring note."
                        }
                      },
                      "required": [
                        "lat",
                        "lon",
                        "accuracy",
                        "name",
                        "from"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              },
              "required": [
                "id",
                "source",
                "text",
                "recorded_at",
                "created_at",
                "device",
                "place"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "note"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "version",
        "type",
        "timestamp",
        "data"
      ],
      "additionalProperties": false,
      "description": "A ring note got its place from a later location batch. It has no audio."
    },
    {
      "type": "object",
      "properties": {
        "version": {
          "type": "number",
          "const": 1
        },
        "type": {
          "type": "string",
          "const": "health.samples"
        },
        "timestamp": {
          "type": "string",
          "format": "date-time",
          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$",
          "description": "When Relay stored what this message holds."
        },
        "data": {
          "type": "object",
          "properties": {
            "samples": {
              "minItems": 1,
              "maxItems": 500,
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "integer",
                    "minimum": -9007199254740991,
                    "maximum": 9007199254740991,
                    "description": "Unique in this Relay."
                  },
                  "device": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "description": "The device key's id in Relay."
                      },
                      "name": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "id",
                      "name"
                    ],
                    "additionalProperties": false,
                    "description": "The phone or Pebble app that sent the item."
                  },
                  "type": {
                    "type": "string",
                    "enum": [
                      "steps",
                      "heart_rate",
                      "sleep",
                      "workout"
                    ]
                  },
                  "start": {
                    "type": "string",
                    "format": "date-time",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$",
                    "description": "A time in ISO 8601, UTC."
                  },
                  "end": {
                    "type": "string",
                    "format": "date-time",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$",
                    "description": "A time in ISO 8601, UTC."
                  },
                  "value": {
                    "type": "number"
                  },
                  "unit": {
                    "type": "string"
                  },
                  "source": {
                    "type": "string",
                    "description": "The app or watch that counted it."
                  }
                },
                "required": [
                  "id",
                  "device",
                  "type",
                  "start",
                  "end",
                  "value",
                  "unit",
                  "source"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "samples"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "version",
        "type",
        "timestamp",
        "data"
      ],
      "additionalProperties": false,
      "description": "Health samples, in the order Relay stored them."
    },
    {
      "type": "object",
      "properties": {
        "version": {
          "type": "number",
          "const": 1
        },
        "type": {
          "type": "string",
          "const": "location.points"
        },
        "timestamp": {
          "type": "string",
          "format": "date-time",
          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$",
          "description": "When Relay stored what this message holds."
        },
        "data": {
          "type": "object",
          "properties": {
            "points": {
              "minItems": 1,
              "maxItems": 500,
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "integer",
                    "minimum": -9007199254740991,
                    "maximum": 9007199254740991,
                    "description": "Unique in this Relay."
                  },
                  "device": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "description": "The device key's id in Relay."
                      },
                      "name": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "id",
                      "name"
                    ],
                    "additionalProperties": false,
                    "description": "The phone or Pebble app that sent the item."
                  },
                  "at": {
                    "type": "string",
                    "format": "date-time",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$",
                    "description": "A time in ISO 8601, UTC."
                  },
                  "lat": {
                    "type": "number"
                  },
                  "lon": {
                    "type": "number"
                  },
                  "accuracy": {
                    "type": "number",
                    "description": "In meters."
                  },
                  "place": {
                    "anyOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                },
                "required": [
                  "id",
                  "device",
                  "at",
                  "lat",
                  "lon",
                  "accuracy",
                  "place"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "points"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "version",
        "type",
        "timestamp",
        "data"
      ],
      "additionalProperties": false,
      "description": "Location points, in the order Relay stored them."
    },
    {
      "type": "object",
      "properties": {
        "version": {
          "type": "number",
          "const": 1
        },
        "type": {
          "type": "string",
          "const": "webhook.test"
        },
        "timestamp": {
          "type": "string",
          "format": "date-time",
          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$",
          "description": "When Relay stored what this message holds."
        },
        "data": {
          "type": "object",
          "properties": {
            "webhook": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                }
              },
              "required": [
                "id",
                "name"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "webhook"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "version",
        "type",
        "timestamp",
        "data"
      ],
      "additionalProperties": false,
      "description": "Send a test, from the Relay page."
    }
  ],
  "title": "Relay webhook message, version 1",
  "description": "The JSON body of each message a Relay webhook sends."
}
