开发者

把 askher 接入你的系统。
与 Sofia 遵循相同的规则。

通过 API 读取商家资料、查询空位并管理预订;通过 Webhook 第一时间获知动态;还有一个可嵌入网站的按钮。Pro 及以上套餐已包含,无需额外付费。

基础

快速开始

API 的访问地址为 https://askher.it/api/v1,使用 JSON 和 UTF-8。日期格式为 YYYY-MM-DD,时间格式为 HH:MM,一律采用商家所在时区(Europe/Rome)。预订会经过与 Sofia 电话接待相同的校验:容纳人数、时长、营业时间、休业安排和团体预订。不存在的座位永远无法预订。

每个请求都要在 Authorization 请求头中携带密钥。写入操作(POST、PATCH)需要 JSON 请求体,并带上 Content-Type: application/json,大小不超过 4,096 字节。

curl https://askher.it/api/v1/locale \
  -H "Authorization: Bearer $ASKHER_CHIAVE"

密钥与订阅

密钥在管理后台的 Sul tuo sito → Chiavi API(“你的网站 → API 密钥”)中创建。密钥以 ask_live_ 开头,仅对一个商家有效,完整内容只显示一次,请立即复制保存。

密钥可随时吊销,吊销后调用将返回 401。请将其保存在服务器端,切勿放入浏览器或应用的代码中。

API、Webhook 和按钮已包含在 Pro 与 Enterprise 套餐中,无需额外付费。使用 Base 套餐或没有有效订阅时,调用将返回 403。定制集成和专属软件由我们按报价开发(Enterprise)。

频率限制

每个密钥:每分钟 60 次请求,其中最多 10 次写入(创建、修改、取消)。每个商家,所有密钥合计:每小时 2,000 次请求。

每个响应都带有 X-RateLimit-Limit 和 X-RateLimit-Remaining(针对该密钥的每分钟限制),错误响应也不例外;只有 401 和 403 除外,因为它们在检查限制之前就已返回。超出限制时返回 429,并通过 Retry-After 给出重试前需要等待的秒数。

错误

错误的结构始终相同。campi 列出需要修正的字段(400 和 422);返回 409 时,这里改为 alternative,即最接近的空闲时段。

422响应

{
  "errore": {
    "codice": "dati_non_validi",
    "messaggio": "Controlla i campi indicati: data AAAA-MM-GG, ora HH:MM, persone intero da 1 a 60, nome fino a 80 caratteri, telefono da 6 a 15 cifre, note fino a 300 caratteri.",
    "campi": ["ora"]
  }
}

codice 保持稳定,供你的代码使用;messaggio 是一句意大利语,可用于展示或记录日志。

状态代码触发条件
400parametri_non_validijson_non_validocampo_sconosciutoidempotency_key_non_valida参数、JSON 或 Idempotency-Key 无效,或包含未定义的字段
401chiave_mancantechiave_non_validachiave_revocata密钥缺失、错误或已被吊销
403piano_non_inclusoabbonamento_non_attivo该商家的套餐不包含 API,或订阅未生效
404prenotazione_non_trovata没有该代码对应的预订
409non_disponibilerichiesta_in_corso没有空位(响应中包含备选方案),或带有相同 Idempotency-Key 的请求仍在处理中
413corpo_troppo_grande请求体超过 4,096 字节
415formato_non_supportato请求体缺少 Content-Type: application/json
422dati_non_validinessun_cambioidempotency_key_riusata取值格式不正确或超出范围,没有需要修改的内容,或 Idempotency-Key 已与不同的请求体一起使用过
429troppe_richieste超出请求频率限制:请在 Retry-After 之后重试
502prenotazioni_non_raggiungibili预订系统没有响应:请稍后重试
503prenotazioni_non_attive该商家的预订尚未接入 askher

接口

商家信息

GET/api/v1/locale

Sofia 掌握的全部信息:名称、地址、每周营业时间、即将到来的休业安排、预订规则、含价格的菜单、过敏原和已售罄菜品、服务、饮食选项、支付方式以及顾客通知。

