Send AlertHub alerts from Node.js, Python, and PHP

Send AlertHub alerts from Node.js, Python, and PHP

If your app can make an HTTPS POST, it can alert. You do not need a vendor Slack SDK in every service. Point all languages at the same Ingestion API: POST https://api.thealerthub.com/sendAlert.

Keep the project secret in environment variables. Never ship it in a browser bundle — that key writes alerts.

Only warning and critical reach Slack, Telegram, and the rest. info is dashboard-only. Levels.

Setup (once)

  1. Create a project at app.thealerthub.com.
  2. Set ALERTHUB_KEY in the server environment.
  3. Connect at least one destination, then run a snippet below.

Placeholders ({{user.id}}) work if you send extra JSON fields. Details: Webhook Builder.

Node.js (built-in fetch)

const ALERTHUB_URL = 'https://api.thealerthub.com/sendAlert';

export async function sendAlert({ title, description, level = 'warning', source = 'api' }) {
  const res = await fetch(ALERTHUB_URL, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      ah_key: process.env.ALERTHUB_KEY,
      ah_title: title,
      ah_description: description,
      ah_level: level,
      ah_source: source,
    }),
  });
  if (!res.ok) throw new Error(`AlertHub ${res.status}`);
  return res.json();
}

// await sendAlert({ title: 'Queue depth', description: 'jobs=900', level: 'critical' });

Use this from Express error handlers, workers, and GitHub Actions (curl is fine in YAML; Node is for the app itself).

Python (requests)

import os
import requests

ALERTHUB_URL = "https://api.thealerthub.com/sendAlert"

def send_alert(title, description, level="warning", source="api"):
    r = requests.post(
        ALERTHUB_URL,
        json={
            "ah_key": os.environ["ALERTHUB_KEY"],
            "ah_title": title,
            "ah_description": description,
            "ah_level": level,
            "ah_source": source,
        },
        timeout=10,
    )
    r.raise_for_status()
    return r.json()

Call from Django/except, Celery failure handlers, or FastAPI middleware. Do not block the request path on a slow network without a timeout (shown above).

PHP (cURL)

<?php
function alerthub_send(string $title, string $description, string $level = 'warning', string $source = 'api'): void {
    $payload = json_encode([
        'ah_key' => getenv('ALERTHUB_KEY'),
        'ah_title' => $title,
        'ah_description' => $description,
        'ah_level' => $level,
        'ah_source' => $source,
    ]);
    $ch = curl_init('https://api.thealerthub.com/sendAlert');
    curl_setopt_array($ch, [
        CURLOPT_POST => true,
        CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
        CURLOPT_POSTFIELDS => $payload,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 10,
    ]);
    $body = curl_exec($ch);
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    if ($body === false || $code >= 400) {
        error_log('AlertHub failed: ' . $code);
    }
}

WordPress sites that need more than hooks can keep using the plugin for add_action, and this snippet for custom plugins.

Ideas to squeeze more value

  • Wrap once. One helper per repo beats copy-paste in 12 workers.
  • Cron without a language. Bash guide and uptime.
  • n8n / Zapier when the event is in a SaaS, not your code. n8n.

FAQ

Is there an official npm/PyPI/Composer package?
The stable integration is HTTP to api.thealerthub.com. Use the snippets above.

Query string instead of JSON?
Supported. JSON is easier for nested {{placeholders}}.

Can the browser call this?
Do not expose ah_key to visitors. Send from your backend.

Next steps

Drop a helper in your API, fire a warning, confirm the dashboard and Telegram.

Related: Ingestion API · GitHub Actions