Receiving Updates via Webhooks¶
For high-throughput production environments, Webhooks are the recommended mechanism for receiving incoming updates. Whenever an event happens, the CodeMeet server sends an HTTP POST request containing a JSON-serialized Update object directly to your webhook URL.
Webhook Security & Requirements¶
- HTTPS Only: Your webhook endpoint must be reachable via a public URL with a valid TLS/SSL certificate.
- Ports: Supported standard ports include
443,80,8080, and8443. - Secret Token: Configure a secret token string to verify that incoming HTTP requests originate from the CodeMeet relay service.
Webhook Management Methods¶
1. Set Webhook (setWebhook)¶
Configures and activates the webhook for your bot:
POST
https://botapi.codemeet.chat/bot<TOKEN>/setWebhook
Parameters¶
| Parameter | Type | Status | Description |
|---|---|---|---|
url |
String |
Required | Public HTTPS URL where updates should be posted (e.g. https://mybot.example.com/webhook). |
secret_token |
String |
Optional | A secret string (1–256 characters: A-Z, a-z, 0-9, _, -) forwarded in headers. |
drop_pending_updates |
Boolean |
Optional | If true, drops undelivered backlog updates immediately. |
max_connections |
Integer |
Optional | Maximum simultaneous HTTPS connections (1–100, default: 40). |
allowed_updates |
Array of String |
Optional | List of update types to forward. |
Request Example¶
{
"url": "https://api.example.com/codemeet/webhook",
"secret_token": "a8fbc7190d3e21849102cba",
"drop_pending_updates": true
}
Response Example¶
2. Get Webhook Status (getWebhookInfo)¶
Inspects the current webhook status, error logs, and pending update queue size:
GET
POST
https://botapi.codemeet.chat/bot<TOKEN>/getWebhookInfo
Response Example¶
{
"ok": true,
"result": {
"url": "https://api.example.com/codemeet/webhook",
"has_custom_certificate": false,
"pending_update_count": 0,
"last_error": null
}
}
3. Remove Webhook (deleteWebhook)¶
Deletes the webhook URL and restores the ability to use getUpdates:
POST
https://botapi.codemeet.chat/bot<TOKEN>/deleteWebhook
FastAPI (Python) Webhook Server Example¶
from fastapi import FastAPI, Request, Header, HTTPException
app = FastAPI()
BOT_TOKEN = "YOUR_BOT_TOKEN"
WEBHOOK_SECRET = "a8fbc7190d3e21849102cba"
@app.post("/webhook")
async def receive_update(
request: Request,
x_codemeet_bot_api_secret_token: str | None = Header(None)
):
update = await request.json()
print("Received update:", update)
if "message" in update:
msg = update["message"]
chat_id = msg["chat"]["id"]
text = msg.get("text", "")
# Process and respond...
return {"status": "ok"}