资料中未填写的字段会返回 null 或空值。caparra 和 dehors 未启用时为 null;animali 的取值为 ammessi、solo_piccola_taglia 或 non_ammessi。没有对公众开放的场所(上门、在线、在客户处)时,senza_sede 为 true:indirizzo、come_arrivare 和 parcheggio 为 null,zona 说明服务区域;有场所时 senza_sede 为 false,zona 为 null。

curl https://askher.it/api/v1/locale \
  -H "Authorization: Bearer $ASKHER_CHIAVE"

200响应

{
  "id": "osteria-del-borgo",
  "nome": "Osteria del Borgo",
  "assistente": "Sofia",
  "descrizione": "Cucina di tradizione e pasta fatta in casa.",
  "cucina": ["italiana"],
  "fascia_prezzo": "€€",
  "sito": null,
  "modalita": "tavoli",
  "coperti": 60,
  "agenda": null,
  "senza_sede": false,
  "indirizzo": { "via": "Via Roma 1", "citta": "Bergamo", "cap": "24121" },
  "zona": null,
  "come_arrivare": null,
  "parcheggio": null,
  "orari": {
    "lunedi": [],
    "martedi": [{ "da": "19:00", "a": "23:00" }],
    "mercoledi": [{ "da": "19:00", "a": "23:00" }],
    "giovedi": [{ "da": "19:00", "a": "23:00" }],
    "venerdi": [{ "da": "12:00", "a": "14:30" }, { "da": "19:00", "a": "23:30" }],
    "sabato": [{ "da": "12:00", "a": "14:30" }, { "da": "19:00", "a": "23:30" }],
    "domenica": [{ "da": "12:00", "a": "15:00" }]
  },
  "chiusure": [{ "dal": "2026-12-24", "al": "2026-12-26", "motivo": "Natale" }],
  "prenotazioni": {
    "persone_max": 10,
    "tolleranza_minuti": 15,
    "caparra": null,
    "regole": []
  },
  "menu": [
    {
      "piatto": "Casoncelli alla bergamasca",
      "categoria": "Primi",
      "prezzo": 14,
      "allergeni": ["glutine", "uova", "latte"],
      "etichette": ["della casa"],
      "disponibile": true,
      "descrizione": null
    }
  ],
  "servizi": {
    "asporto": true,
    "consegna": false,
    "eventi_privati": true,
    "wifi": true,
    "accessibile": true,
    "seggiolone": true,
    "dehors": { "posti": 20, "periodo": "da maggio a settembre" },
    "animali": "solo_piccola_taglia"
  },
  "diete": { "vegetariano": true, "vegano": false, "senza_glutine": true, "senza_glutine_certificato": false },
  "pagamenti": ["Contanti", "Carte di credito"],
  "avvisi": []
}

预约制商家

诊所、美发店和各类中心按预约营业:GET /api/v1/locale 通过 modalita: "appuntamenti" 标明(餐厅为 "tavoli"),并在 agenda 中列出各项服务及其时长(分钟)、工作人员以及谁负责哪项服务。每位工作人员同一时间只接一个预约;没有列出工作人员时,商家同一时间只接一个预约。

在此模式下,查询空位、创建和修改还接受 servizio、operatore 和 durata_min,persone 变为可选(默认 1)。如果商家有价目表,服务必须是其中之一(不区分大小写和重音),并由它决定时长;未提供 operatore 时,askher 会在提供该服务的人员中选一位空闲的。对餐厅而言,这些字段出现在请求体中会返回 400(campo_sconosciuto),出现在 query 中则被忽略。

curl -X POST https://askher.it/api/v1/prenotazioni \
  -H "Authorization: Bearer $ASKHER_CHIAVE" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: visita-0412" \
  -d '{"data":"2026-12-03","ora":"10:00","servizio":"Igiene","nome":"Verdi"}'

201响应

{
  "prenotazione": {
    "codice": "T4MZ", "data": "2026-12-03", "ora": "10:00", "persone": 1,
    "nome": "Verdi", "telefono": "+393331234567", "note": null,
    "servizio": "Igiene", "operatore": "Dottor Neri", "durata_min": 45,
    "stato": "confermata", "origine": "api", "creata": "2026-11-22T18:04:11Z"
  },
  "stato": "confermata",
  "riepilogo": "giovedì 3 dicembre alle 10:00, Igiene con Dottor Neri (45 min), a nome Verdi"
}

