Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: include shoutout eventsub that is currently in beta #888

Merged
merged 2 commits into from
Jan 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions functions/src/eventsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ enum EventsubType {
ChannelUpdate = "channel.update",
StreamOnline = "stream.online",
StreamOffline = "stream.offline",
ChannelShoutoutCreate = "channel.shoutout.create",
ChannelShoutoutReceive = "channel.shoutout.receive",
}

function createEventsub(token: string, type: string, twitchUserId: string) {
const condition =
type == "channel.raid"
? { to_broadcaster_user_id: twitchUserId }
: { broadcaster_user_id: twitchUserId };
const version =
type === "channel.shoutout.create" || type === "channel.shoutout.receive"
? "beta"
: "1";
return fetch("https://api.twitch.tv/helix/eventsub/subscriptions", {
method: "POST",
headers: {
Expand All @@ -52,7 +58,7 @@ function createEventsub(token: string, type: string, twitchUserId: string) {
},
body: JSON.stringify({
type,
version: "1",
version: version,
condition,
transport: {
method: "webhook",
Expand Down Expand Up @@ -136,7 +142,9 @@ export const eventsub = functions.https.onRequest(async (req, res) => {
channelId,
type,
timestamp: admin.firestore.Timestamp.fromMillis(Date.parse(timestamp)),
expiresAt: admin.firestore.Timestamp.fromMillis(Date.now() + 1000 * 86400 * 7 * 2),
expiresAt: admin.firestore.Timestamp.fromMillis(
Date.now() + 1000 * 86400 * 7 * 2
),
event: req.body.event,
});

Expand Down