Replit prompt

Replit: Discord Webhook Notifier

Send formatted Discord notifications from any trigger with embedded content, colors, and field formatting.

Build a Discord webhook notification system for {{project_name}}.

## Discord webhook URL: Set as DISCORD_WEBHOOK_URL environment variable
## Notification types: {{notification_types}}
## Triggered by: {{trigger}}

### Notification System

**Core Sender (webhook.js)**
```javascript
async function sendDiscordMessage(embed) {
  const response = await fetch(process.env.DISCORD_WEBHOOK_URL, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ embeds: [embed] })
  });
  if (!response.ok) throw new Error(`Discord webhook failed: ${response.status}`);
  return response;
}
```

**Embed Builder**
Color codes by type: Success (green: 0x00ff00), Error (red: 0xff0000), Warning (yellow: 0xffff00), Info (blue: 0x0000ff).

```javascript
function buildEmbed({ type, title, description, fields, footer }) {
  const colors = { success: 0x00ff00, error: 0xff0000, warning: 0xffff00, info: 0x0099ff };
  return {
    title,
    description,
    color: colors[type] || colors.info,
    fields: fields?.map(f => ({ name: f.label, value: String(f.value), inline: f.inline ?? true })),
    footer: footer ? { text: footer } : undefined,
    timestamp: new Date().toISOString()
  };
}
```

**Notification Templates for {{notification_types}}**
For each notification type: function with relevant parameters, proper formatting.

**Rate Limiting**
Discord limit: 5 messages per 2 seconds per webhook.
Queue messages if sending in bulk.
Respect 429 responses with retry-after.

**Testing**
Test script: send one of each notification type and verify they appear correctly.

Fill in: {{project_name}}, {{notification_types}}, {{trigger}}. In Loopy you fill these in a form and copy the finished prompt in one click.