如果该时间已被占用,会返回 409(或 disponibile: false)及 alternative:同一天附近最多三个空闲时间,每个都带有对应的 operatore,或之后 7 天内的第一个空闲时间。每条预订都包含 servizio、operatore 和 durata_min(桌位预订为 null),webhook 中也是如此。状态为 richiesta 且时间明确的预约会在日程中占住该时段,直到商家确认或取消,以免重复预约。

409响应

{
  "errore": {
    "codice": "non_disponibile",
    "messaggio": "giovedì 3 dicembre alle 10:00 non c'è posto per Igiene (45 min).",
    "alternative": [
      { "data": "2026-12-03", "ora": "09:00", "operatore": "Dottor Neri" },
      { "data": "2026-12-03", "ora": "11:00", "operatore": "Dottor Neri" }
    ]
  }
}

空位查询

GET/api/v1/disponibilita

有空位吗?按与 Sofia 相同的规则作答,不会预订任何内容。

查询参数

  • datastring必填

    日期,格式为 YYYY-MM-DD。

  • orastring必填

    时间,格式为 HH:MM。

  • personeinteger必填

    1 至 60 的整数。

  • serviziostring选填

    仅限预约制商家:价目表中的服务,最多 60 个字符。

  • operatorestring选填

    仅限预约制商家:由谁负责,取自 agenda 中的工作人员。未提供时,askher 会选一位空闲人员。

  • durata_mininteger选填

    仅限预约制商家:5 到 1440 分钟,用于价目表之外的服务。价目表中的服务按其标注的时长计算。

无空位时,alternative 会给出最近的空闲时段。若 solo_su_richiesta: true,说明该团体超出了商家的人数上限:仍可预订,但需等待确认。messaggio 就是 Sofia 会说的那句话。

curl "https://askher.it/api/v1/disponibilita?data=2026-12-05&ora=20%3A30&persone=4" \
  -H "Authorization: Bearer $ASKHER_CHIAVE"

200响应

{
  "data": "2026-12-05",
  "ora": "20:30",
  "persone": 4,
  "disponibile": false,
  "solo_su_richiesta": false,
  "messaggio": "sabato 5 dicembre alle 20:30 è al completo per 4.",
  "alternative": [{ "data": "2026-12-05", "ora": "21:30" }]
}

创建预订

POST/api/v1/prenotazioni

创建一个预订,并进行与电话预订相同的防超订校验。

请求体字段(JSON)

  • datastring必填

    日期,格式为 YYYY-MM-DD。

  • orastring必填

    时间,格式为 HH:MM。

  • personeinteger必填

    1 至 60 的整数。

  • nomestring必填

    预订人姓名,最多 80 个字符。

  • telefonostring选填

    6 至 15 位数字,开头可带 +;空格、点、连字符和括号会被去除。

  • notestring选填

    最多 300 个字符。

  • serviziostring选填

    仅限预约制商家:价目表中的服务,最多 60 个字符。

  • operatorestring选填

    仅限预约制商家:由谁负责,取自 agenda 中的工作人员。未提供时,askher 会选一位空闲人员。

  • durata_mininteger选填

    仅限预约制商家:5 到 1440 分钟,用于价目表之外的服务。价目表中的服务按其标注的时长计算。

请求头

  • Idempotency-Keystring选填

    8 至 80 个字符,可使用字母、数字、- 和 _。每个商家的有效期为 24 小时:请求体相同则返回相同的响应,并带有 Idempotent-Replayed: true,不会重复预订;请求体不同则返回 422(idempotency_key_riusata);如果第一个请求仍在处理中,则返回 409(richiesta_in_corso)。如果第一个请求以 502 或 503 失败,该密钥可以重新使用。

返回 201,包含预订的 codice 和 stato:confermata,或对需确认的团体返回 richiesta。无空位时返回 409 及备选方案。

多余的字段会被拒绝并返回 400,无效的取值返回 422。

curl -X POST https://askher.it/api/v1/prenotazioni \
  -H "Authorization: Bearer $ASKHER_CHIAVE" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: ordine-2291" \
  -d '{"data":"2026-12-05","ora":"20:00","persone":2,"nome":"Rossi","telefono":"+39 333 1234567"}'

201响应

