fix: challenge
This commit is contained in:
@ -21,6 +21,23 @@ type TwitchSubscribeBody = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const twitchChallengeEvent = z.object({
|
||||||
|
challenge: z.string(),
|
||||||
|
subscription: z.object({
|
||||||
|
id: z.string(),
|
||||||
|
status: z.enum(['webhook_callback_verification_pending']),
|
||||||
|
type: z.enum(['channel.subscribe']),
|
||||||
|
version: z.string(),
|
||||||
|
condition: z.object({ broadcaster_user_id: z.string() }),
|
||||||
|
transport: z.object({
|
||||||
|
method: z.enum(['webhook']),
|
||||||
|
callback: z.string(),
|
||||||
|
}),
|
||||||
|
created_at: z.string(),
|
||||||
|
cost: z.number(),
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
// Not the complete event, but the information we need.
|
// Not the complete event, but the information we need.
|
||||||
export const twitchFollowEvent = z.object({
|
export const twitchFollowEvent = z.object({
|
||||||
subscription: z.object({
|
subscription: z.object({
|
||||||
@ -31,6 +48,8 @@ export const twitchFollowEvent = z.object({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const twitchEvent = z.union([twitchFollowEvent, twitchChallengeEvent]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*curl -X POST 'https://api.twitch.tv/helix/eventsub/subscriptions' \
|
*curl -X POST 'https://api.twitch.tv/helix/eventsub/subscriptions' \
|
||||||
-H 'Authorization: Bearer 2gbdx6oar67tqtcmt49t3wpcgycthx' \
|
-H 'Authorization: Bearer 2gbdx6oar67tqtcmt49t3wpcgycthx' \
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { createHmac, timingSafeEqual } from "node:crypto";
|
import { createHmac, timingSafeEqual } from "node:crypto";
|
||||||
import type { RequestHandler } from "@sveltejs/kit";
|
import type { RequestHandler } from "@sveltejs/kit";
|
||||||
import { HASH_SECRET } from "$env/static/private";
|
import { HASH_SECRET } from "$env/static/private";
|
||||||
import { twitchFollowEvent } from "$lib/twitch";
|
import { twitchChallengeEvent, twitchFollowEvent } from "$lib/twitch";
|
||||||
import { client } from "$lib";
|
import { client } from "$lib";
|
||||||
const getHmacMessage = (request: Request, body: string): string => {
|
const getHmacMessage = (request: Request, body: string): string => {
|
||||||
return (
|
return (
|
||||||
@ -42,9 +42,13 @@ export const fallback: RequestHandler = async ({ request }) => {
|
|||||||
console.log(jsonBody);
|
console.log(jsonBody);
|
||||||
const event = twitchFollowEvent.safeParse(jsonBody);
|
const event = twitchFollowEvent.safeParse(jsonBody);
|
||||||
if (!event.success) {
|
if (!event.success) {
|
||||||
console.log("Not a follow event");
|
const stuff = twitchChallengeEvent.safeParse(jsonBody);
|
||||||
console.log(event.error);
|
if (!stuff.success) {
|
||||||
return new Response();
|
console.log("unknown event!!");
|
||||||
|
return new Response();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(stuff.data.challenge);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { user_name } = event.data.event;
|
const { user_name } = event.data.event;
|
||||||
|
Reference in New Issue
Block a user