twitch_api/eventsub/channel/shoutout/
receive.rs1#![doc(alias = "channel.shoutout.receive")]
2use super::*;
5#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
7#[cfg_attr(feature = "typed-builder", derive(typed_builder::TypedBuilder))]
8#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
9#[non_exhaustive]
10pub struct ChannelShoutoutReceiveV1 {
11 #[cfg_attr(feature = "typed-builder", builder(setter(into)))]
13 pub broadcaster_user_id: types::UserId,
14 #[cfg_attr(feature = "typed-builder", builder(setter(into)))]
16 pub moderator_user_id: types::UserId,
17}
18
19impl ChannelShoutoutReceiveV1 {
20 pub fn new(
22 broadcaster_user_id: impl Into<types::UserId>,
23 moderator_user_id: impl Into<types::UserId>,
24 ) -> Self {
25 Self {
26 broadcaster_user_id: broadcaster_user_id.into(),
27 moderator_user_id: moderator_user_id.into(),
28 }
29 }
30}
31
32impl EventSubscription for ChannelShoutoutReceiveV1 {
33 type Payload = ChannelShoutoutReceiveV1Payload;
34
35 const EVENT_TYPE: EventType = EventType::ChannelShoutoutReceive;
36 #[cfg(feature = "twitch_oauth2")]
37 const SCOPE: twitch_oauth2::Validator = twitch_oauth2::validator![any(
38 twitch_oauth2::Scope::ModeratorReadShoutouts,
39 twitch_oauth2::Scope::ModeratorManageShoutouts
40 )];
41 const VERSION: &'static str = "1";
42}
43
44#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
46#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
47#[non_exhaustive]
48pub struct ChannelShoutoutReceiveV1Payload {
49 pub broadcaster_user_id: types::UserId,
51 pub broadcaster_user_login: types::UserName,
53 pub broadcaster_user_name: types::DisplayName,
55 pub from_broadcaster_user_id: types::UserId,
57 pub from_broadcaster_user_login: types::UserName,
59 pub from_broadcaster_user_name: types::DisplayName,
61 pub viewer_count: i64,
63 pub started_at: types::Timestamp,
65}
66
67#[cfg(test)]
68#[test]
69fn parse_payload() {
70 let payload = r##"
71 {
72 "subscription": {
73 "id": "f1c2a387-161a-49f9-a165-0f21d7a4e1c4",
74 "type": "channel.shoutout.receive",
75 "version": "1",
76 "status": "enabled",
77 "cost": 0,
78 "condition": {
79 "broadcaster_user_id": "626262",
80 "moderator_user_id": "98765"
81 },
82 "transport": {
83 "method": "webhook",
84 "callback": "https://example.com/webhooks/callback"
85 },
86 "created_at": "2022-07-25T10:11:12.1236739Z"
87 },
88 "event": {
89 "broadcaster_user_id": "626262",
90 "broadcaster_user_name": "SandySanderman",
91 "broadcaster_user_login": "sandysanderman",
92 "from_broadcaster_user_id": "12345",
93 "from_broadcaster_user_name": "SimplySimple",
94 "from_broadcaster_user_login": "simplysimple",
95 "viewer_count": 860,
96 "started_at": "2022-07-26T17:00:03.17106713Z"
97 }
98 }
99 "##;
100
101 let val = dbg!(crate::eventsub::Event::parse(payload).unwrap());
102 crate::tests::roundtrip(&val)
103}