Temporary Event Webhook for Calendar Events #72

Open
opened 2025-12-13 01:09:51 -06:00 by EagleTrooper · 0 comments
Owner

Request

When a new event is

  • created / Posted
  • canceled
    Send an event notification to a discord webhook.

This is until the Milsim Integration Bot is built out and can handle cron jobs to check for event data and post to Discord.

Rough Code example

Discord Notification Function

// utils/discordNotifier.js
import fetch from 'node-fetch';
import { DISCORD_WEBHOOK_URL } from '../config/discord.js';

export async function sendDiscordEventNotification(type, event) {
    let embed;

    if (type === 'created') {
        embed = {
            title: '📅 New Event Created',
            color: 0x2ecc71, // green
            fields: [
                { name: 'Event', value: event.name, inline: false },
                { name: 'Start', value: `<t:${Math.floor(new Date(event.start).getTime() / 1000)}:F>`, inline: true },
                { name: 'End', value: `<t:${Math.floor(new Date(event.end).getTime() / 1000)}:F>`, inline: true },
                { name: 'Location', value: event.location || 'N/A', inline: false }
            ],
            description: event.description || '',
            footer: { text: 'Calendar System' }
        };
    }

    if (type === 'cancelled') {
        embed = {
            title: '❌ Event Cancelled',
            color: 0xe74c3c, // red
            fields: [
                { name: 'Event', value: event.name, inline: false },
                { name: 'Originally Scheduled', value: `<t:${Math.floor(new Date(event.start).getTime() / 1000)}:F>` }
            ],
            footer: { text: 'Calendar System' }
        };
    }

    await fetch(DISCORD_WEBHOOK_URL, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
            username: 'Event Bot',
            embeds: [embed]
        })
    });
}

Send Notification of New Event Created

    // 🔔 Notify Discord
    await sendDiscordEventNotification('created', event);

Send Notification of Event Canceld

    // 🔔 Notify Discord
    await sendDiscordEventNotification('cancelled', event);

I am not sure exactly how this would best implement into the code but would be good to handle until Discord Bot can be built to "Sync" events. New event created in calendar Creates discord event / event in discord creates calendar event. (Not even sure if we want this)

## Request When a new event is - created / Posted - canceled Send an event notification to a discord webhook. This is until the Milsim Integration Bot is built out and can handle cron jobs to check for event data and post to Discord. Rough Code example Discord Notification Function ```js // utils/discordNotifier.js import fetch from 'node-fetch'; import { DISCORD_WEBHOOK_URL } from '../config/discord.js'; export async function sendDiscordEventNotification(type, event) { let embed; if (type === 'created') { embed = { title: '📅 New Event Created', color: 0x2ecc71, // green fields: [ { name: 'Event', value: event.name, inline: false }, { name: 'Start', value: `<t:${Math.floor(new Date(event.start).getTime() / 1000)}:F>`, inline: true }, { name: 'End', value: `<t:${Math.floor(new Date(event.end).getTime() / 1000)}:F>`, inline: true }, { name: 'Location', value: event.location || 'N/A', inline: false } ], description: event.description || '', footer: { text: 'Calendar System' } }; } if (type === 'cancelled') { embed = { title: '❌ Event Cancelled', color: 0xe74c3c, // red fields: [ { name: 'Event', value: event.name, inline: false }, { name: 'Originally Scheduled', value: `<t:${Math.floor(new Date(event.start).getTime() / 1000)}:F>` } ], footer: { text: 'Calendar System' } }; } await fetch(DISCORD_WEBHOOK_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username: 'Event Bot', embeds: [embed] }) }); } ``` Send Notification of New Event Created ```js // 🔔 Notify Discord await sendDiscordEventNotification('created', event); ``` Send Notification of Event Canceld ```js // 🔔 Notify Discord await sendDiscordEventNotification('cancelled', event); ``` I am not sure exactly how this would best implement into the code but would be good to handle until Discord Bot can be built to "Sync" events. New event created in calendar Creates discord event / event in discord creates calendar event. (Not even sure if we want this)
EagleTrooper added the Kind/FeatureKind/Enhancement
Priority
Medium
Calendar
labels 2025-12-13 01:09:51 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: 17th-Ranger-Battalion-ORG/milsim-site-v4#72