Skip to main content

Recipe Library Overview

Pre-built webhook integration patterns for common use cases. Each recipe includes complete code examples and deployment instructions.

Recipe: Slack Notification Bot

Send real-time Slack notifications when users complete challenges or earn rewards.

Prerequisites

  • Slack workspace with incoming webhooks enabled
  • Slack webhook URL from your workspace settings

Configuration

  1. Get your Slack webhook URL from Slack App settings
  2. Configure Nudj webhook to point to your handler
  3. Deploy the handler code below

Recipe: Email Notification System

Send personalized emails for important user events using SendGrid.

Prerequisites

  • SendGrid account and API key
  • Email templates configured in SendGrid
  • Verified sender domain

Email Templates Needed

  • Challenge completion
  • Reward earned
  • Achievement unlocked
  • Weekly summary

Recipe: Analytics & Data Pipeline

Stream events to your data warehouse for analytics.

Prerequisites

  • Data warehouse (BigQuery, Snowflake, Redshift)
  • Message queue (optional but recommended)

Architecture

  1. Webhook receives events
  2. Events queued for processing
  3. Batch insert to data warehouse
  4. Analytics dashboards update

Recipe: Zapier/Make.com Integration

Connect Nudj webhooks to 1000+ apps without code.

Creating a Zap

  1. Trigger Setup
    • Choose “Webhooks by Zapier” as trigger
    • Select “Catch Hook” as event
    • Copy the webhook URL provided
  2. Configure Nudj Webhook
    {
      "url": "https://hooks.zapier.com/hooks/catch/YOUR_ID/",
      "events": ["challenge-completion", "reward-distribution"],
      "httpMethod": "POST",
      "isEnabled": true
    }
    
  3. Test & Map Fields
    • Send test webhook from Nudj
    • Map fields to your action apps
    • Common actions:
      • Add row to Google Sheets
      • Create Salesforce lead
      • Send Teams message
      • Create Asana task

Recipe: Database Sync

Keep your database synchronized with Nudj events.
const express = require('express');
const { Pool } = require('pg');
const app = express();

const pool = new Pool({
  connectionString: process.env.DATABASE_URL
});

const WEBHOOK_SECRET = process.env.WEBHOOK_SECRET;

// Create events table if not exists
async function initDatabase() {
  await pool.query(`
    CREATE TABLE IF NOT EXISTS nudj_events (
      id VARCHAR(255) PRIMARY KEY,
      event_category VARCHAR(100),
      event_subcategory VARCHAR(100),
      organisation_id VARCHAR(255),
      community_id VARCHAR(255),
      user_id VARCHAR(255),
      event_source_id VARCHAR(255),
      payload JSONB,
      tags TEXT[],
      created_at TIMESTAMP,
      received_at TIMESTAMP DEFAULT NOW()
    )
  `);
  
  // Create user points table
  await pool.query(`
    CREATE TABLE IF NOT EXISTS user_points (
      user_id VARCHAR(255) PRIMARY KEY,
      total_points INTEGER DEFAULT 0,
      total_xp INTEGER DEFAULT 0,
      last_updated TIMESTAMP DEFAULT NOW()
    )
  `);
}

app.post('/webhooks/nudj', express.json(), async (req, res) => {
  if (req.headers['x-api-key'] !== WEBHOOK_SECRET) {
    return res.status(401).json({ error: 'Unauthorized' });
  }

  const event = req.body;
  
  try {
    // Store raw event
    await pool.query(
      `INSERT INTO nudj_events 
       (id, event_category, event_subcategory, organisation_id, 
        community_id, user_id, event_source_id, payload, tags, created_at)
       VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
       ON CONFLICT (id) DO NOTHING`,
      [
        event.id,
        event.eventCategory,
        event.eventSubCategory,
        event.organisationId,
        event.communityId,
        event.userId,
        event.eventSourceId,
        JSON.stringify(event.payload),
        event.tags,
        event.createdAt
      ]
    );
    
    // Update user points for reward events
    if (event.eventSubCategory === 'reward-distribution') {
      const { earnedPoints = 0, earnedXp = 0 } = event.payload;
      await pool.query(
        `INSERT INTO user_points (user_id, total_points, total_xp)
         VALUES ($1, $2, $3)
         ON CONFLICT (user_id) 
         DO UPDATE SET 
           total_points = user_points.total_points + $2,
           total_xp = user_points.total_xp + $3,
           last_updated = NOW()`,
        [event.userId, earnedPoints, earnedXp]
      );
    }
    
    res.status(200).json({ success: true });
  } catch (error) {
    console.error('Database error:', error);
    res.status(500).json({ error: 'Internal error' });
  }
});

initDatabase().then(() => {
  app.listen(3000, () => {
    console.log('Database sync webhook running on port 3000');
  });
});

Deployment Options

Serverless Deployment

// api/webhooks/nudj.js
export default async function handler(req, res) {
  if (req.method !== 'POST') {
    return res.status(405).json({ error: 'Method not allowed' });
  }
  
  if (req.headers['x-api-key'] !== process.env.WEBHOOK_SECRET) {
    return res.status(401).json({ error: 'Unauthorized' });
  }
  
  const event = req.body;
  
  // Process webhook
  await processWebhook(event);
  
  res.status(200).json({ success: true });
}