{
  "prenotazione": {
    "codice": "K7P2", "data": "2026-12-05", "ora": "20:00", "persone": 2,
    "nome": "Rossi", "telefono": "+393331234567", "note": null,
    "servizio": null, "operatore": null, "durata_min": null,
    "stato": "confermata", "origine": "api", "creata": "2026-11-22T18:04:11Z"
  },
  "stato": "confermata",
  "riepilogo": "sabato 5 dicembre alle 20:00, 2 persone, a nome Rossi"
}

409响应

{
  "errore": {
    "codice": "non_disponibile",
    "messaggio": "sabato 5 dicembre alle 20:00 è al completo per 2.",
    "alternative": [{ "data": "2026-12-05", "ora": "21:30" }]
  }
}

预订列表

GET/api/v1/prenotazioni

返回商家的预订,来源不限:电话、网站、API 和管理后台。

查询参数

  • dalstring选填

    起始日期,YYYY-MM-DD。缺省为今天。

  • alstring选填

    截止日期(含当天),YYYY-MM-DD,不得早于 dal。缺省为此后的所有预订。

按日期从远到近排序。stato 的取值为 confermata、richiesta、arrivati 或 annullata;origine 的取值为 telefono、sito、api 或 gestore。

curl "https://askher.it/api/v1/prenotazioni?dal=2026-12-01&al=2026-12-07" \
  -H "Authorization: Bearer $ASKHER_CHIAVE"

200响应

{
  "prenotazioni": [
    {
      "codice": "K7P2", "data": "2026-12-05", "ora": "20:00", "persone": 2,
      "nome": "Rossi", "telefono": "+393331234567", "note": null,
      "servizio": null, "operatore": null, "durata_min": null,
      "stato": "confermata", "origine": "api", "creata": "2026-11-22T18:04:11Z"
    },
    {
      "codice": "M3QX", "data": "2026-12-03", "ora": "13:00", "persone": 4,
      "nome": "Bianchi", "telefono": null, "note": "Un seggiolone",
      "servizio": null, "operatore": null, "durata_min": null,
      "stato": "confermata", "origine": "telefono", "creata": "2026-11-20T09:12:40Z"
    }
  ]
}

查询单个预订

GET/api/v1/prenotazioni/{codice}

查询今天、未来或最近 30 天内的预订,否则返回 404。

路径参数

  • codicestring必填

    预订代码(例如 K7P2),不区分大小写。

curl https://askher.it/api/v1/prenotazioni/K7P2 \
  -H "Authorization: Bearer $ASKHER_CHIAVE"

200响应

{
  "prenotazione": {
    "codice": "K7P2", "data": "2026-12-05", "ora": "20:00", "persone": 2,
    "nome": "Rossi", "telefono": "+393331234567", "note": null,
    "servizio": null, "operatore": null, "durata_min": null,
    "stato": "confermata", "origine": "api", "creata": "2026-11-22T18:04:11Z"
  }
}

修改预订

PATCH/api/v1/prenotazioni/{codice}

只修改所传的字段:至少传一个,否则返回 422 及 nessun_cambio。姓名和电话不可修改。座位会像新预订一样重新校验:若无空位,返回 409 及备选方案,原预订保持不变。

请求体字段(JSON)

  • datastring选填

    新的日期,YYYY-MM-DD。

  • orastring选填

    新的时间,HH:MM。

  • personeinteger选填

    1 至 60 的整数。

  • notestring选填

    1 至 300 个字符:将替换原有备注。

  • serviziostring选填

    仅限预约制商家:价目表中的服务,最多 60 个字符。

  • operatorestring选填

    仅限预约制商家:由谁负责,取自 agenda 中的工作人员。未提供时,askher 会选一位空闲人员。

  • durata_mininteger选填

    仅限预约制商家:5 到 1440 分钟,用于价目表之外的服务。价目表中的服务按其标注的时长计算。

返回 200,包含更新后的预订、stato 和 riepilogo。

curl -X PATCH https://askher.it/api/v1/prenotazioni/K7P2 \
  -H "Authorization: Bearer $ASKHER_CHIAVE" \
  -H "Content-Type: application/json" \
  -d '{"persone":3}'

200响应

