Webhooks
An àite bhòtadh tric, thoir webhook_url do ruith. Nuair a ruigeas an t-iarrtas inbhe dheireannach (succeeded, failed no
canceled), cuiridh sinn POST le ainm-sgrìobhte chun URL sin.
curl -X POST "https://api.doitong.ru/v1/run/{model_id}?webhook_url=https://example.com/hooks/doitong" \
-H "Authorization: Bearer $DOITONG_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "..."}'
An tachartas
POST /hooks/doitong HTTP/1.1
Content-Type: application/json
User-Agent: Doitong-Webhooks/1
Doitong-Request-Id: req_8k2m4q7x1z9c3v5b6n0p2r4t
Doitong-Signature: t=1760961609,v1=5f1c0d6e2b…
{
"id": "evt_8k2m4q7x1z9c3v5b6n0p2r4t_succeeded",
"object": "event",
"type": "request.succeeded",
"created_at": "2026-10-20T12:00:09Z",
"data": {
"id": "req_8k2m4q7x1z9c3v5b6n0p2r4t",
"object": "request",
"status": "succeeded",
"outputs": [ { "type": "video", "url": "https://content.doitong.com/dev-api/…/0-output.mp4" } ]
}
}
- Is e
typerequest.succeeded,request.failednorequest.canceled. - Is e
dataan nì iarrtais slàn, dìreach mar a thilleasGET /requests/{id}. - Tha
idseasmhach airson iarrtas agus an inbhe dheireannach aige. Cleachd e gus lìbhrigeadh a làimhsich thu mu thràth a leigeil seachad.
Lìbhrigidhean agus ath-oidhirpean
Freagair le inbhe 2xx sam bith taobh a-staigh 10 diogan. Thèid rud sam bith eile (no ùine-ama) ath-fheuchainn: suas ri 6 oidhirpean uile gu lèir,
às dèidh 30 diog, 2 mhionaid, 10 mionaidean, 1 uair agus 6 uairean. Dèan obair shlaodach an dèidh dhut freagairt, chan ann roimhe.
Dearbhaich an t-ainm-sgrìobhte
Tha an dìomhair soidhnidh fhèin aig gach iuchair. Leugh e aon turas bho GET https://api.doitong.ru/v1/account (webhook_signing_secret,
tha e a’ tòiseachadh le whsec_) agus glèidh e ri taobh na h-iuchrach.
Tha bann-cinn Doitong-Signature de chruth t=<unix time>,v1=<signature>, far a bheil an t-ainm-sgrìobhte na
HMAC-SHA256 hexadecimal de "<t>.<raw request body>" le do dhìomhaireachd mar an iuchair. Gus dearbhadh:
- Gabh na bytes den bhodhaig amh dìreach mar a fhuaireadh iad (mus tèid JSON a pharsadh).
- Obraich a-mach HMAC-SHA256 de
t + "." + bodyle do dhìomhaireachd, mar hexadecimal litrichean beaga. - Dèan coimeas ris an
v1ann an ùine sheasmhach. - Diùlt an tachartas nuair a tha
tcòrr is 5 mionaidean air falbh bhon uaireadair agad (dìon an aghaidh ath-chluich).
Glacadair slàn ann an Node.js (Express) agus Python (Flask):
import crypto from "node:crypto";
import express from "express";
const SECRET = process.env.DOITONG_WEBHOOK_SECRET; // whsec_...
const app = express();
app.post("/hooks/doitong", express.raw({ type: "application/json" }), (req, res) => {
const header = req.get("Doitong-Signature") || "";
const parts = Object.fromEntries(header.split(",").map((p) => p.split("=", 2)));
const t = Number(parts.t);
const expected = crypto.createHmac("sha256", SECRET).update(t + "." + req.body).digest("hex");
const given = Buffer.from(parts.v1 || "", "utf8");
const valid =
given.length === expected.length &&
crypto.timingSafeEqual(given, Buffer.from(expected, "utf8")) &&
Math.abs(Date.now() / 1000 - t) < 300;
if (!valid) return res.status(400).send("bad signature");
const event = JSON.parse(req.body);
if (event.type === "request.succeeded") {
console.log(event.data.id, event.data.outputs.map((o) => o.url));
}
res.sendStatus(204);
});
import hashlib
import hmac
import json
import os
import time
from flask import Flask, abort, request
SECRET = os.environ["DOITONG_WEBHOOK_SECRET"].encode() # whsec_...
app = Flask(__name__)
@app.post("/hooks/doitong")
def doitong_hook():
body = request.get_data() # raw bytes
parts = dict(p.split("=", 1) for p in request.headers.get("Doitong-Signature", "").split(",") if "=" in p)
t = parts.get("t", "0")
expected = hmac.new(SECRET, t.encode() + b"." + body, hashlib.sha256).hexdigest()
if not hmac.compare_digest(expected, parts.get("v1", "")) or abs(time.time() - int(t)) > 300:
abort(400)
event = json.loads(body)
if event["type"] == "request.succeeded":
print(event["data"]["id"], [o["url"] for o in event["data"]["outputs"]])
return "", 204
Molaidhean
- Freagair gu luath agus cuir do ghiollachd fhèin ann an ciudha.
- Buinidh an dìomhair don iuchair API a thòisich an ruith. Tha dìomhaireachdan eadar-dhealaichte aig iuchraichean ann an seirbheisean eadar-dhealaichte.