Skip to content

Commit d0988cf

Browse files
committed
add shared chat session info to ChannelChatMessageV1Payload
1 parent e54d55d commit d0988cf

File tree

2 files changed

+124
-32
lines changed

2 files changed

+124
-32
lines changed

src/eventsub/channel/chat/message.rs

Lines changed: 122 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ pub struct ChannelChatMessageV1Payload {
8080
pub channel_points_custom_reward_id: Option<types::RewardId>,
8181
/// An ID for the type of animation selected as part of an “animate my message” redemption.
8282
pub channel_points_animation_id: Option<String>,
83+
/// Only present when in a shared chat session. The broadcaster user ID of the channel the message was sent from.
84+
pub source_broadcaster_user_id: Option<types::UserId>,
85+
/// Only present when in a shared chat session. The user name of the broadcaster of the channel the message was sent from.
86+
pub source_broadcaster_user_name: Option<types::DisplayName>,
87+
/// Only present when in a shared chat session. The login of the broadcaster of the channel the message was sent from.
88+
pub source_broadcaster_user_login: Option<types::UserName>,
89+
/// Only present when in a shared chat session. The UUID that identifies the source message from the channel the message was sent from.
90+
pub source_message_id: Option<types::MsgId>,
91+
/// Only present when in a shared chat session. The list of chat badges for the chatter in the channel the message was sent from.
92+
#[serde(deserialize_with = "crate::deserialize_default_from_null")]
93+
pub source_badges: Vec<Badge>,
8394
}
8495

