Skip to main content
← All Guides
beginner 15 min 200 XP

Set Up Ticket Notifications in Slack

Create a webhook endpoint that sends a Slack message whenever a new ticket is created. Covers webhook setup, signature verification, and Slack formatting.

Prerequisites

  • A cStar account with a secret API key
  • A Slack workspace with a webhook URL
1

Create a webhook endpoint

Register a webhook endpoint that listens for ticket.created events.

setup.js
import { CStarClient } from '@cstar.help/js';

const cstar = new CStarClient({
  apiKey: process.env.CSTAR_SECRET_KEY,
  teamId: process.env.CSTAR_TEAM_ID,
});

const { data: webhook } = await cstar.webhooks.create({
  name: 'Slack Notifications',
  url: 'https://your-server.com/api/cstar-webhook',
  events: ['ticket.created'],
});

console.log('Webhook ID:', webhook.id);
console.log('Signing secret:', webhook.secret);
2

Build the webhook handler

Create an endpoint on your server that receives webhook events and verifies the signature.

api/cstar-webhook.js
import { constructEvent } from '@cstar.help/js/webhook';

export async function POST(request) {
  const rawBody = await request.text();
  const signature = request.headers.get('x-cstar-signature');
  const secret = process.env.CSTAR_WEBHOOK_SECRET;

  // Verify the webhook came from cStar
  const event = constructEvent(rawBody, signature, secret);

  if (event.type === 'ticket.created') {
    const ticket = event.data;
    await sendSlackMessage(ticket);
  }

  return new Response('OK', { status: 200 });
}
3

Send the Slack message

Format the ticket data and post it to your Slack webhook.

api/cstar-webhook.js
async function sendSlackMessage(ticket) {
  const priorityEmoji = {
    urgent: ':rotating_light:',
    high: ':fire:',
    normal: ':ticket:',
    low: ':information_source:',
  };

  await fetch(process.env.SLACK_WEBHOOK_URL, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      text: `${priorityEmoji[ticket.priority] || ':ticket:'} New ticket: *${ticket.title}*`,
      blocks: [
        {
          type: 'section',
          text: {
            type: 'mrkdwn',
            text: `*${ticket.title}*\nPriority: ${ticket.priority} | Customer: ${ticket.customerName || 'Unknown'}\n<${ticket.dashboardUrl}|View in cStar>`,
          },
        },
      ],
    }),
  });
}
4

Test it

Use the CLI to fire a test event and verify your Slack message appears.

# Fire a test webhook event
cstar trigger ticket.created

# Or create a real ticket via the API
cstar seed --count 1

What's Next?