# Webhooks: Stripe, GitHub, and Telegram

Source: https://prontaro.com/docs/integrations/webhooks/

Debug Stripe, GitHub, and Telegram webhook handlers on localhost without re-registering URLs after every restart.

On the Free plan, each named tunnel keeps a permanent `*.prontaro.dev` subdomain (up to 40K requests per month). The browser warning page never intercepts webhooks or API clients, so provider POST requests arrive at `localhost` with original HMAC headers intact, and delivery statuses appear in Prontaro Logs.

## Why Prontaro works well for webhooks

| Need | Free plan (`*.prontaro.dev`) | Tunnels and above (`*.prontaro.run`) |
| --- | --- | --- |
| **Permanent HTTPS URL across restarts** | Yes (assigned subdomain) | Yes (custom `--url` or custom domain) |
| **Webhook delivery without warning page** | Yes | Yes (no warning in browsers either) |
| **Sender IP allowlist (`prontaro access`)** | Yes | Yes |
| **Receive on your dedicated IPv4 (`:443`)** | No | Yes (Dedicated / Pro) |

## Step 1. Start a persistent HTTPS tunnel

Install the [`prontaro` CLI](https://prontaro.com/docs/cli/overview.md), sign in (`prontaro login`), and expose your local app port (for example `3000`):

```
 prontaro http 3000
  Tunnel     webhooks                                ● connected
  Address    https://a7f2k9m3.prontaro.dev  →  http://127.0.0.1:3000
  Access     everyone · no password   (as of launch)
  Server     <server> · <region> · 18 ms
```

The URL stays tied to the `webhooks` name in your account. When you stop it (`Ctrl+C`) and run `prontaro http 3000 --name webhooks` or `prontaro run webhooks` tomorrow, it comes back at the exact same URL — no need to update webhook settings at the provider.

On Tunnels and higher plans you can pick a readable subdomain (`--url my-webhooks` → `https://my-webhooks.prontaro.run`) or attach a [custom domain](https://prontaro.com/docs/tunnels/domains.md).

## Step 2. Register the URL and verify signatures

Never trust an incoming POST request based on URL secrecy alone — always verify the provider’s cryptographic signature or secret token in your handler.

### Stripe

Add an endpoint in the Stripe Dashboard:

**Stripe Dashboard → Developers → Webhooks → Add endpoint**

- `Endpoint URL`: `https://a7f2k9m3.prontaro.dev/webhooks/stripe`
- `Events`: `checkout.session.completed, invoice.paid`

Copy the signing secret (`whsec_...`) and verify `Stripe-Signature` against the raw request body before JSON parsing:

```ts
// Express: mount express.raw({ type: 'application/json' }) on this route
import Stripe from 'stripe';

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);

app.post('/webhooks/stripe', express.raw({ type: 'application/json' }), (req, res) => {
  const sig = req.headers['stripe-signature'] as string;
  try {
    const event = stripe.webhooks.constructEvent(
      req.body,
      sig,
      process.env.STRIPE_WEBHOOK_SECRET!,
    );
    console.log('Stripe event:', event.type);
    res.sendStatus(200);
  } catch (err) {
    res.status(400).send(`Signature error: ${(err as Error).message}`);
  }
});
```

### GitHub

Create a webhook in your repository or organization settings:

**Repository → Settings → Webhooks → Add webhook**

- `Payload URL`: `https://a7f2k9m3.prontaro.dev/webhooks/github`
- `Content type`: `application/json`
- `Secret`: `<GITHUB_WEBHOOK_SECRET>`

Verify the `X-Hub-Signature-256` HMAC-SHA256 header using constant-time comparison (`timingSafeEqual`):

```ts
import crypto from 'node:crypto';

function verifyGitHubSignature(rawBody: Buffer, header: string | undefined, secret: string) {
  if (!header?.startsWith('sha256=')) return false;
  const expected = 'sha256=' + crypto.createHmac('sha256', secret).update(rawBody).digest('hex');
  const a = Buffer.from(header);
  const b = Buffer.from(expected);
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}
```

### Telegram Bot API

Telegram requires HTTPS on port `443` with a trusted TLS certificate — Prontaro provides both automatically. Register your webhook with a `secret_token`:

```bash
curl -fsS -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/setWebhook" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://a7f2k9m3.prontaro.dev/webhooks/telegram",
    "secret_token": "'"${TELEGRAM_WEBHOOK_SECRET}"'"
  }'
```

Telegram includes `X-Telegram-Bot-Api-Secret-Token` on every incoming request (update) — compare it against `TELEGRAM_WEBHOOK_SECRET` before processing the payload.

## Step 3. Restrict access by sender IP (optional)

On top of signature verification, you can restrict [tunnel access](https://prontaro.com/docs/tunnels/access.md) to the provider’s published IPv4 CIDR ranges. Rejected requests stop at the Prontaro server before reaching your machine and do not count toward your monthly traffic allowance.

#### In the dashboard

1. Open **Tunnels**, select `webhooks`, and switch to the **Access** tab.
2. Enable IPv4 restrictions and add the provider’s published CIDRs (for example Telegram’s `149.154.160.0/20` and `91.108.4.0/22`).

Tunnels Access [Open in dashboard](https://my.prontaro.com/tunnels)

#### In the terminal (CLI)

```bash
# Example using Telegram Bot API's published ranges
prontaro access webhooks allow 149.154.160.0/20 91.108.4.0/22
```

> **Skip Basic Auth on webhook tunnels and keep IP lists current**
>
> 1. **Do not enable Basic Auth:** Stripe, GitHub, and Telegram do not send Basic Auth credentials, so the tunnel will reject their deliveries with `401 Unauthorized`. Prontaro also strips the `Authorization` header after verifying Basic Auth, which conflicts with providers that send their own `Authorization` header. Rely on HMAC / `secret_token` verification and optional IP allowlists.
> 2. **Keep provider CIDRs updated:** providers occasionally add egress ranges (check GitHub `/meta` and Stripe’s webhook IP list). Any blocked new sender IP shows up immediately in Logs.

## Step 4. Debug deliveries in Logs

Open [Logs in the dashboard](https://my.prontaro.com/journal) and filter by the `webhooks` tunnel.

Logs [Open in dashboard](https://my.prontaro.com/journal)

Entries appear within about `10` seconds and show:

- sender IP, HTTP method (`POST`), and path (`/webhooks/stripe`);
- your local app’s HTTP status (`200`, `400`, `500`) or local delivery errors (`502`, `504`);
- request duration and bytes transferred;
- access refusals — if a provider rotates onto a new IP, you can allow it directly from the log row.

Webhook bodies, signature headers, and query strings are never stored in Prontaro Logs — inspect payloads directly in your local app logs.

## Common errors

| Symptom | Cause | Fix |
| --- | --- | --- |
| `400 Invalid signature` in Stripe / GitHub | Framework parsed JSON before HMAC verification, altering raw bytes. | Pass the untouched raw body buffer (`express.raw()` / `req.arrayBuffer()`). |
| `403 Forbidden` in provider delivery log | Provider sent the webhook from a new IP missing from `prontaro access`. | Open **Logs** in the dashboard, locate the refused IP, and allow it under **Access**. |
| `502 local_unreachable` | `prontaro http` is running, but nothing listens on local port `3000`. | Start your local server and verify its bind address (`127.0.0.1` or `0.0.0.0`). |
| Telegram reports SSL error or timeout | Registered `http://` instead of `https://` or handler took too long to reply. | Use `https://...prontaro.dev` and return `200 OK` before slow background work. |

## Next steps

- [HTTPS tunnels](https://prontaro.com/docs/tunnels/https.md) — persistent subdomains, `--url` names, and running tunnels in the background.
- [Access control & firewalls](https://prontaro.com/docs/tunnels/access.md) — restrict incoming requests by sender IP and configure Basic Auth.
- [Custom domains](https://prontaro.com/docs/tunnels/domains.md) — receive webhooks on your own domain with automatic Let’s Encrypt certificates.
- [Connection logs](https://prontaro.com/docs/billing/logs.md) — log retention, filtering, and delivery debugging.
- [Prontaro vs ngrok](https://prontaro.com/docs/compare/ngrok.md) — how plans, permanent Free URLs, and webhook features compare.
