{
  "$id": "https://hatang.dev/schema/chat-protocol/v1/http.json",
  "title": "Ha Tang chat protocol v1: HTTP shapes",
  "bootstrap": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "visitor_token": {
        "type": "string"
      },
      "visitor": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64
          },
          "site_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64
          },
          "channel": {
            "type": "string"
          },
          "email": {
            "type": [
              "string",
              "null"
            ]
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "phone": {
            "type": [
              "string",
              "null"
            ]
          },
          "avatar_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "external_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "custom_data": {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {}
          },
          "locale": {
            "anyOf": [
              {
                "type": "string",
                "enum": [
                  "vi",
                  "en"
                ]
              },
              {
                "type": "null"
              }
            ]
          },
          "browser": {
            "type": [
              "string",
              "null"
            ]
          },
          "os": {
            "type": [
              "string",
              "null"
            ]
          },
          "device": {
            "type": [
              "string",
              "null"
            ]
          },
          "country": {
            "type": [
              "string",
              "null"
            ]
          },
          "city": {
            "type": [
              "string",
              "null"
            ]
          },
          "current_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "current_title": {
            "type": [
              "string",
              "null"
            ]
          },
          "referrer": {
            "type": [
              "string",
              "null"
            ]
          },
          "first_seen_at": {
            "type": "string"
          },
          "last_seen_at": {
            "type": "string"
          },
          "identified_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "utm": {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {
              "type": "string"
            }
          },
          "visits": {
            "type": "integer",
            "minimum": -9007199254740991,
            "maximum": 9007199254740991
          },
          "customer_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "client": {
            "type": "string",
            "enum": [
              "web",
              "app"
            ]
          },
          "app": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64
                  },
                  "platform": {
                    "type": "string"
                  },
                  "version": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "sdk": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "required": [
                  "id",
                  "platform",
                  "version",
                  "sdk"
                ],
                "additionalProperties": {}
              },
              {
                "type": "null"
              }
            ]
          },
          "current_screen": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "site_id",
          "channel",
          "email",
          "name",
          "phone",
          "avatar_url",
          "external_id",
          "custom_data",
          "locale",
          "browser",
          "os",
          "device",
          "country",
          "city",
          "current_url",
          "current_title",
          "referrer",
          "first_seen_at",
          "last_seen_at",
          "identified_at",
          "utm",
          "visits",
          "customer_id",
          "client"
        ],
        "additionalProperties": {}
      },
      "config": {
        "type": "object",
        "properties": {
          "site_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64
          },
          "name": {
            "type": "string"
          },
          "color": {
            "type": "string"
          },
          "position": {
            "type": "string",
            "enum": [
              "right",
              "left"
            ]
          },
          "locale_default": {
            "type": "string",
            "enum": [
              "vi",
              "en",
              "auto"
            ]
          },
          "greeting": {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {
              "type": "string"
            }
          },
          "away_message": {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {
              "type": "string"
            }
          },
          "offline_capture": {
            "type": "string",
            "enum": [
              "email_required",
              "email_optional",
              "off"
            ]
          },
          "hide_when_offline": {
            "type": "boolean"
          },
          "theme": {
            "type": "string",
            "enum": [
              "light",
              "dark",
              "auto"
            ]
          },
          "bot_enabled": {
            "type": "boolean"
          },
          "agent_avatars": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "avatar_url": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "name",
                "avatar_url"
              ],
              "additionalProperties": {}
            }
          },
          "launcher": {
            "type": "object",
            "properties": {
              "icon": {
                "type": "string"
              },
              "image_url": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "label": {
                "type": "object",
                "propertyNames": {
                  "type": "string"
                },
                "additionalProperties": {
                  "type": "string"
                }
              }
            },
            "required": [
              "icon",
              "image_url",
              "label"
            ],
            "additionalProperties": {}
          },
          "header": {
            "type": "object",
            "properties": {
              "subtitle": {
                "type": "object",
                "propertyNames": {
                  "type": "string"
                },
                "additionalProperties": {
                  "type": "string"
                }
              },
              "logo_url": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "profile": {
                "type": "string",
                "enum": [
                  "agents",
                  "business"
                ]
              }
            },
            "required": [
              "subtitle",
              "logo_url",
              "profile"
            ],
            "additionalProperties": {}
          },
          "greeting_options": {
            "type": "object",
            "properties": {
              "enabled": {
                "type": "boolean"
              },
              "on_mobile": {
                "type": "boolean"
              },
              "sender": {
                "type": "string",
                "enum": [
                  "none",
                  "online_agent"
                ]
              },
              "teaser_seconds": {
                "type": "integer",
                "minimum": -9007199254740991,
                "maximum": 9007199254740991
              }
            },
            "required": [
              "enabled",
              "on_mobile",
              "sender",
              "teaser_seconds"
            ],
            "additionalProperties": {}
          },
          "contact_buttons": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "enum": [
                    "zalo",
                    "messenger",
                    "phone",
                    "email"
                  ]
                },
                "url": {
                  "type": "string"
                },
                "label": {
                  "type": "string"
                }
              },
              "required": [
                "kind",
                "url",
                "label"
              ],
              "additionalProperties": {}
            }
          },
          "layout": {
            "type": "object",
            "properties": {
              "size": {
                "type": "string",
                "enum": [
                  "s",
                  "m",
                  "l"
                ]
              },
              "offset": {
                "anyOf": [
                  {
                    "type": "object",
                    "properties": {
                      "bottom": {
                        "type": "integer",
                        "minimum": -9007199254740991,
                        "maximum": 9007199254740991
                      },
                      "side": {
                        "type": "integer",
                        "minimum": -9007199254740991,
                        "maximum": 9007199254740991
                      }
                    },
                    "required": [
                      "bottom",
                      "side"
                    ],
                    "additionalProperties": {}
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "mobile_offset": {
                "anyOf": [
                  {
                    "type": "object",
                    "properties": {
                      "bottom": {
                        "type": "integer",
                        "minimum": -9007199254740991,
                        "maximum": 9007199254740991
                      },
                      "side": {
                        "type": "integer",
                        "minimum": -9007199254740991,
                        "maximum": 9007199254740991
                      }
                    },
                    "required": [
                      "bottom",
                      "side"
                    ],
                    "additionalProperties": {}
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            },
            "required": [
              "size",
              "offset",
              "mobile_offset"
            ],
            "additionalProperties": {}
          },
          "prechat": {
            "type": "object",
            "properties": {
              "enabled": {
                "type": "boolean"
              },
              "fields": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "enum": [
                      "off",
                      "optional",
                      "required"
                    ]
                  },
                  "phone": {
                    "type": "string",
                    "enum": [
                      "off",
                      "optional",
                      "required"
                    ]
                  },
                  "email": {
                    "type": "string",
                    "enum": [
                      "off",
                      "optional",
                      "required"
                    ]
                  }
                },
                "required": [
                  "name",
                  "phone",
                  "email"
                ],
                "additionalProperties": {}
              }
            },
            "required": [
              "enabled",
              "fields"
            ],
            "additionalProperties": {}
          },
          "visibility": {
            "type": "object",
            "properties": {
              "devices": {
                "type": "string",
                "enum": [
                  "all",
                  "desktop",
                  "mobile"
                ]
              },
              "url_include": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "url_exclude": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "devices",
              "url_include",
              "url_exclude"
            ],
            "additionalProperties": {}
          },
          "notifications": {
            "type": "object",
            "properties": {
              "sound": {
                "type": "boolean"
              },
              "title_alert": {
                "type": "boolean"
              }
            },
            "required": [
              "sound",
              "title_alert"
            ],
            "additionalProperties": {}
          },
          "allow_in_iframe": {
            "type": "boolean"
          }
        },
        "required": [
          "site_id",
          "name",
          "color",
          "position",
          "locale_default",
          "greeting",
          "away_message",
          "offline_capture",
          "hide_when_offline",
          "theme",
          "bot_enabled",
          "agent_avatars"
        ],
        "additionalProperties": {}
      },
      "availability": {
        "type": "object",
        "properties": {
          "online": {
            "type": "boolean"
          },
          "within_hours": {
            "type": "boolean"
          },
          "next_open_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "agents_online": {
            "type": "integer",
            "minimum": -9007199254740991,
            "maximum": 9007199254740991
          }
        },
        "required": [
          "online",
          "within_hours",
          "next_open_at",
          "agents_online"
        ],
        "additionalProperties": {}
      },
      "conversation": {
        "anyOf": [
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1,
                "maxLength": 64
              },
              "site_id": {
                "type": "string",
                "minLength": 1,
                "maxLength": 64
              },
              "visitor_id": {
                "type": "string",
                "minLength": 1,
                "maxLength": 64
              },
              "channel": {
                "type": "string"
              },
              "channel_account_id": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "status": {
                "type": "string",
                "enum": [
                  "open",
                  "pending",
                  "resolved",
                  "closed"
                ]
              },
              "assignee_kind": {
                "anyOf": [
                  {
                    "type": "string",
                    "enum": [
                      "user",
                      "bot"
                    ]
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "assignee_id": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "seq": {
                "type": "integer",
                "minimum": -9007199254740991,
                "maximum": 9007199254740991
              },
              "visitor_unread": {
                "type": "integer",
                "minimum": -9007199254740991,
                "maximum": 9007199254740991
              },
              "agent_unread": {
                "type": "integer",
                "minimum": -9007199254740991,
                "maximum": 9007199254740991
              },
              "last_message_at": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "last_message_preview": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "last_message_sender_type": {
                "anyOf": [
                  {
                    "type": "string",
                    "enum": [
                      "visitor",
                      "agent",
                      "bot",
                      "system"
                    ]
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "last_visitor_message_at": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "first_response_at": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "resolved_at": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "tags": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "member_ids": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "flag": {
                "anyOf": [
                  {
                    "type": "string",
                    "enum": [
                      "hidden",
                      "spam"
                    ]
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "snoozed_until": {
                "type": "string"
              },
              "muted_by": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "subject": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "created_at": {
                "type": "string"
              },
              "updated_at": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "site_id",
              "visitor_id",
              "channel",
              "status",
              "assignee_kind",
              "assignee_id",
              "seq",
              "visitor_unread",
              "agent_unread",
              "last_message_at",
              "last_message_preview",
              "last_message_sender_type",
              "first_response_at",
              "resolved_at",
              "tags",
              "member_ids",
              "flag",
              "subject",
              "created_at",
              "updated_at"
            ],
            "additionalProperties": {}
          },
          {
            "type": "null"
          }
        ]
      },
      "timeline": {
        "type": "array",
        "items": {
          "oneOf": [
            {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 64
                },
                "conversation_id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 64
                },
                "seq": {
                  "type": "integer",
                  "minimum": -9007199254740991,
                  "maximum": 9007199254740991
                },
                "sender_type": {
                  "type": "string",
                  "enum": [
                    "visitor",
                    "agent",
                    "bot",
                    "system"
                  ]
                },
                "sender_id": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "sender_name": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "visibility": {
                  "type": "string",
                  "enum": [
                    "public",
                    "private"
                  ]
                },
                "content_type": {
                  "type": "string",
                  "enum": [
                    "text",
                    "file"
                  ]
                },
                "content": {
                  "type": "string"
                },
                "attachments": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 64
                      },
                      "name": {
                        "type": "string"
                      },
                      "size": {
                        "type": "integer",
                        "minimum": -9007199254740991,
                        "maximum": 9007199254740991
                      },
                      "type": {
                        "type": "string"
                      },
                      "url": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "id",
                      "name",
                      "size",
                      "type"
                    ],
                    "additionalProperties": {}
                  }
                },
                "client_id": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "metadata": {
                  "type": "object",
                  "propertyNames": {
                    "type": "string"
                  },
                  "additionalProperties": {}
                },
                "delivery_status": {
                  "anyOf": [
                    {
                      "type": "string",
                      "enum": [
                        "pending",
                        "sent",
                        "failed"
                      ]
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "delivery_error": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "read_at": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "created_at": {
                  "type": "string"
                },
                "kind": {
                  "type": "string",
                  "const": "message"
                }
              },
              "required": [
                "id",
                "conversation_id",
                "seq",
                "sender_type",
                "sender_id",
                "visibility",
                "content_type",
                "content",
                "attachments",
                "created_at",
                "kind"
              ],
              "additionalProperties": {}
            },
            {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 64
                },
                "conversation_id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 64
                },
                "seq": {
                  "type": "integer",
                  "minimum": -9007199254740991,
                  "maximum": 9007199254740991
                },
                "type": {
                  "type": "string"
                },
                "actor_type": {
                  "type": "string",
                  "enum": [
                    "visitor",
                    "agent",
                    "bot",
                    "system"
                  ]
                },
                "actor_id": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "data": {
                  "type": "object",
                  "propertyNames": {
                    "type": "string"
                  },
                  "additionalProperties": {}
                },
                "created_at": {
                  "type": "string"
                },
                "kind": {
                  "type": "string",
                  "const": "event"
                }
              },
              "required": [
                "id",
                "conversation_id",
                "seq",
                "type",
                "actor_type",
                "actor_id",
                "data",
                "created_at",
                "kind"
              ],
              "additionalProperties": {}
            }
          ]
        }
      },
      "timeline_has_more": {
        "type": "boolean"
      },
      "bundle": {
        "type": "string"
      },
      "ws_url": {
        "type": "string"
      },
      "protocol_version": {
        "type": "integer",
        "minimum": -9007199254740991,
        "maximum": 9007199254740991
      },
      "app": {
        "anyOf": [
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1,
                "maxLength": 64
              },
              "platform": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "platform"
            ],
            "additionalProperties": {}
          },
          {
            "type": "null"
          }
        ]
      }
    },
    "required": [
      "visitor_token",
      "visitor",
      "config",
      "availability",
      "conversation",
      "timeline",
      "bundle",
      "ws_url",
      "protocol_version",
      "app"
    ],
    "additionalProperties": {}
  },
  "message_card": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "oneOf": [
      {
        "type": "object",
        "properties": {
          "kind": {
            "type": "string",
            "const": "product"
          },
          "products": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "price": {
                  "type": "number"
                },
                "compare_at_price": {
                  "type": [
                    "number",
                    "null"
                  ]
                },
                "currency": {
                  "type": "string"
                },
                "image_url": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "url": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "sku": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "store_product_ids": {
                  "anyOf": [
                    {
                      "type": "object",
                      "properties": {
                        "app_store": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "google_play": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      },
                      "additionalProperties": {}
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "base_plan_id": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "offer_id": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "billing_period": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "trial_days": {
                  "anyOf": [
                    {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              },
              "required": [
                "id",
                "name",
                "price",
                "currency"
              ],
              "additionalProperties": {}
            }
          },
          "intro": {
            "type": "string"
          }
        },
        "required": [
          "kind",
          "products"
        ],
        "additionalProperties": {}
      },
      {
        "type": "object",
        "properties": {
          "kind": {
            "type": "string",
            "const": "order"
          },
          "order": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "code": {
                "type": "string"
              },
              "status": {
                "type": "string"
              },
              "items": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "quantity": {
                      "type": "number"
                    },
                    "price": {
                      "type": "number"
                    },
                    "variant": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "name",
                    "quantity",
                    "price"
                  ],
                  "additionalProperties": {}
                }
              },
              "subtotal": {
                "type": "number"
              },
              "discount": {
                "type": "number"
              },
              "shipping": {
                "type": "number"
              },
              "total": {
                "type": "number"
              },
              "currency": {
                "type": "string"
              },
              "payment_status": {
                "type": "string",
                "enum": [
                  "unpaid",
                  "paid"
                ]
              }
            },
            "required": [
              "id",
              "code",
              "status",
              "items",
              "subtotal",
              "discount",
              "shipping",
              "total",
              "currency",
              "payment_status"
            ],
            "additionalProperties": {}
          },
          "intro": {
            "type": "string"
          }
        },
        "required": [
          "kind",
          "order"
        ],
        "additionalProperties": {}
      },
      {
        "type": "object",
        "properties": {
          "kind": {
            "type": "string",
            "const": "payment"
          },
          "payment": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "order_id": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "order_code": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "amount": {
                "type": "number"
              },
              "currency": {
                "type": "string"
              },
              "checkout_url": {
                "type": "string"
              },
              "qr_image_url": {
                "type": "string"
              },
              "qr_payload": {
                "type": "string"
              },
              "code": {
                "type": "string"
              },
              "expires_at": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "status": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "order_id",
              "order_code",
              "amount",
              "currency",
              "checkout_url",
              "qr_image_url",
              "code",
              "expires_at",
              "status"
            ],
            "additionalProperties": {}
          },
          "intro": {
            "type": "string"
          }
        },
        "required": [
          "kind",
          "payment"
        ],
        "additionalProperties": {}
      },
      {
        "type": "object",
        "properties": {
          "kind": {
            "type": "string",
            "const": "quick_replies"
          },
          "options": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "kind",
          "options"
        ],
        "additionalProperties": {}
      },
      {
        "type": "object",
        "properties": {
          "kind": {
            "type": "string",
            "const": "csat"
          },
          "options": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "answered": {
            "type": "boolean"
          }
        },
        "required": [
          "kind",
          "options"
        ],
        "additionalProperties": {}
      }
    ]
  }
}