{
  "prenotazione": {
    "codice": "K7P2", "data": "2026-12-05", "ora": "20:00", "persone": 3,
    "nome": "Rossi", "telefono": "+393331234567", "note": null,
    "servizio": null, "operatore": null, "durata_min": null,
    "stato": "confermata", "origine": "api", "creata": "2026-11-22T18:04:11Z"
  },
  "stato": "confermata",
  "riepilogo": "sabato 5 dicembre alle 20:00, 3 persone, a nome Rossi"
}

取消预订

DELETE/api/v1/prenotazioni/{codice}

取消该预订。返回 200,包含该预订以及 stato: "annullata";若代码不存在,返回 404。

curl -X DELETE https://askher.it/api/v1/prenotazioni/K7P2 \
  -H "Authorization: Bearer $ASKHER_CHIAVE"

200响应

{
  "prenotazione": {
    "codice": "K7P2", "data": "2026-12-05", "ora": "20:00", "persone": 2,
    "nome": "Rossi", "telefono": "+393331234567", "note": null,
    "servizio": null, "operatore": null, "durata_min": null,
    "stato": "annullata", "origine": "api", "creata": "2026-11-22T18:04:11Z"
  },
  "stato": "annullata"
}

Webhook 与网站

Webhook

在管理后台的 Sul tuo sito → Webhook(“你的网站 → Webhook”)中填写一个公开的 https:// 地址。当预订来自网站按钮、API 或管理后台时,askher 会发送 JSON POST。电话预订可通过 GET /api/v1/prenotazioni 读取。

事件:prenotazione.creata、prenotazione.modificata、prenotazione.annullata,以及你在管理后台发送测试事件时的 prova。dati 中是预订内容,字段与 API 相同。

请求体

{
  "id": "evt_9f2c41d07a6be3a1",
  "evento": "prenotazione.creata",
  "locale": "osteria-del-borgo",
  "creato": "2026-11-22T18:04:12.511Z",
  "dati": {
    "codice": "K7P2", "data": "2026-12-05", "ora": "20:00", "persone": 2,
    "nome": "Rossi", "telefono": "+393331234567", "note": null,
    "servizio": null, "operatore": null, "durata_min": null,
    "stato": "confermata", "origine": "api", "creata": "2026-11-22T18:04:11Z"
  }
}

每次推送都带有 askher-evento(事件名称)和 askher-firma 请求头,并带有 User-Agent: askher-webhook/1。

请在 5 秒内返回 2xx。如果你的服务器没有响应或返回 5xx,我们会在 2 秒后重试一次;不会跟随重定向。

验证签名

askher-firma: t=<seconds>,v1=<signature>:签名是以 Webhook 密钥(以 whsec_ 开头)对 ${t}.${corpo} 计算的十六进制 HMAC-SHA256,计算对象是未经解析、与收到时完全一致的请求体。

请丢弃 t 早于 5 分钟的事件,并以恒定时间比较签名。

import { createHmac, timingSafeEqual } from "node:crypto";

export function firmaValida(corpo, intestazione, segreto) {
  const parti = Object.fromEntries(intestazione.split(",").map((x) => x.split("=")));
  const t = Number(parti.t);
  if (!t || Math.abs(Date.now() / 1000 - t) > 300) return false;
  const attesa = createHmac("sha256", segreto).update(`${parti.t}.${corpo}`).digest("hex");
  const ricevuta = String(parti.v1 ?? "");
  return ricevuta.length === attesa.length && timingSafeEqual(Buffer.from(attesa), Buffer.from(ricevuta));
}

网站“询问 askher”按钮

在 </body> 之前加一行代码:页面右下角会出现一个按钮,点击后在聊天中打开 Sofia。她依据商家资料回答营业时间、服务和价格问题(餐厅还包括菜单和过敏原),并按与电话相同的规则预订。她会第一时间表明自己是人工智能。它只是一个文件,无 Cookie,运行在不影响网站样式的 Shadow DOM 中,支持键盘操作和屏幕阅读器,在手机上会全屏打开。

HTML

<script src="https://askher.it/widget/v1.js" data-locale="ID-DEL-LOCALE" async></script>

带有正确 ID 的代码已在管理后台准备好。按钮只会在你于其中列出的允许站点上响应;颜色和问候语可在同一页面修改,并支持实时预览。为防止滥用,我们对每位访客和每个商家设有限制。