@@ -64,6 +64,16 @@ pub struct ChannelChatNotificationV1Payload {
6464 /// The notification
6565 #[ serde( flatten) ]
6666 pub notification : Notification ,
67+ /// Only present when in a shared chat session. The broadcaster user ID of the channel the message was sent from.
68+ pub source_broadcaster_user_id : Option < types:: UserId > ,
69+ /// Only present when in a shared chat session. The user name of the broadcaster of the channel the message was sent from.
70+ pub source_broadcaster_user_name : Option < types:: DisplayName > ,
71+ /// Only present when in a shared chat session. The login of the broadcaster of the channel the message was sent from.
72+ pub source_broadcaster_user_login : Option < types:: UserName > ,
73+ /// Only present when in a shared chat session. The UUID that identifies the source message from the channel the message was sent from.
74+ pub source_message_id : Option < types:: MsgId > ,
75+ /// Only present when in a shared chat session. The list of chat badges for the chatter in the channel the message was sent from.
76+ pub source_badges : Option < Vec < Badge > > ,
6777}
6878
6979/// Information about the user that triggered this notification
@@ -219,43 +229,84 @@ pub enum Notification {
219229 /// Information about the bits badge tier event.
220230 #[ serde( with = "crate::eventsub::enum_field_as_inner" ) ]
221231 BitsBadgeTier ( BitsBadgeTier ) ,
232+
233+ // Shared chat notifications
234+ /// Information about the sub event that happened in a shared chat.
235+ #[ serde( with = "crate::eventsub::enum_field_as_inner_prefixed" ) ]
236+ SharedChatSub ( Subscription ) ,
237+ /// Information about the resub event that happened in a shared chat.
238+ #[ serde( with = "crate::eventsub::enum_field_as_inner_prefixed" ) ]
239+ SharedChatResub ( Resubscription ) ,
240+ /// Information about the gift sub event that happened in a shared chat.
241+ #[ serde( with = "crate::eventsub::enum_field_as_inner_prefixed" ) ]
242+ SharedChatSubGift ( SubGift ) ,
243+ /// Information about the community gift sub event that happened in a shared chat.
244+ #[ serde( with = "crate::eventsub::enum_field_as_inner_prefixed" ) ]
245+ SharedChatCommunitySubGift ( CommunitySubGift ) ,
246+ /// Information about the community gift paid upgrade event that happened in a shared chat.
247+ #[ serde( with = "crate::eventsub::enum_field_as_inner_prefixed" ) ]
248+ SharedChatGiftPaidUpgrade ( GiftPaidUpgrade ) ,
249+ /// Information about the Prime gift paid upgrade event that happened in a shared chat.
250+ #[ serde( with = "crate::eventsub::enum_field_as_inner_prefixed" ) ]
251+ SharedChatPrimePaidUpgrade ( PrimePaidUpgrade ) ,
252+ /// Information about the pay it forward event that happened in a shared chat.
253+ #[ serde( with = "crate::eventsub::enum_field_as_inner_prefixed" ) ]
254+ SharedChatPayItForward ( PayItForward ) ,
255+ /// Information about the raid event that happened in a shared chat.
256+ #[ serde( with = "crate::eventsub::enum_field_as_inner_prefixed" ) ]
257+ SharedChatRaid ( Raid ) ,
258+ /// Information about the announcement event that happened in a shared chat.
259+ #[ serde( with = "crate::eventsub::enum_field_as_inner_prefixed" ) ]
260+ SharedChatAnnouncement ( Announcement ) ,
222261}
223262
224263impl crate :: eventsub:: NamedField for Subscription {
225264 const NAME : & ' static str = "sub" ;
265+ const OPT_PREFIX : Option < & ' static str > = Some ( "shared_chat_" ) ;
226266}
227267impl crate :: eventsub:: NamedField for Resubscription {
228268 const NAME : & ' static str = "resub" ;
269+ const OPT_PREFIX : Option < & ' static str > = Some ( "shared_chat_" ) ;
229270}
230271impl crate :: eventsub:: NamedField for SubGift {
231272 const NAME : & ' static str = "sub_gift" ;
273+ const OPT_PREFIX : Option < & ' static str > = Some ( "shared_chat_" ) ;
232274}
233275impl crate :: eventsub:: NamedField for CommunitySubGift {
234276 const NAME : & ' static str = "community_sub_gift" ;
277+ const OPT_PREFIX : Option < & ' static str > = Some ( "shared_chat_" ) ;
235278}
236279impl crate :: eventsub:: NamedField for GiftPaidUpgrade {
237280 const NAME : & ' static str = "gift_paid_upgrade" ;
281+ const OPT_PREFIX : Option < & ' static str > = Some ( "shared_chat_" ) ;
238282}
239283impl crate :: eventsub:: NamedField for PrimePaidUpgrade {
240284 const NAME : & ' static str = "prime_paid_upgrade" ;
285+ const OPT_PREFIX : Option < & ' static str > = Some ( "shared_chat_" ) ;
241286}
242287impl crate :: eventsub:: NamedField for Raid {
243288 const NAME : & ' static str = "raid" ;
289+ const OPT_PREFIX : Option < & ' static str > = Some ( "shared_chat_" ) ;
244290}
245291impl crate :: eventsub:: NamedField for Unraid {
246292 const NAME : & ' static str = "unraid" ;
293+ const OPT_PREFIX : Option < & ' static str > = Some ( "shared_chat_" ) ;
247294}
248295impl crate :: eventsub:: NamedField for PayItForward {
249296 const NAME : & ' static str = "pay_it_forward" ;
297+ const OPT_PREFIX : Option < & ' static str > = Some ( "shared_chat_" ) ;
250298}
251299impl crate :: eventsub:: NamedField for Announcement {
252300 const NAME : & ' static str = "announcement" ;
301+ const OPT_PREFIX : Option < & ' static str > = Some ( "shared_chat_" ) ;
253302}
254303impl crate :: eventsub:: NamedField for CharityDonation {
255304 const NAME : & ' static str = "charity_donation" ;
305+ const OPT_PREFIX : Option < & ' static str > = Some ( "shared_chat_" ) ;
256306}
257307impl crate :: eventsub:: NamedField for BitsBadgeTier {
258308 const NAME : & ' static str = "bits_badge_tier" ;
309+ const OPT_PREFIX : Option < & ' static str > = Some ( "shared_chat_" ) ;
259310}
260311
261312/// A subscription notification
@@ -389,6 +440,7 @@ pub struct Resubscription {
389440 /// * `3000` — Third level of paid subscription
390441 pub sub_tier : types:: SubscriptionTier ,
391442 /// Indicates if the resub was obtained through Amazon Prime.
443+ #[ serde( default ) ]
392444 pub is_prime : bool ,
393445 /// Whether or not the resub was a result of a gift.
394446 pub is_gift : bool ,
@@ -539,86 +591,78 @@ pub struct BitsBadgeTier {
539591#[ cfg( test) ]
540592#[ test]
541593fn parse_payload ( ) {
594+ // FIXME: examples uses sub_plan: https://github.com/twitchdev/issues/issues/1039
542595 let payload = r##"
543596 {
544597 "subscription": {
545- "id": "f1c2a387-161a-49f9-a165-0f21d7a4e1c4",
598+ "id": "dc1a3cfc-a930-4972-bf9e-0ffc4e7a8996",
599+ "status": "enabled",
546600 "type": "channel.chat.notification",
547601 "version": "1",
548- "status": "enabled",
549- "cost": 0,
550602 "condition": {
551- "broadcaster_user_id": "1337 ",
552- "user_id": "9001 "
603+ "broadcaster_user_id": "1971641 ",
604+ "user_id": "2914196 "
553605 },
554- "transport": {
555- "method": "webhook ",
556- "callback ": "https://example.com/webhooks/callback "
606+ "transport": {
607+ "method": "websocket ",
608+ "session_id ": "AgoQOtgGkFvXRlSkij343CndhIGY2VsbC1h "
557609 },
558- "created_at": "2023-04-11T10:11:12.123Z"
610+ "created_at": "2023-10-06T18:04:38.807682738Z",
611+ "cost": 0
559612 },
560613 "event": {
561- "broadcaster_user_id": "1337 ",
562- "broadcaster_user_name ": "Cool_User ",
563- "broadcaster_user_login ": "cool_user ",
564- "chatter_user_id": "444 ",
565- "chatter_user_login": "cool_chatter ",
566- "chatter_user_name": "Cool_Chatter ",
614+ "broadcaster_user_id": "1971641 ",
615+ "broadcaster_user_login ": "streamer ",
616+ "broadcaster_user_name ": "streamer ",
617+ "chatter_user_id": "49912639 ",
618+ "chatter_user_login": "viewer23 ",
619+ "chatter_user_name": "viewer23 ",
567620 "chatter_is_anonymous": false,
568- "color": "red",
569- "badges": [
570- {
571- "set_id": "moderator",
572- "id": "1",
573- "info": ""
574- },
575- {
576- "set_id": "subscriber",
577- "id": "12",
578- "info": "16"
579- },
580- {
581- "set_id": "sub-gifter",
582- "id": "1",
583- "info": ""
584- }
585- ],
586- "system_message": "chat message",
587- "message_id": "message-id",
621+ "color": "",
622+ "badges": [],
623+ "system_message": "viewer23 subscribed at Tier 1. They've subscribed for 10 months!",
624+ "message_id": "d62235c8-47ff-a4f4--84e8-5a29a65a9c03",
588625 "message": {
589- "text": "chat-msg",
590- "fragments": [
591- {
592- "type": "emote",
593- "text": "chat-msg",
594- "cheermote": null,
595- "emote": {
596- "id": "emote-id",
597- "emote_set_id": "emote-set",
598- "owner_id": "emote-owner",
599- "format": [
600- "static"
601- ]
602- },
603- "mention": null
604- }
605- ]
626+ "text": "",
627+ "fragments": []
606628 },
607- "notice_type": "announcement ",
629+ "notice_type": "resub ",
608630 "sub": null,
609- "resub": null,
631+ "resub": {
632+ "cumulative_months": 10,
633+ "duration_months": 0,
634+ "streak_months": null,
635+ "sub_tier": "1000",
636+ "is_gift": false,
637+ "gifter_is_anonymous": null,
638+ "gifter_user_id": null,
639+ "gifter_user_name": null,
640+ "gifter_user_login": null
641+ },
610642 "sub_gift": null,
611643 "community_sub_gift": null,
612644 "gift_paid_upgrade": null,
613645 "prime_paid_upgrade": null,
614646 "pay_it_forward": null,
615647 "raid": null,
616648 "unraid": null,
617- "announcement": {
618- "color": "blue"
619- },
649+ "announcement": null,
620650 "bits_badge_tier": null,
621- "charity_donation": null
651+ "charity_donation": null,
652+ "shared_chat_sub": null,
653+ "shared_chat_resub": null,
654+ "shared_chat_sub_gift": null,
655+ "shared_chat_community_sub_gift": null,
656+ "shared_chat_gift_paid_upgrade": null,
657+ "shared_chat_prime_paid_upgrade": null,
658+ "shared_chat_pay_it_forward": null,
659+ "shared_chat_raid": null,
660+ "shared_chat_announcement": null,
661+ "source_broadcaster_user_id": null,
662+ "source_broadcaster_user_login": null,
663+ "source_broadcaster_user_name": null,
664+ "source_message_id": null,
665+ "source_badges": null
622666 }
623667 }
624668 "## ;
@@ -1055,3 +1099,92 @@ fn parse_payload_examples() {
10551099 crate :: tests:: roundtrip ( & val)
10561100 }
10571101}
1102+
1103+ #[ cfg( test) ]
1104+ #[ test]
1105+ fn parse_shared_chat ( ) {
1106+ // FIXME: examples uses sub_plan: https://github.com/twitchdev/issues/issues/1039
1107+ let payload = r#"
1108+ {
1109+ "subscription": {
1110+ "id": "dc1a3cfc-a930-4972-bf9e-0ffc4e7a8996",
1111+ "status": "enabled",
1112+ "type": "channel.chat.notification",
1113+ "version": "1",
1114+ "condition": {
1115+ "broadcaster_user_id": "1971641",
1116+ "user_id": "2914196"
1117+ },
1118+ "transport": {
1119+ "method": "websocket",
1120+ "session_id": "AgoQOtgGkFvXRlSkij343CndhIGY2VsbC1h"
1121+ },
1122+ "created_at": "2023-10-06T18:04:38.807682738Z",
1123+ "cost": 0
1124+ },
1125+ "event": {
1126+ "broadcaster_user_id": "1971641",
1127+ "broadcaster_user_login": "streamer",
1128+ "broadcaster_user_name": "streamer",
1129+ "chatter_user_id": "49912639",
1130+ "chatter_user_login": "viewer23",
1131+ "chatter_user_name": "viewer23",
1132+ "chatter_is_anonymous": false,
1133+ "color": "",
1134+ "badges": [],
1135+ "system_message": "viewer23 subscribed at Tier 1. They've subscribed for 10 months!",
1136+ "message_id": "d62235c8-47ff-a4f4--84e8-5a29a65a9c03",
1137+ "message": {
1138+ "text": "",
1139+ "fragments": []
1140+ },
1141+ "notice_type": "shared_chat_resub",
1142+ "sub": null,
1143+ "resub": null,
1144+ "sub_gift": null,
1145+ "community_sub_gift": null,
1146+ "gift_paid_upgrade": null,
1147+ "prime_paid_upgrade": null,
1148+ "pay_it_forward": null,
1149+ "raid": null,
1150+ "unraid": null,
1151+ "announcement": null,
1152+ "bits_badge_tier": null,
1153+ "charity_donation": null,
1154+ "shared_chat_sub": null,
1155+ "shared_chat_resub": {
1156+ "cumulative_months": 10,
1157+ "duration_months": 0,
1158+ "streak_months": null,
1159+ "sub_tier": "1000",
1160+ "is_gift": false,
1161+ "gifter_is_anonymous": null,
1162+ "gifter_user_id": null,
1163+ "gifter_user_name": null,
1164+ "gifter_user_login": null
1165+ },
1166+ "shared_chat_sub_gift": null,
1167+ "shared_chat_community_sub_gift": null,
1168+ "shared_chat_gift_paid_upgrade": null,
1169+ "shared_chat_prime_paid_upgrade": null,
1170+ "shared_chat_pay_it_forward": null,
1171+ "shared_chat_raid": null,
1172+ "shared_chat_unraid": null,
1173+ "shared_chat_announcement": null,
1174+ "shared_chat_bits_badge_tier": null,
1175+ "shared_chat_charity_donation": null,
1176+ "source_broadcaster_user_id": "112233",
1177+ "source_broadcaster_user_login": "streamer33",
1178+ "source_broadcaster_user_name": "streamer33",
1179+ "source_message_id": "2be7193d-0366-4453-b6ec-b288ce9f2c39",
1180+ "source_badges": [{
1181+ "set_id": "subscriber",
1182+ "id": "3",
1183+ "info": "3"
1184+ }]
1185+ }
1186+ }
1187+ "# ;
1188+ let val = dbg ! ( crate :: eventsub:: Event :: parse( payload) . unwrap( ) ) ;
1189+ crate :: tests:: roundtrip ( & val)
1190+ }
0 commit comments