Skip to content

NOD Discord API

Jeremy Peterson edited this page Feb 26, 2026 · 1 revision

NOD Discord API

Discord integration for the NAS Operations Dashboard (NOD) TMI tracking.


Overview

The NOD Discord API provides a simplified interface for Discord TMI operations, enabling automatic ingestion of TMI messages from Discord channels and two-way sync between PERTI and Discord.

Base URL: /api/nod/discord.php

Prerequisites: Discord bot token and channel configuration in load/config.php


Quick Reference

Action Method Description
status GET Check Discord integration status
list GET List Discord TMI entries from database
active GET List currently active TMIs
refresh GET Trigger manual refresh from Discord channel
webhook POST Receive Discord webhook events
parse POST Parse TMI message manually
end POST Mark a Discord TMI as ended
send POST Send a TMI message to Discord

Status & Configuration

Check Status

Check if Discord integration is configured and ready.

GET /api/nod/discord.php?action=status

Response (Configured)

{
  "configured": true,
  "status": "READY",
  "message": "Discord integration is configured and ready",
  "config_check": {
    "bot_token": true,
    "tmi_channel": true,
    "guild_id": true
  },
  "channels": {
    "tmi": "123456789012345678"
  }
}

Response (Not Configured)

{
  "configured": false,
  "status": "NOT_CONFIGURED",
  "message": "Discord integration not configured. Add DISCORD_BOT_TOKEN and other credentials to load/config.php"
}

TMI Queries

List Discord TMIs

List all TMI entries ingested from Discord.

GET /api/nod/discord.php?action=list

Optional Parameters

Parameter Type Description
limit int Maximum results (default: 50)
offset int Pagination offset
status string Filter by status (active, ended, all)

Response

{
  "success": true,
  "tmis": [
    {
      "id": 123,
      "discord_message_id": "1234567890123456789",
      "tmi_type": "GDP",
      "airport": "KJFK",
      "program_rate": 38,
      "start_time": "2026-02-01T14:00:00Z",
      "end_time": "2026-02-01T18:00:00Z",
      "scope": "BLANKET",
      "message_text": "GDP KJFK 38/HR 14Z-18Z BLANKET",
      "parsed_at": "2026-02-01T14:05:00Z",
      "status": "active"
    }
  ],
  "count": 1
}

List Active TMIs

List currently active TMIs from Discord.

GET /api/nod/discord.php?action=active

Response

{
  "success": true,
  "tmis": [
    {
      "id": 123,
      "tmi_type": "GDP",
      "airport": "KJFK",
      "program_rate": 38,
      "start_time": "2026-02-01T14:00:00Z",
      "end_time": "2026-02-01T18:00:00Z",
      "elapsed_minutes": 45
    }
  ],
  "count": 1
}

Sync Operations

Refresh from Discord

Trigger a manual refresh to fetch recent messages from the Discord TMI channel.

GET /api/nod/discord.php?action=refresh

Response

{
  "success": true,
  "messages_fetched": 25,
  "new_tmis": 3,
  "updated_tmis": 1,
  "errors": []
}

Send TMI to Discord

Send a TMI announcement to the Discord channel.

POST /api/nod/discord.php?action=send
Content-Type: application/json

{
  "tmi_type": "GDP",
  "airport": "KJFK",
  "program_rate": 38,
  "start_time": "2026-02-01T14:00:00Z",
  "end_time": "2026-02-01T18:00:00Z",
  "scope": "BLANKET",
  "reason": "WEATHER"
}

Response

{
  "success": true,
  "message_id": "1234567890123456789",
  "message_text": "GDP KJFK 38/HR 14Z-18Z BLANKET - WEATHER"
}

Message Handling

Parse Message

Manually parse a TMI message to extract structured data.

POST /api/nod/discord.php?action=parse
Content-Type: application/json

{
  "message": "GDP KJFK 38/HR 14Z-18Z BLANKET - WEATHER"
}

Response

{
  "success": true,
  "parsed": {
    "tmi_type": "GDP",
    "airport": "KJFK",
    "program_rate": 38,
    "start_time": "14:00Z",
    "end_time": "18:00Z",
    "scope": "BLANKET",
    "reason": "WEATHER"
  },
  "confidence": 0.95
}

Webhook Handler

Receive Discord webhook events (legacy integration).

POST /api/nod/discord.php?action=webhook
Content-Type: application/json

{
  "type": "MESSAGE_CREATE",
  "channel_id": "123456789012345678",
  "message": {
    "id": "1234567890123456789",
    "content": "GDP KJFK 38/HR 14Z-18Z BLANKET",
    "author": {"username": "TMI-Bot"},
    "timestamp": "2026-02-01T14:00:00Z"
  }
}

End Discord TMI

Mark a Discord-ingested TMI as ended.

POST /api/nod/discord.php?action=end
Content-Type: application/json

{
  "discord_message_id": "1234567890123456789"
}

or

{
  "tmi_id": 123
}

Response

{
  "success": true,
  "tmi_id": 123,
  "ended_at": "2026-02-01T18:00:00Z"
}

Configuration

Single-Organization (Basic)

Discord integration requires these settings in load/config.php:

define('DISCORD_BOT_TOKEN', 'your-bot-token');
define('DISCORD_GUILD_ID', '123456789012345678');
define('DISCORD_TMI_CHANNEL_ID', '123456789012345678');

Multi-Organization Support

TMI advisories can be posted to multiple Discord servers simultaneously using MultiDiscordAPI.php. Enable multi-org mode and configure each organization's webhook and guild:

// In load/config.php
define('DISCORD_MULTI_ORG_ENABLED', true);
define('DISCORD_ORGANIZATIONS', [
    'VATUSA' => [
        'webhook_url' => 'https://discord.com/api/webhooks/...',
        'guild_id'    => '123456789012345678',
    ],
    'VATCAN' => [
        'webhook_url' => 'https://discord.com/api/webhooks/...',
        'guild_id'    => '987654321098765432',
    ],
]);

When multi-org is enabled, TMI publishing via TMIDiscord.php automatically fans out advisory messages to all configured organizations. The tmi_discord_posts table tracks per-org delivery status, retry counts, and approval state.

Key classes:

  • load/discord/DiscordAPI.php — Single-server Discord REST client
  • load/discord/MultiDiscordAPI.php — Multi-organization posting orchestrator
  • load/discord/TMIDiscord.php — TMI-specific message formatting and dispatch

Error Handling

Discord Not Configured

{
  "success": false,
  "error": "Discord not configured"
}

Unknown Action

{
  "error": "Unknown action: invalid"
}

See Also

Clone this wiki locally