environment-setup-guide
Guide developers through setting up development environments with proper tools, dependencies, and configurations
speak-webhooks-events
Implement Speak webhook signature validation and event handling for language learning. Use when setting up webhook endpoints, implementing signature verification, or handling Speak event notifications for lessons and progress. Trigger with phrases like "speak webhook", "speak events", "speak webh...
Full skill instructions
Securely handle Speak webhooks with signature validation for language learning event notifications.
| Event | Description | Payload |
|---|---|---|
lesson.started | User started a lesson | sessionId, userId, topic |
lesson.completed | User completed a lesson | sessionId, summary, score |
lesson.abandoned | User abandoned mid-lesson | sessionId, progress, reason |
pronunciation.milestone | Score threshold reached | userId, language, score |
streak.achieved | Learning streak milestone | userId, streakDays |
level.up | User advanced a level | userId, language, newLevel |
subscription.changed | Plan changed | userId, plan, action |
import express from 'express';
import crypto from 'crypto';
const app = express();
// IMPORTANT: Raw body needed for signature verification
app.post('/webhooks/speak',
express.raw({ type: 'application/json' }),
async (req, res) => {
const signature = req.headers['x-speak-signature'] as string;
const timestamp = req.headers['x-speak-timestamp'] as string;
const eventId = req.headers['x-speak-event-id'] as string;
// Verify signature
if (!verifySpeakSignature(req.body, signature, timestamp)) {
console.error('Invalid webhook signature', { eventId });
return res.status(401).json({ error: 'Invalid signature' });
}
// Check for duplicate (idempotency)
if (await isEventProcessed(eventId)) {
return res.status(200).json({ received: true, duplicate: true });
}
const event = JSON.parse(req.body.toString());
try {
await handleSpeakEvent(event);
await markEventProcessed(eventId);
res.status(200).json({ received: true });
} catch (error) {
console.error('Webhook processing failed', { eventId, error });
// Return 500 to trigger Speak retry
res.status(500).json({ error: 'Processing failed' });
}
}
);
function verifySpeakSignature(
payload: Buffer,
signature: string,
timestamp: string
): boolean {
const secret = process.env.SPEAK_WEBHOOK_SECRET!;
// Reject old timestamps (replay attack protection)
const timestampAge = Date.now() - parseInt(timestamp) * 1000;
if (timestampAge > 300000) { // 5 minutes
console.error('Webhook timestamp too old', { age: timestampAge });
return false;
}
// Reject future timestamps
if (timestampAge < -60000) { // 1 minute tolerance
console.error('Webhook timestamp in future');
return false;
}
// Compute expected signature
const signedPayload = `${timestamp}.${payload.toString()}`;
const expectedSignature = crypto
.createHmac('sha256', secret)
.update(signedPayload)
.digest('hex');
// Timing-safe comparison
try {
return crypto.timingSafeEqual(
Buffer.from(signature.replace('sha256=', '')),
Buffer.from(expectedSignature)
);
} catch {
return false;
}
}
type SpeakEventType =
| 'lesson.started'
| 'lesson.completed'
| 'lesson.abandoned'
| 'pronunciation.milestone'
| 'streak.achieved'
| 'level.up'
| 'subscription.changed';
interface SpeakEvent {
id: string;
type: SpeakEventType;
data: Record<string, any>;
userId: string;
createdAt: string;
}
// Type-safe event handlers
interface LessonCompletedData {
sessionId: string;
topic: string;
language: string;
duration: number;
averagePronunciationScore: number;
vocabularyLearned: number;
grammarPatternsUsed: string[];
}
interface StreakAchievedData {
streakDays: number;
totalLessons: number;
milestone: number;
}
const eventHandlers: Record<SpeakEventType, (data: any, userId: string) => Promise<void>> = {
'lesson.started': async (data, userId) => {
console.log(`User ${userId} started lesson: ${data.topic}`);
await analytics.track('lesson_started', { userId, ...data });
},
'lesson.completed': async (data: LessonCompletedData, userId) => {
console.log(`User ${userId} completed lesson: ${data.topic}`);
// Update user progress
await db.users.update(userId, {
totalLessons: { $inc: 1 },
vocabularyCount: { $inc: data.vocabularyLearned },
lastLessonAt: new Date(),
});
// Award XP
const xp = calculateXP(data);
await gamification.awardXP(userId, xp);
// Send completion notification
await notifications.send(userId, {
type: 'lesson_complete',
title: 'Lesson Complete!',
body: `Great job! You scored ${data.averagePronunciationScore}%`,
});
await analytics.track('lesson_completed', { userId, ...data });
},
'lesson.abandoned': async (data, userId) => {
console.log(`User ${userId} abandoned lesson at ${data.progress}%`);
// Track for engagement analysis
await analytics.track('lesson_abandoned', { userId, ...data });
// Maybe send re-engagement notification later
await scheduler.schedule('re_engagement', {
userId,
delayHours: 24,
});
},
'pronunciation.milestone': async (data, userId) => {
console.log(`User ${userId} reached pronunciation milestone: ${data.score}`);
await gamification.awardBadge(userId, `pronunciation_${data.score}`);
await notifications.send(userId, {
type: 'achievement',
title: 'Pronunciation Milestone!',
body: `You've reached ${data.score}% pronunciation accuracy!`,
});
},
'streak.achieved': async (data: StreakAchievedData, userId) => {
console.log(`User ${userId} achieved ${data.streakDays} day streak`);
await gamification.awardBadge(userId, `streak_${data.milestone}`);
// Special rewards for milestone streaks
if ([7, 30, 100, 365].includes(data.milestone)) {
await rewards.grantStreakReward(userId, data.milestone);
}
},
'level.up': async (data, userId) => {
console.log(`User ${userId} leveled up to ${data.newLevel} in ${data.language}`);
await db.users.update(userId, {
[`levels.${data.language}`]: data.newLevel,
});
await gamification.awardBadge(userId, `level_${data.language}_${data.newLevel}`);
},
'subscription.changed': async (data, userId) => {
console.log(`User ${userId} subscription: ${data.action}`);
await db.users.update(userId, {
subscriptionPlan: data.plan,
subscriptionStatus: data.action === 'cancelled' ? 'cancelled' : 'active',
});
await analytics.track('subscription_changed', { userId, ...data });
},
};
async function handleSpeakEvent(event: SpeakEvent): Promise<void> {
const handler = eventHandlers[event.type];
if (!handler) {
console.log(`Unhandled event type: ${event.type}`);
return;
}
try {
await handler(event.data, event.userId);
console.log(`Processed ${event.type}: ${event.id}`);
} catch (error) {
console.error(`Failed to process ${event.type}: ${event.id}`, error);
throw error; // Rethrow to trigger retry
}
}
import { Redis } from 'ioredis';
const redis = new Redis(process.env.REDIS_URL);
async function isEventProcessed(eventId: string): Promise<boolean> {
const key = `speak:event:${eventId}`;
const exists = await redis.exists(key);
return exists === 1;
}
async function markEventProcessed(eventId: string): Promise<void> {
const key = `speak:event:${eventId}`;
// Keep for 7 days to handle delayed retries
await redis.set(key, '1', 'EX', 86400 * 7);
}
# Use Speak CLI to send test events
speak webhooks trigger lesson.completed \
--url http://localhost:3000/webhooks/speak \
--data '{"sessionId":"sess_123","topic":"greetings","score":85}'
# Test with signature
TIMESTAMP=$(date +%s)
PAYLOAD='{"type":"lesson.completed","data":{"score":85}}'
SIGNATURE=$(echo -n "${TIMESTAMP}.${PAYLOAD}" | openssl dgst -sha256 -hmac "$SPEAK_WEBHOOK_SECRET" | cut -d' ' -f2)
curl -X POST http://localhost:3000/webhooks/speak \
-H "Content-Type: application/json" \
-H "X-Speak-Signature: sha256=${SIGNATURE}" \
-H "X-Speak-Timestamp: ${TIMESTAMP}" \
-H "X-Speak-Event-Id: test_$(uuidgen)" \
-d "${PAYLOAD}"
# Expose local server
ngrok http 3000
# Register webhook URL in Speak dashboard
# URL: https://your-ngrok-url.ngrok.io/webhooks/speak
# Test events will now hit your local server
| Issue | Cause | Solution |
|---|---|---|
| Invalid signature | Wrong secret | Verify webhook secret |
| Timestamp rejected | Clock drift | Check server time sync |
| Duplicate events | Missing idempotency | Implement event ID tracking |
| Handler timeout | Slow processing | Use async queue |
| Event not recognized | New event type | Add handler or log |
For performance optimization, see speak-performance-tuning.
Guide developers through setting up development environments with proper tools, dependencies, and configurations
Implement Exa lint rules, policy enforcement, and automated guardrails. Use when setting up code quality rules for Exa integrations, implementing pre-commit hooks, or configuring CI policy checks for Exa best practices. Trigger with phrases like "exa policy", "exa lint", "exa guardrails", "exa be...
Configure CI/CD pipelines for Documenso integrations. Use when setting up automated testing, deployment pipelines, or continuous integration for Documenso projects. Trigger with phrases like "documenso CI", "documenso GitHub Actions", "documenso pipeline", "documenso automated testing".
Build check model availability and implement fallback chains. Use when building resilient systems or handling model outages. Trigger with phrases like 'openrouter availability', 'openrouter fallback', 'openrouter model down', 'openrouter health check'.
Configure Langfuse enterprise organization management and access control. Use when implementing team access controls, configuring organization settings, or setting up role-based permissions for Langfuse projects. Trigger with phrases like "langfuse RBAC", "langfuse teams", "langfuse organization"...
Execute compliance and security auditing for Cursor usage. Triggers on "cursor compliance", "cursor audit", "cursor security review", "cursor soc2", "cursor gdpr". Use when analyzing or auditing cursor compliance audit. Trigger with phrases like "cursor compliance audit", "cursor audit", "cursor".
Configure Apollo.io CI/CD integration. Use when setting up automated testing, continuous integration, or deployment pipelines for Apollo integrations. Trigger with phrases like "apollo ci", "apollo github actions", "apollo pipeline", "apollo ci/cd", "apollo automated tests".
Create robust Python automation with full logging and safety checks. Use when tasks need complex data processing, authenticated API work, conditional file operations, or error handling beyond simple shell commands.
Configure PostHog across development, staging, and production environments. Use when setting up multi-environment deployments, configuring per-environment secrets, or implementing environment-specific PostHog configurations. Trigger with phrases like "posthog environments", "posthog staging", "po...
Expert in designing and building autonomous AI agents. Masters tool use, memory systems, planning strategies, and multi-agent orchestration. Use when: build agent, AI agent, autonomous agent, tool use, function calling.
Validate insecure deserialization checker operations. Auto-activating skill for Security Fundamentals. Triggers on: insecure deserialization checker, insecure deserialization checker Part of the Security Fundamentals skill category. Use when working with insecure deserialization checker functiona...
Manage path traversal finder operations. Auto-activating skill for Security Fundamentals. Triggers on: path traversal finder, path traversal finder Part of the Security Fundamentals skill category. Use when working with path traversal finder functionality. Trigger with phrases like "path traversa...
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience