@overlaysymphony/twitch 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/authentication/authentication.ts +1 -1
- package/src/authentication/index.ts +1 -1
- package/src/chat/chat.ts +4 -4
- package/src/chat/helpers.ts +1 -1
- package/src/chat/index.ts +4 -3
- package/src/chat/interfaces/index.ts +2 -2
- package/src/chat/parser.ts +1 -1
- package/src/eventsub/events/automod.message.hold-2.ts +81 -0
- package/src/eventsub/events/automod.message.update-2.ts +94 -0
- package/src/eventsub/events/automod.settings.update-1.ts +65 -0
- package/src/eventsub/events/automod.terms.update-1.ts +59 -0
- package/src/eventsub/events/channel.ad_break.begin-1.ts +50 -0
- package/src/eventsub/events/channel.ban-1.ts +58 -0
- package/src/eventsub/events/channel.bits.use-1.ts +112 -0
- package/src/eventsub/events/channel.channel_points_automatic_reward_redemption.add-2.ts +88 -0
- package/src/eventsub/events/channel.channel_points_custom_reward.add-1.ts +101 -0
- package/src/eventsub/events/channel.channel_points_custom_reward.remove-1.ts +103 -0
- package/src/eventsub/events/channel.channel_points_custom_reward.update-1.ts +103 -0
- package/src/eventsub/events/channel.channel_points_custom_reward_redemption.add-1.ts +65 -0
- package/src/eventsub/events/channel.channel_points_custom_reward_redemption.update-1.ts +65 -0
- package/src/eventsub/events/channel.charity_campaign.donate-1.ts +69 -0
- package/src/eventsub/events/channel.charity_campaign.progress-1.ts +74 -0
- package/src/eventsub/events/channel.charity_campaign.start-1.ts +76 -0
- package/src/eventsub/events/channel.charity_campaign.stop-1.ts +76 -0
- package/src/eventsub/events/channel.chat.clear-1.ts +41 -0
- package/src/eventsub/events/channel.chat.clear_user_messages-1.ts +47 -0
- package/src/eventsub/events/channel.chat.message-1.ts +160 -0
- package/src/eventsub/events/channel.chat.message_delete-1.ts +49 -0
- package/src/eventsub/events/channel.chat.notification-1.ts +317 -0
- package/src/eventsub/events/channel.chat.user_message_hold-1.ts +75 -0
- package/src/eventsub/events/channel.chat.user_message_update-1.ts +82 -0
- package/src/eventsub/events/channel.chat_settings.update-1.ts +83 -0
- package/src/eventsub/events/channel.cheer-1.ts +50 -0
- package/src/eventsub/events/channel.follow-2.ts +49 -0
- package/src/eventsub/events/channel.goal.begin-1.ts +80 -0
- package/src/eventsub/events/channel.goal.end-1.ts +80 -0
- package/src/eventsub/events/channel.goal.progress-1.ts +80 -0
- package/src/eventsub/events/channel.guest_star_guest.update-beta.ts +85 -0
- package/src/eventsub/events/channel.guest_star_session.begin-beta.ts +50 -0
- package/src/eventsub/events/channel.guest_star_session.end-beta.ts +58 -0
- package/src/eventsub/events/channel.guest_star_settings.update-beta.ts +62 -0
- package/src/eventsub/events/channel.hype_train.begin-2.ts +90 -0
- package/src/eventsub/events/channel.hype_train.end-2.ts +70 -0
- package/src/eventsub/events/channel.hype_train.progress-2.ts +90 -0
- package/src/eventsub/events/channel.moderate-2.ts +258 -0
- package/src/eventsub/events/channel.moderator.add-1.ts +44 -0
- package/src/eventsub/events/channel.moderator.remove-1.ts +44 -0
- package/src/eventsub/events/channel.poll.begin-1.ts +73 -0
- package/src/eventsub/events/channel.poll.end-1.ts +75 -0
- package/src/eventsub/events/channel.poll.progress-1.ts +73 -0
- package/src/eventsub/events/channel.prediction.begin-1.ts +72 -0
- package/src/eventsub/events/channel.prediction.end-1.ts +76 -0
- package/src/eventsub/events/channel.prediction.lock-1.ts +72 -0
- package/src/eventsub/events/channel.prediction.progress-1.ts +72 -0
- package/src/eventsub/events/channel.raid-1.ts +48 -0
- package/src/eventsub/events/channel.shared_chat.begin-1.ts +55 -0
- package/src/eventsub/events/channel.shared_chat.end-1.ts +46 -0
- package/src/eventsub/events/channel.shared_chat.update-1.ts +55 -0
- package/src/eventsub/events/channel.shield_mode.begin-1.ts +51 -0
- package/src/eventsub/events/channel.shield_mode.end-1.ts +51 -0
- package/src/eventsub/events/channel.shoutout.create-1.ts +61 -0
- package/src/eventsub/events/channel.shoutout.receive-1.ts +51 -0
- package/src/eventsub/events/channel.subscribe-1.ts +48 -0
- package/src/eventsub/events/channel.subscription.end-1.ts +48 -0
- package/src/eventsub/events/channel.subscription.gift-1.ts +52 -0
- package/src/eventsub/events/channel.subscription.message-1.ts +66 -0
- package/src/eventsub/events/channel.suspicious_user.message-1.ts +85 -0
- package/src/eventsub/events/channel.suspicious_user.update-1.ts +55 -0
- package/src/eventsub/events/channel.unban-1.ts +50 -0
- package/src/eventsub/events/channel.unban_request.create-1.ts +53 -0
- package/src/eventsub/events/channel.unban_request.resolve-1.ts +64 -0
- package/src/eventsub/events/channel.update-2.ts +48 -0
- package/src/eventsub/events/channel.vip.add-1.ts +44 -0
- package/src/eventsub/events/channel.vip.remove-1.ts +44 -0
- package/src/eventsub/events/channel.warning.acknowledge-1.ts +47 -0
- package/src/eventsub/events/channel.warning.send-1.ts +57 -0
- package/src/eventsub/events/index.ts +73 -284
- package/src/eventsub/events/stream.offline-1.ts +38 -0
- package/src/eventsub/events/stream.online-1.ts +44 -0
- package/src/eventsub/events/user.update-1.ts +48 -0
- package/src/eventsub/events/user.whisper.message-1.ts +51 -0
- package/src/eventsub/events-helpers.ts +53 -25
- package/src/eventsub/eventsub.ts +37 -74
- package/src/eventsub/index.ts +8 -6
- package/src/eventsub/messages.ts +16 -4
- package/src/helix/channel-points/custom-rewards.ts +3 -3
- package/src/helix/channel-points/index.ts +1 -1
- package/src/helix/helix.ts +1 -1
- package/src/helix/subscriptions/index.ts +1 -1
- package/src/helix/subscriptions/subscriptions.ts +40 -47
- package/src/helix/users/index.ts +1 -1
- package/src/helix/users/users.ts +3 -3
- package/src/helpers/alerts/alerts.ts +5 -5
- package/src/helpers/alerts/index.ts +2 -2
- package/src/helpers/charity/charity.ts +2 -2
- package/src/helpers/charity/index.ts +1 -1
- package/src/helpers/goal/goal.ts +2 -2
- package/src/helpers/goal/index.ts +1 -1
- package/src/helpers/hype-train/hype-train.ts +2 -2
- package/src/helpers/hype-train/index.ts +1 -1
- package/src/helpers/poll/index.ts +1 -1
- package/src/helpers/poll/poll.ts +3 -3
- package/src/helpers/prediction/index.ts +1 -1
- package/src/helpers/prediction/prediction.ts +3 -3
- package/src/helpers/redemption/index.ts +1 -1
- package/src/helpers/redemption/redemption.ts +3 -3
- package/src/helpers/status/index.ts +1 -1
- package/src/helpers/status/status.ts +2 -2
- package/src/ui/authentication.ts +1 -1
- package/src/ui/popup.ts +26 -3
- package/src/eventsub/events/channel.ad_break.begin.ts +0 -51
- package/src/eventsub/events/channel.ban.ts +0 -59
- package/src/eventsub/events/channel.channel_points_custom_reward._.ts +0 -29
- package/src/eventsub/events/channel.channel_points_custom_reward.add.ts +0 -75
- package/src/eventsub/events/channel.channel_points_custom_reward.remove.ts +0 -77
- package/src/eventsub/events/channel.channel_points_custom_reward.update.ts +0 -77
- package/src/eventsub/events/channel.channel_points_custom_reward_redemption._.ts +0 -10
- package/src/eventsub/events/channel.channel_points_custom_reward_redemption.add.ts +0 -59
- package/src/eventsub/events/channel.channel_points_custom_reward_redemption.update.ts +0 -59
- package/src/eventsub/events/channel.charity_campaign.donate.ts +0 -66
- package/src/eventsub/events/channel.charity_campaign.progress.ts +0 -67
- package/src/eventsub/events/channel.charity_campaign.start.ts +0 -69
- package/src/eventsub/events/channel.charity_campaign.stop.ts +0 -69
- package/src/eventsub/events/channel.chat.clear.ts +0 -42
- package/src/eventsub/events/channel.chat.clear_user_messages.ts +0 -48
- package/src/eventsub/events/channel.chat.message_delete.ts +0 -50
- package/src/eventsub/events/channel.chat.notification.ts +0 -50
- package/src/eventsub/events/channel.cheer.ts +0 -51
- package/src/eventsub/events/channel.follow.ts +0 -50
- package/src/eventsub/events/channel.goal.begin.ts +0 -51
- package/src/eventsub/events/channel.goal.end.ts +0 -55
- package/src/eventsub/events/channel.goal.progress.ts +0 -51
- package/src/eventsub/events/channel.guest_star_guest.update.ts +0 -66
- package/src/eventsub/events/channel.guest_star_session.begin.ts +0 -46
- package/src/eventsub/events/channel.guest_star_session.end.ts +0 -48
- package/src/eventsub/events/channel.guest_star_settings.update.ts +0 -50
- package/src/eventsub/events/channel.hype_train._.ts +0 -12
- package/src/eventsub/events/channel.hype_train.begin.ts +0 -57
- package/src/eventsub/events/channel.hype_train.end.ts +0 -55
- package/src/eventsub/events/channel.hype_train.progress.ts +0 -70
- package/src/eventsub/events/channel.moderator.add.ts +0 -45
- package/src/eventsub/events/channel.moderator.remove.ts +0 -45
- package/src/eventsub/events/channel.poll._.ts +0 -26
- package/src/eventsub/events/channel.poll.begin.ts +0 -55
- package/src/eventsub/events/channel.poll.end.ts +0 -57
- package/src/eventsub/events/channel.poll.progress.ts +0 -55
- package/src/eventsub/events/channel.prediction._.ts +0 -25
- package/src/eventsub/events/channel.prediction.begin.ts +0 -51
- package/src/eventsub/events/channel.prediction.end.ts +0 -55
- package/src/eventsub/events/channel.prediction.lock.ts +0 -51
- package/src/eventsub/events/channel.prediction.progress.ts +0 -51
- package/src/eventsub/events/channel.raid.ts +0 -49
- package/src/eventsub/events/channel.shield_mode.begin.ts +0 -50
- package/src/eventsub/events/channel.shield_mode.end.ts +0 -50
- package/src/eventsub/events/channel.shoutout.create.ts +0 -62
- package/src/eventsub/events/channel.shoutout.receive.ts +0 -52
- package/src/eventsub/events/channel.subscribe.ts +0 -49
- package/src/eventsub/events/channel.subscription.end.ts +0 -49
- package/src/eventsub/events/channel.subscription.gift.ts +0 -53
- package/src/eventsub/events/channel.subscription.message.ts +0 -67
- package/src/eventsub/events/channel.unban.ts +0 -51
- package/src/eventsub/events/channel.update.ts +0 -49
- package/src/eventsub/events/stream.offline.ts +0 -39
- package/src/eventsub/events/stream.online.ts +0 -45
- package/src/eventsub/events/user.update.ts +0 -45
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type EventConfig, registerEvent } from "../events-helpers.ts"
|
|
2
|
+
|
|
3
|
+
declare module "../events-helpers.ts" {
|
|
4
|
+
interface EventConfigs {
|
|
5
|
+
"user.whisper.message": UserWhisperMessage
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** User Whisper Message v1: When a user receives a whisper. */
|
|
10
|
+
type UserWhisperMessage = EventConfig<{
|
|
11
|
+
Type: "user.whisper.message"
|
|
12
|
+
Version: "1"
|
|
13
|
+
/** The conditions to listen for when a user receives a whisper. */
|
|
14
|
+
Condition: {
|
|
15
|
+
/** The user_id of the person receiving whispers. */
|
|
16
|
+
user_id: string
|
|
17
|
+
}
|
|
18
|
+
/** The event fired when a user receives a whisper. */
|
|
19
|
+
Event: {
|
|
20
|
+
/** The ID of the user sending the message. */
|
|
21
|
+
from_user_id: string
|
|
22
|
+
/** The name of the user sending the message. */
|
|
23
|
+
from_user_name: string
|
|
24
|
+
/** The login of the user sending the message. */
|
|
25
|
+
from_user_login: string
|
|
26
|
+
/** The ID of the user receiving the message. */
|
|
27
|
+
to_user_id: string
|
|
28
|
+
/** The name of the user receiving the message. */
|
|
29
|
+
to_user_name: string
|
|
30
|
+
/** The login of the user receiving the message. */
|
|
31
|
+
to_user_login: string
|
|
32
|
+
/** The whisper ID. */
|
|
33
|
+
whisper_id: string
|
|
34
|
+
/** Object containing whisper information. */
|
|
35
|
+
whisper: {
|
|
36
|
+
/** The body of the whisper message. */
|
|
37
|
+
text: string
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}>
|
|
41
|
+
|
|
42
|
+
registerEvent("user.whisper.message", {
|
|
43
|
+
scopes: ["user:manage:whispers", "user:read:whispers"],
|
|
44
|
+
subscriber: (userId) => ({
|
|
45
|
+
type: "user.whisper.message",
|
|
46
|
+
version: "1",
|
|
47
|
+
condition: {
|
|
48
|
+
user_id: userId,
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
})
|
|
@@ -1,29 +1,57 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Event,
|
|
14
|
-
> {
|
|
15
|
-
type: "notification"
|
|
16
|
-
metadata: {
|
|
17
|
-
message_id: string
|
|
18
|
-
message_type: "notification"
|
|
19
|
-
message_timestamp: Date
|
|
20
|
-
subscription_type: Subscription["type"]
|
|
21
|
-
subscription_version: Subscription["version"]
|
|
1
|
+
export type EventConfig<
|
|
2
|
+
Config extends {
|
|
3
|
+
Type: string
|
|
4
|
+
Version: string
|
|
5
|
+
Condition: {}
|
|
6
|
+
Event: {}
|
|
7
|
+
},
|
|
8
|
+
> = Config & {
|
|
9
|
+
Subscription: {
|
|
10
|
+
type: Config["Type"]
|
|
11
|
+
version: Config["Version"]
|
|
12
|
+
condition: Config["Condition"]
|
|
22
13
|
}
|
|
23
|
-
|
|
14
|
+
Payload: {
|
|
24
15
|
id: string
|
|
25
|
-
type:
|
|
26
|
-
subscription:
|
|
27
|
-
|
|
16
|
+
type: Config["Type"]
|
|
17
|
+
subscription: {
|
|
18
|
+
type: Config["Type"]
|
|
19
|
+
version: Config["Version"]
|
|
20
|
+
condition: Config["Condition"]
|
|
21
|
+
}
|
|
22
|
+
event: Config["Event"]
|
|
28
23
|
}
|
|
29
24
|
}
|
|
25
|
+
|
|
26
|
+
export interface EventConfigs {}
|
|
27
|
+
|
|
28
|
+
export type EventType = keyof EventConfigs
|
|
29
|
+
export type EventPayload<Type extends EventType = EventType> =
|
|
30
|
+
EventConfigs[Type]["Payload"]
|
|
31
|
+
|
|
32
|
+
const events: {
|
|
33
|
+
[Type in EventType]?: {
|
|
34
|
+
scopes: string[]
|
|
35
|
+
subscriber: (userId: string) => EventConfigs[Type]["Subscription"]
|
|
36
|
+
}
|
|
37
|
+
} = {}
|
|
38
|
+
|
|
39
|
+
export function registerEvent<Type extends EventType>(
|
|
40
|
+
type: Type,
|
|
41
|
+
config: {
|
|
42
|
+
scopes: string[]
|
|
43
|
+
subscriber: (userId: string) => EventConfigs[Type]["Subscription"]
|
|
44
|
+
},
|
|
45
|
+
): void {
|
|
46
|
+
// @ts-expect-error too complex for typescript
|
|
47
|
+
events[type] = config
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function buildSubscription<Type extends EventType>(
|
|
51
|
+
type: Type,
|
|
52
|
+
userId: string,
|
|
53
|
+
): EventConfigs[Type]["Subscription"] {
|
|
54
|
+
if (!events[type]) throw new Error(`Event ${type} is not registered.`)
|
|
55
|
+
|
|
56
|
+
return events[type].subscriber(userId)
|
|
57
|
+
}
|
package/src/eventsub/eventsub.ts
CHANGED
|
@@ -1,87 +1,50 @@
|
|
|
1
|
-
import
|
|
2
|
-
import createPubSub from "@overlaysymphony/core/libs/pubsub"
|
|
3
|
-
|
|
4
|
-
import { type Authentication } from "../authentication/index.js"
|
|
5
|
-
import { createSubscription } from "../helix/subscriptions/index.js"
|
|
1
|
+
import "./events/index.ts"
|
|
6
2
|
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
type TwitchSubscriptionType,
|
|
10
|
-
} from "./events/index.js"
|
|
11
|
-
import { type TwitchMessage } from "./messages.js"
|
|
3
|
+
import createDefer from "@overlaysymphony/core/libs/defer"
|
|
4
|
+
import createEvents, { type Events } from "@overlaysymphony/core/libs/events"
|
|
12
5
|
|
|
13
|
-
type
|
|
14
|
-
|
|
15
|
-
) => () => void
|
|
6
|
+
import { type Authentication } from "../authentication/index.ts"
|
|
7
|
+
import { createSubscription } from "../helix/subscriptions/index.ts"
|
|
16
8
|
|
|
17
|
-
type
|
|
18
|
-
|
|
19
|
-
Event extends TwitchNotificationMessage<EventType>["payload"],
|
|
20
|
-
>(
|
|
21
|
-
types: EventType[],
|
|
22
|
-
callback: (event: Event) => void,
|
|
23
|
-
) => () => void
|
|
9
|
+
import { type EventPayload, buildSubscription } from "./events-helpers.ts"
|
|
10
|
+
import { type TwitchMessage } from "./messages.ts"
|
|
24
11
|
|
|
25
|
-
export
|
|
26
|
-
listen: EventSubListener
|
|
27
|
-
subscribe: EventSubSubscriber
|
|
28
|
-
}
|
|
12
|
+
export type TwitchEventSub = Events<EventPayload>
|
|
29
13
|
|
|
30
|
-
export async function createEventSub(
|
|
14
|
+
export default async function createEventSub(
|
|
31
15
|
authentication: Authentication,
|
|
32
16
|
): Promise<TwitchEventSub> {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (data.type === "notification") {
|
|
48
|
-
data.payload.id = data.metadata.message_id
|
|
49
|
-
data.payload.type = data.payload.subscription.type
|
|
50
|
-
|
|
51
|
-
pubsub.dispatch(data.payload)
|
|
52
|
-
return
|
|
53
|
-
}
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
return promise.then((sessionId) => {
|
|
57
|
-
const subscriptions: Partial<Record<TwitchSubscriptionType, boolean>> = {}
|
|
58
|
-
|
|
59
|
-
const listen: EventSubListener = (callback) => {
|
|
60
|
-
return pubsub.subscribe((event) => {
|
|
61
|
-
callback(event)
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const subscribe: EventSubSubscriber = (types, callback) => {
|
|
66
|
-
for (const type of types) {
|
|
67
|
-
if (!subscriptions[type]) {
|
|
68
|
-
subscriptions[type] = true
|
|
69
|
-
void createSubscription(sessionId, authentication, type)
|
|
17
|
+
return createEvents<EventPayload, string>(
|
|
18
|
+
async (pubsub) => {
|
|
19
|
+
const socket = new WebSocket("wss://eventsub.wss.twitch.tv/ws")
|
|
20
|
+
|
|
21
|
+
const { promise, resolve } = createDefer<string>()
|
|
22
|
+
socket.addEventListener("message", ({ data: rawData }) => {
|
|
23
|
+
const data = JSON.parse(rawData as string) as TwitchMessage
|
|
24
|
+
data.type = data.metadata.message_type
|
|
25
|
+
|
|
26
|
+
if (data.type === "session_welcome") {
|
|
27
|
+
resolve(data.payload.session.id)
|
|
28
|
+
return
|
|
70
29
|
}
|
|
71
|
-
}
|
|
72
30
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
31
|
+
if (data.type === "notification") {
|
|
32
|
+
data.payload.id = data.metadata.message_id
|
|
33
|
+
data.payload.type = data.payload.subscription.type
|
|
34
|
+
|
|
35
|
+
pubsub.dispatch(data.payload)
|
|
36
|
+
return
|
|
78
37
|
}
|
|
79
38
|
})
|
|
80
|
-
}
|
|
81
39
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
40
|
+
return await promise
|
|
41
|
+
},
|
|
42
|
+
async (pubsub, sessionId, type) => {
|
|
43
|
+
await createSubscription(
|
|
44
|
+
authentication,
|
|
45
|
+
{ method: "websocket", session_id: sessionId },
|
|
46
|
+
buildSubscription(type, authentication.user.id),
|
|
47
|
+
)
|
|
48
|
+
},
|
|
49
|
+
)
|
|
87
50
|
}
|
package/src/eventsub/index.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export {
|
|
2
|
+
type EventConfig,
|
|
3
|
+
type EventConfigs,
|
|
4
|
+
type EventType,
|
|
5
|
+
registerEvent,
|
|
6
|
+
} from "./events-helpers.ts"
|
|
6
7
|
|
|
7
|
-
export
|
|
8
|
+
export { default } from "./eventsub.ts"
|
|
9
|
+
export * from "./eventsub.ts"
|
package/src/eventsub/messages.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type EventConfigs, type EventType } from "./events-helpers.ts"
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export type SessionWelcomeMessage = {
|
|
4
4
|
type: "session_welcome"
|
|
5
5
|
metadata: {
|
|
6
6
|
message_id: string
|
|
@@ -18,7 +18,7 @@ export interface SessionWelcomeMessage {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export
|
|
21
|
+
export type SessionKeepaliveMessage = {
|
|
22
22
|
type: "session_keepalive"
|
|
23
23
|
metadata: {
|
|
24
24
|
message_id: string
|
|
@@ -28,7 +28,19 @@ export interface SessionKeepaliveMessage {
|
|
|
28
28
|
payload: Record<string, never>
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
export type NotificationMessage<Type extends EventType = EventType> = {
|
|
32
|
+
type: "notification"
|
|
33
|
+
metadata: {
|
|
34
|
+
message_id: string
|
|
35
|
+
message_type: "notification"
|
|
36
|
+
message_timestamp: Date
|
|
37
|
+
subscription_type: EventConfigs[Type]["Type"]
|
|
38
|
+
subscription_version: EventConfigs[Type]["Version"]
|
|
39
|
+
}
|
|
40
|
+
payload: EventConfigs[Type]["Payload"]
|
|
41
|
+
}
|
|
42
|
+
|
|
31
43
|
export type TwitchMessage =
|
|
32
44
|
| SessionWelcomeMessage
|
|
33
45
|
| SessionKeepaliveMessage
|
|
34
|
-
|
|
|
46
|
+
| NotificationMessage
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type Authentication } from "../../authentication/index.
|
|
2
|
-
import { helix } from "../helix.
|
|
1
|
+
import { type Authentication } from "../../authentication/index.ts"
|
|
2
|
+
import { helix } from "../helix.ts"
|
|
3
3
|
|
|
4
4
|
interface CustomReward {
|
|
5
5
|
broadcaster_id: string
|
|
@@ -51,7 +51,7 @@ export async function getCustomRewards(
|
|
|
51
51
|
broadcaster_id: string
|
|
52
52
|
}
|
|
53
53
|
>(authentication, {
|
|
54
|
-
method: "
|
|
54
|
+
method: "GET",
|
|
55
55
|
path: "/channel_points/custom_rewards",
|
|
56
56
|
params: {
|
|
57
57
|
broadcaster_id: authentication.user.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./custom-rewards.
|
|
1
|
+
export * from "./custom-rewards.ts"
|
package/src/helix/helix.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./subscriptions.
|
|
1
|
+
export * from "./subscriptions.ts"
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { type Authentication } from "../../authentication/index.
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
buildSubscription,
|
|
6
|
-
} from "../../eventsub/events/index.js"
|
|
7
|
-
import { type BaseSubscription } from "../../eventsub/events-helpers.js"
|
|
8
|
-
import { helix } from "../helix.js"
|
|
1
|
+
import { type Authentication } from "../../authentication/index.ts"
|
|
2
|
+
import { type EventConfigs, type EventType } from "../../eventsub/index.ts"
|
|
3
|
+
|
|
4
|
+
import { helix } from "../helix.ts"
|
|
9
5
|
|
|
10
6
|
interface SubscriptionWebhookTransport {
|
|
11
7
|
method: "webhook"
|
|
@@ -22,15 +18,15 @@ type SubscriptionTransport =
|
|
|
22
18
|
| SubscriptionWebhookTransport
|
|
23
19
|
| SubscriptionWebsocketTransport
|
|
24
20
|
|
|
25
|
-
|
|
26
|
-
type:
|
|
27
|
-
version:
|
|
28
|
-
condition:
|
|
21
|
+
interface SubscriptionRequest<Type extends EventType> {
|
|
22
|
+
type: EventConfigs[Type]["Type"]
|
|
23
|
+
version: EventConfigs[Type]["Version"]
|
|
24
|
+
condition: EventConfigs[Type]["Condition"]
|
|
29
25
|
transport: SubscriptionTransport
|
|
30
26
|
}
|
|
31
27
|
|
|
32
|
-
|
|
33
|
-
Subscription & {
|
|
28
|
+
type ActiveSubscription<Type extends EventType> =
|
|
29
|
+
EventConfigs[Type]["Subscription"] & {
|
|
34
30
|
id: string
|
|
35
31
|
status:
|
|
36
32
|
| "enabled"
|
|
@@ -53,60 +49,57 @@ export type ActiveSubscription<Subscription extends BaseSubscription> =
|
|
|
53
49
|
transport: SubscriptionTransport
|
|
54
50
|
}
|
|
55
51
|
|
|
56
|
-
export async function createSubscription<
|
|
57
|
-
Type extends TwitchSubscriptionType,
|
|
58
|
-
Subscription extends TwitchSubscription<Type>,
|
|
59
|
-
>(
|
|
60
|
-
sessionId: string,
|
|
52
|
+
export async function createSubscription<Type extends EventType>(
|
|
61
53
|
authentication: Authentication,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
54
|
+
transport: SubscriptionTransport,
|
|
55
|
+
subscription: EventConfigs[Type]["Subscription"],
|
|
56
|
+
): Promise<ActiveSubscription<Type>> {
|
|
57
|
+
const [activeSubscription] = await helix<
|
|
58
|
+
ActiveSubscription<EventType>,
|
|
59
|
+
never,
|
|
60
|
+
never,
|
|
61
|
+
SubscriptionRequest<EventType>
|
|
62
|
+
>(authentication, {
|
|
63
|
+
method: "POST",
|
|
68
64
|
path: "/eventsub/subscriptions",
|
|
69
65
|
body: {
|
|
70
66
|
...subscription,
|
|
71
|
-
transport
|
|
72
|
-
method: "websocket" as const,
|
|
73
|
-
session_id: sessionId,
|
|
74
|
-
},
|
|
67
|
+
transport,
|
|
75
68
|
},
|
|
76
69
|
})
|
|
77
70
|
|
|
78
71
|
return activeSubscription
|
|
79
72
|
}
|
|
80
73
|
|
|
81
|
-
export async function deleteSubscription(
|
|
82
|
-
authentication: Authentication,
|
|
83
|
-
id: string,
|
|
84
|
-
): Promise<void> {
|
|
85
|
-
await helix<never, never, { id: string }>(authentication, {
|
|
86
|
-
method: "delete",
|
|
87
|
-
path: "/eventsub/subscriptions",
|
|
88
|
-
params: {
|
|
89
|
-
id,
|
|
90
|
-
},
|
|
91
|
-
})
|
|
92
|
-
}
|
|
93
|
-
|
|
94
74
|
export async function getSubscriptions(
|
|
95
75
|
authentication: Authentication,
|
|
96
|
-
): Promise<Array<ActiveSubscription<
|
|
76
|
+
): Promise<Array<ActiveSubscription<EventType>>> {
|
|
97
77
|
const subscriptions = await helix<
|
|
98
|
-
ActiveSubscription<
|
|
78
|
+
ActiveSubscription<EventType>,
|
|
99
79
|
never,
|
|
100
80
|
{
|
|
101
|
-
status?: ActiveSubscription<
|
|
102
|
-
type?:
|
|
81
|
+
status?: ActiveSubscription<EventType>["status"]
|
|
82
|
+
type?: EventType
|
|
103
83
|
user_id?: string
|
|
104
84
|
after?: string
|
|
105
85
|
}
|
|
106
86
|
>(authentication, {
|
|
107
|
-
method: "
|
|
87
|
+
method: "GET",
|
|
108
88
|
path: "/eventsub/subscriptions",
|
|
109
89
|
})
|
|
110
90
|
|
|
111
91
|
return subscriptions
|
|
112
92
|
}
|
|
93
|
+
|
|
94
|
+
export async function deleteSubscription(
|
|
95
|
+
authentication: Authentication,
|
|
96
|
+
id: string,
|
|
97
|
+
): Promise<void> {
|
|
98
|
+
await helix<never, never, { id: string }>(authentication, {
|
|
99
|
+
method: "DELETE",
|
|
100
|
+
path: "/eventsub/subscriptions",
|
|
101
|
+
params: {
|
|
102
|
+
id,
|
|
103
|
+
},
|
|
104
|
+
})
|
|
105
|
+
}
|
package/src/helix/users/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./users.
|
|
1
|
+
export * from "./users.ts"
|
package/src/helix/users/users.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type Authentication } from "../../authentication/index.
|
|
2
|
-
import { helix } from "../helix.
|
|
1
|
+
import { type Authentication } from "../../authentication/index.ts"
|
|
2
|
+
import { helix } from "../helix.ts"
|
|
3
3
|
|
|
4
4
|
export interface TwitchUser {
|
|
5
5
|
id: string
|
|
@@ -25,7 +25,7 @@ export async function getUsers(
|
|
|
25
25
|
const data = await helix<TwitchUser, RawUser>(
|
|
26
26
|
authentication,
|
|
27
27
|
{
|
|
28
|
-
method: "
|
|
28
|
+
method: "GET",
|
|
29
29
|
path: "/users",
|
|
30
30
|
params: {
|
|
31
31
|
id,
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import createQueue, { type Queue } from "@overlaysymphony/core/libs/queue"
|
|
2
2
|
|
|
3
|
-
import { type
|
|
4
|
-
import { type TwitchEventSub } from "../../eventsub/index.
|
|
3
|
+
import { type EventPayload } from "../../eventsub/events-helpers.ts"
|
|
4
|
+
import { type TwitchEventSub } from "../../eventsub/index.ts"
|
|
5
5
|
|
|
6
|
-
export type Alert =
|
|
6
|
+
export type Alert = EventPayload<
|
|
7
7
|
| "channel.cheer"
|
|
8
8
|
| "channel.follow"
|
|
9
9
|
| "channel.raid"
|
|
10
10
|
| "channel.subscribe"
|
|
11
11
|
| "channel.subscription.gift"
|
|
12
12
|
| "channel.subscription.message"
|
|
13
|
-
>
|
|
13
|
+
>
|
|
14
14
|
|
|
15
15
|
export const mapTypeToPriority = {
|
|
16
16
|
"channel.follow": 0,
|
|
@@ -25,7 +25,7 @@ export function onAlert(
|
|
|
25
25
|
eventsub: TwitchEventSub,
|
|
26
26
|
handleAlert: (alert: Alert) => void,
|
|
27
27
|
): void {
|
|
28
|
-
eventsub.
|
|
28
|
+
eventsub.on(
|
|
29
29
|
[
|
|
30
30
|
"channel.cheer",
|
|
31
31
|
"channel.follow",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "./alerts.
|
|
2
|
-
export * from "./alerts.
|
|
1
|
+
export { default } from "./alerts.ts"
|
|
2
|
+
export * from "./alerts.ts"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type TwitchEventSub } from "../../eventsub/index.
|
|
1
|
+
import { type TwitchEventSub } from "../../eventsub/index.ts"
|
|
2
2
|
|
|
3
3
|
export interface Charity {
|
|
4
4
|
name: string
|
|
@@ -42,7 +42,7 @@ export function onCharity(
|
|
|
42
42
|
targetAmount: 0,
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
eventsub.
|
|
45
|
+
eventsub.on(
|
|
46
46
|
[
|
|
47
47
|
"channel.charity_campaign.start",
|
|
48
48
|
"channel.charity_campaign.progress",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./charity.
|
|
1
|
+
export * from "./charity.ts"
|
package/src/helpers/goal/goal.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type TwitchEventSub } from "../../eventsub/index.
|
|
1
|
+
import { type TwitchEventSub } from "../../eventsub/index.ts"
|
|
2
2
|
|
|
3
3
|
export interface Goal {
|
|
4
4
|
type: string
|
|
@@ -24,7 +24,7 @@ export function onGoal(
|
|
|
24
24
|
targetAmount: 0,
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
eventsub.
|
|
27
|
+
eventsub.on(
|
|
28
28
|
["channel.goal.begin", "channel.goal.progress", "channel.goal.end"],
|
|
29
29
|
(payload) => {
|
|
30
30
|
goal.type = payload.event.type
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./goal.
|
|
1
|
+
export * from "./goal.ts"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type TwitchEventSub } from "../../eventsub/index.
|
|
1
|
+
import { type TwitchEventSub } from "../../eventsub/index.ts"
|
|
2
2
|
|
|
3
3
|
export interface HypeTrain {
|
|
4
4
|
level: number
|
|
@@ -27,7 +27,7 @@ export function onHypeTrain(
|
|
|
27
27
|
goal: 0,
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
eventsub.
|
|
30
|
+
eventsub.on(
|
|
31
31
|
[
|
|
32
32
|
"channel.hype_train.begin",
|
|
33
33
|
"channel.hype_train.progress",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./hype-train.
|
|
1
|
+
export * from "./hype-train.ts"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./poll.
|
|
1
|
+
export * from "./poll.ts"
|
package/src/helpers/poll/poll.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type TwitchEventSub } from "../../eventsub/index.
|
|
1
|
+
import { type TwitchEventSub } from "../../eventsub/index.ts"
|
|
2
2
|
|
|
3
3
|
export interface Poll {
|
|
4
4
|
id: string
|
|
@@ -31,7 +31,7 @@ export function onPoll(
|
|
|
31
31
|
endsAt: undefined,
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
eventsub.
|
|
34
|
+
eventsub.on(
|
|
35
35
|
["channel.poll.begin", "channel.poll.progress", "channel.poll.end"],
|
|
36
36
|
(payload) => {
|
|
37
37
|
// Twitch sometimes sends duplicate end events.
|
|
@@ -66,7 +66,7 @@ export function onPoll(
|
|
|
66
66
|
payload.type === "channel.poll.begin" ||
|
|
67
67
|
payload.type === "channel.poll.progress"
|
|
68
68
|
) {
|
|
69
|
-
poll.endsAt = payload.event.ends_at
|
|
69
|
+
poll.endsAt = new Date(payload.event.ends_at)
|
|
70
70
|
} else {
|
|
71
71
|
poll.endsAt = undefined
|
|
72
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./prediction.
|
|
1
|
+
export * from "./prediction.ts"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type TwitchEventSub } from "../../eventsub/index.
|
|
1
|
+
import { type TwitchEventSub } from "../../eventsub/index.ts"
|
|
2
2
|
|
|
3
3
|
export interface Prediction {
|
|
4
4
|
title: string
|
|
@@ -32,7 +32,7 @@ export function onPrediction(
|
|
|
32
32
|
locksAt: new Date(""),
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
eventsub.
|
|
35
|
+
eventsub.on(
|
|
36
36
|
[
|
|
37
37
|
"channel.prediction.begin",
|
|
38
38
|
"channel.prediction.progress",
|
|
@@ -55,7 +55,7 @@ export function onPrediction(
|
|
|
55
55
|
payload.type === "channel.prediction.begin" ||
|
|
56
56
|
payload.type === "channel.prediction.progress"
|
|
57
57
|
) {
|
|
58
|
-
prediction.locksAt = payload.event.locks_at
|
|
58
|
+
prediction.locksAt = new Date(payload.event.locks_at)
|
|
59
59
|
} else {
|
|
60
60
|
prediction.locksAt = undefined
|
|
61
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./redemption.
|
|
1
|
+
export * from "./redemption.ts"
|