8596
/// The type a message.
@@ -154,62 +165,133 @@ pub struct Reply {
154165
#[test]
155166
fn parse_payload() {
156167
let payload = r##"
157-
{
168+
{
158169
"subscription": {
159-
"id": "47faedb0-b918-4d79-a974-fe799c9b1f6b",
170+
"id": "0b7f3361-672b-4d39-b307-dd5b576c9b27",
160171
"status": "enabled",
161172
"type": "channel.chat.message",
162173
"version": "1",
163174
"condition": {
164-
"broadcaster_user_id": "141981764",
165-
"user_id": "129546453"
175+
"broadcaster_user_id": "1971641",
176+
"user_id": "2914196"
166177
},
167178
"transport": {
168179
"method": "websocket",
169-
"session_id": "AgoQL5tbQXjKS4SBPvF0F-Qz0hIGY2VsbC1j"
180+
"session_id": "AgoQHR3s6Mb4T8GFB1l3DlPfiRIGY2VsbC1h"
170181
},
171-
"created_at": "2024-02-24T17:17:49.772726224Z",
182+
"created_at": "2023-11-06T18:11:47.492253549Z",
172183
"cost": 0
173184
},
174185
"event": {
175-
"broadcaster_user_id": "141981764",
176-
"broadcaster_user_login": "twitchdev",
177-
"broadcaster_user_name": "TwitchDev",
178-
"chatter_user_id": "129546453",
179-
"chatter_user_login": "nerixyz",
180-
"chatter_user_name": "nerixyz",
181-
"message_id": "9d0bcb5e-ee31-4b09-b72f-66eb94ce061e",
186+
"broadcaster_user_id": "1971641",
187+
"broadcaster_user_login": "streamer",
188+
"broadcaster_user_name": "streamer",
189+
"chatter_user_id": "4145994",
190+
"chatter_user_login": "viewer32",
191+
"chatter_user_name": "viewer32",
192+
"message_id": "cc106a89-1814-919d-454c-f4f2f970aae7",
182193
"message": {
183-
"text": "Hello, World! DinoDance",
194+
"text": "Hi chat",
184195
"fragments": [
185196
{
186197
"type": "text",
187-
"text": "Hello, World! ",
198+
"text": "Hi chat",
188199
"cheermote": null,
189200
"emote": null,
190201
"mention": null
191-
},
202+
}
203+
]
204+
},
205+
"color": "#00FF7F",
206+
"badges": [
207+
{
208+
"set_id": "moderator",
209+
"id": "1",
210+
"info": ""
211+
},
212+
{
213+
"set_id": "subscriber",
214+
"id": "12",
215+
"info": "16"
216+
},
217+
{
218+
"set_id": "sub-gifter",
219+
"id": "1",
220+
"info": ""
221+
}
222+
],
223+
"message_type": "text",
224+
"cheer": null,
225+
"reply": null,
226+
"channel_points_custom_reward_id": null,
227+
"source_broadcaster_user_id": null,
228+
"source_broadcaster_user_login": null,
229+
"source_broadcaster_user_name": null,
230+
"source_message_id": null,
231+
"source_badges": null
232+
}
233+
}
234+
"##;
235+
236+
let val = dbg!(crate::eventsub::Event::parse(payload).unwrap());
237+
crate::tests::roundtrip(&val)
238+
}
239+
240+
#[cfg(test)]
241+
#[test]
242+
fn parse_payload_shared() {
243+
let payload = r##"
244+
{
245+
"subscription": {
246+
"id": "0b7f3361-672b-4d39-b307-dd5b576c9b27",
247+
"status": "enabled",
248+
"type": "channel.chat.message",
249+
"version": "1",
250+
"condition": {
251+
"broadcaster_user_id": "1971641",
252+
"user_id": "2914196"
253+
},
254+
"transport": {
255+
"method": "websocket",
256+
"session_id": "AgoQHR3s6Mb4T8GFB1l3DlPfiRIGY2VsbC1h"
257+
},
258+
"created_at": "2023-11-06T18:11:47.492253549Z",
259+
"cost": 0
260+
},
261+
"event": {
262+
"broadcaster_user_id": "1971641",
263+
"broadcaster_user_login": "streamer",
264+
"broadcaster_user_name": "streamer",
265+
"chatter_user_id": "4145994",
266+
"chatter_user_login": "viewer32",
267+
"chatter_user_name": "viewer32",
268+
"message_id": "cc106a89-1814-919d-454c-f4f2f970aae7",
269+
"message": {
270+
"text": "Hi chat",
271+
"fragments": [
192272
{
193-
"type": "emote",
194-
"text": "DinoDance",
273+
"type": "text",
274+
"text": "Hi chat",
195275
"cheermote": null,
196-
"emote": {
197-
"id": "emotesv2_dcd06b30a5c24f6eb871e8f5edbd44f7",
198-
"emote_set_id": "0",
199-
"owner_id": "0",
200-
"format": [
201-
"static",
202-
"animated"
203-
]
204-
},
276+
"emote": null,
205277
"mention": null
206278
}
207279
]
208280
},
209-
"color": "#FF0000",
281+
"color": "#00FF7F",
210282
"badges": [
211283
{
212-
"set_id": "no_video",
284+
"set_id": "moderator",
285+
"id": "1",
286+
"info": ""
287+
},
288+
{
289+
"set_id": "subscriber",
290+
"id": "12",
291+
"info": "16"
292+
},
293+
{
294+
"set_id": "sub-gifter",
213295
"id": "1",
214296
"info": ""
215297
}
@@ -218,7 +300,17 @@ fn parse_payload() {
218300
"cheer": null,
219301
"reply": null,
220302
"channel_points_custom_reward_id": null,
221-
"channel_points_animation_id": null
303+
"source_broadcaster_user_id": "112233",
304+
"source_broadcaster_user_login": "streamer33",
305+
"source_broadcaster_user_name": "streamer33",
306+
"source_message_id": "e03f6d5d-8ec8-4c63-b473-9e5fe61e289b",
307+
"source_badges": [
308+
{
309+
"set_id": "subscriber",
310+
"id": "3",
311+
"info": "3"
312+
}
313+
]
222314
}
223315
}
224316
"##;

src/eventsub/channel/chat/message_delete.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn parse_payload() {
7575
"broadcaster_user_id": "1337",
7676
"user_id": "9001"
7777
},
78-
"transport": {
78+
"transport": {
7979
"method": "webhook",
8080
"callback": "https://example.com/webhooks/callback"
8181
},
@@ -88,7 +88,7 @@ fn parse_payload() {
8888
"target_user_id": "7734",
8989
"target_user_name": "Uncool_viewer",
9090
"target_user_login": "uncool_viewer",
91-
"message_id": "885196de-cb67-427a-baa8-82f9b0fcd05f"
91+
"message_id": "ab24e0b0-2260-4bac-94e4-05eedd4ecd0e"
9292
}
9393
}
9494
"##;

0 commit comments

Comments
 (0)