BotNetwork

A custom domain and HTTPS for your bot's webhooks, step by step

Every webhook-based bot needs a public HTTPS address that the platform trusts. Getting there is mostly DNS and certificates, and a few platform-specific rules decide whether the first request succeeds.

Published 7 min read

Why a webhook bot needs a domain

With polling, your bot connects out to the platform, so it can run anywhere, even behind a home router. With a webhook, the platform connects to you, which means it needs a stable public URL served over HTTPS with a certificate it trusts. If you are still deciding between the two models, read webhooks vs polling first.

The platforms are explicit about this:

  • Telegram requires TLS for every webhook, on any port, and states that plain-text HTTP webhooks are not possible.
  • Meta's webhooks, which the WhatsApp Cloud API uses, require an endpoint with a valid TLS certificate and state that self-signed certificates are not supported.
  • Discord's HTTP interactions are delivered to an Interactions Endpoint URL that must answer a signed PING before Discord accepts it.

A domain you control is the simplest way to satisfy all three. It also survives a move between servers: you change one DNS record instead of reconfiguring every platform.

Step 1: register a domain

Any registrar works. Pick a short, neutral name you are happy to keep, because webhook URLs end up in several dashboards. If you do not have one yet, you can search and register one at Namecheap domains. A subdomain such as hooks.example.com or bot.example.com is a good habit: it keeps the webhook endpoint separate from any website on the root domain.

Two things to check when registering:

  • The domain must resolve publicly. Newly registered or recently transferred domains can take some time before they resolve everywhere, so register before you need it.
  • Decide who will host DNS. You can use the registrar's DNS or delegate the domain to another DNS provider by changing its nameservers.

Step 2: point DNS at your server

For a bot running on a VPS, create an A record from your chosen hostname to the server's public IPv4 address:

Type Name Content
A hooks 203.0.113.10

This step matters more than it looks for Telegram: its webhook guide says the server must support IPv4 and that IPv6 is currently not supported for webhooks. An AAAA record alone is not enough. If your bot runs on a platform that gives you its own hostname, the platform usually tells you to create a CNAME record instead; follow its instructions.

Check the record before going further:

dig +short hooks.example.com A

If the command prints your server's IP, you can request a certificate. If it prints nothing, wait and check again: certificate authorities look up the same public DNS, so issuance will fail until the record resolves.

Step 3: get a trusted certificate automatically

The least error-prone option is a web server that handles certificates for you. Caddy, for example, obtains and renews certificates from public ACME CAs such as Let's Encrypt or ZeroSSL for any public hostname in its configuration, and redirects HTTP to HTTPS. Its documentation lists the requirements: the A/AAAA records point to the server, ports 80 and 443 are reachable from outside, Caddy can bind to them, and its data directory is writable and persistent.

A minimal Caddyfile that terminates TLS and forwards requests to a bot listening locally on port 8080:

hooks.example.com {
    reverse_proxy 127.0.0.1:8080
}

The bot itself then listens on 127.0.0.1 only, and Caddy is the only process exposed to the internet. Open ports 80 and 443 in the firewall; port 80 is used by the ACME HTTP challenge and for the redirect.

If you prefer Nginx or Apache, the usual route is a Let's Encrypt client such as Certbot. Whatever you use, serve the full chain. Telegram's guide warns that a browser may accept a site with a missing intermediate certificate while the webhook still fails, so do not rely on the browser lock alone.

When you test configuration repeatedly, point the ACME client at the Let's Encrypt staging endpoint, as the Caddy documentation recommends, so you do not run into production rate limits.

Step 4: verify TLS from the outside

Before you register the URL anywhere, confirm what a remote client sees. Telegram's guide suggests both of these:

curl --tlsv1.2 -v https://hooks.example.com/
openssl s_client -tls1_2 -connect hooks.example.com:443 -servername hooks.example.com

Look for three things: the handshake succeeds with TLS 1.2 or newer, the certificate's CN or SAN matches the hostname exactly, and the chain includes the intermediate certificates.

Step 5: meet each platform's rules

Telegram

  • Ports: only 443, 80, 88 and 8443 are supported. Put the port in the URL if it is not 443.
  • TLS 1.2 or newer, with a CN or SAN that matches the domain in the URL.
  • Self-signed certificates are allowed, but then you must upload the public certificate with the certificate parameter of setWebhook. With a publicly trusted certificate you only pass the URL.
  • Telegram documents the source ranges 149.154.160.0/20 and 91.108.4.0/22 and warns they may change.

Our setWebhook walkthrough covers the secret token header and debugging with getWebhookInfo.

WhatsApp Cloud API (Meta webhooks)

  • HTTPS with a valid certificate; self-signed is rejected.
  • When you configure the webhook, Meta sends a GET request with hub.mode, hub.challenge and hub.verify_token. Check the token and respond with the hub.challenge value.
  • Event notifications arrive as POST requests signed in the X-Hub-Signature-256 header with your app secret. Validate it and reply 200.
  • Meta retries failed deliveries for up to 36 hours, so make the handler safe to run twice for the same event.

See your first WhatsApp Cloud API message for the sending side.

Discord HTTP interactions

  • Your endpoint must answer a PING (type: 1) with a 200 response whose body has type: 1, and a valid Content-Type.
  • Every request carries X-Signature-Ed25519 and X-Signature-Timestamp. Verify them with your application's public key and respond 401 when verification fails.
  • Discord states that it sends invalid signatures on purpose as a routine check, and removes the URL if your endpoint accepts them.

If your DNS is on Cloudflare

Cloudflare-proxied records change a few assumptions:

  • A proxied hostname resolves to Cloudflare's anycast addresses, not your server's. Platforms connect to Cloudflare, and Cloudflare connects to your origin.
  • Proxied HTTPS traffic is only accepted on specific ports. Cloudflare's list includes 443 and 8443, which overlap with Telegram's supported ports; port 88 is not on it.
  • Your origin sees Cloudflare's IPs as the connecting address, so an origin firewall rule that only allows Telegram's ranges will block proxied traffic. Either keep the record DNS-only or rely on the secret token header instead of IP filtering.
  • Use the Full (strict) SSL mode so Cloudflare validates the certificate on your origin instead of accepting any certificate.

A landing page for your bot

Platforms and users often ask where to find information about a bot: what it does, how to contact the operator, and what data it stores. A one-page site on the same domain is enough. If you do not want to run it on the bot's server, small shared hosting is a simple option, for example Namecheap hosting; keep the webhook subdomain pointed at the bot server and the root domain at the hosting. Our legal and privacy guide covers what to put on that page.

Checklist

  1. Register a domain (any registrar; Namecheap is one option) and choose a webhook subdomain.
  2. Create an A record to the server's IPv4 address and confirm it with dig.
  3. Run Caddy or another server with automatic certificates, with ports 80 and 443 open.
  4. Check TLS version, hostname match and full chain with curl and openssl.
  5. Apply each platform's rules: Telegram ports and certificate handling, Meta's verification and signature, Discord's PING and Ed25519 checks.
  6. If the record is proxied by Cloudflare, use a supported port, Full (strict) mode and no IP allowlist at the origin.

Keep tokens and app secrets out of the URL and the repository; securing bot tokens explains how.

Sources