twitch_api/eventsub/channel/chat/
message_delete.rs1#![doc(alias = "channel.chat.message_delete")]
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 ChannelChatMessageDeleteV1 {
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 user_id: types::UserId,
17}
18
19impl ChannelChatMessageDeleteV1 {
20 pub fn new(
22 broadcaster_user_id: impl Into<types::UserId>,
23 user_id: impl Into<types::UserId>,
24 ) -> Self {
25 Self {
26 broadcaster_user_id: broadcaster_user_id.into(),
27 user_id: user_id.into(),
28 }
29 }
30}
31
32impl EventSubscription for ChannelChatMessageDeleteV1 {
33 type Payload = ChannelChatMessageDeleteV1Payload;
34
35 const EVENT_TYPE: EventType = EventType::ChannelChatMessageDelete;
36 #[cfg(feature = "twitch_oauth2")]
37 const SCOPE: twitch_oauth2::Validator =
38 twitch_oauth2::validator![twitch_oauth2::Scope::UserReadChat];
39 const VERSION: &'static str = "1";
40}
41
42#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
44#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
45#[non_exhaustive]
46pub struct ChannelChatMessageDeleteV1Payload {
47 pub broadcaster_user_id: types::UserId,
49 pub broadcaster_user_name: types::DisplayName,
51 pub broadcaster_user_login: types::UserName,
53 pub target_user_id: types::UserId,
55 pub target_user_name: types::DisplayName,
57 pub target_user_login: types::UserName,
59 pub message_id: types::MsgId,
61}
62
63#[cfg(test)]
64#[test]
65fn parse_payload() {
66 let payload = r##"
67 {
68 "subscription": {
69 "id": "f1c2a387-161a-49f9-a165-0f21d7a4e1c4",
70 "type": "channel.chat.message_delete",
71 "version": "1",
72 "status": "enabled",
73 "cost": 0,
74 "condition": {
75 "broadcaster_user_id": "1337",
76 "user_id": "9001"
77 },
78 "transport": {
79 "method": "webhook",
80 "callback": "https://example.com/webhooks/callback"
81 },
82 "created_at": "2023-04-11T10:11:12.123Z"
83 },
84 "event": {
85 "broadcaster_user_id": "1337",
86 "broadcaster_user_name": "Cool_User",
87 "broadcaster_user_login": "cool_user",
88 "target_user_id": "7734",
89 "target_user_name": "Uncool_viewer",
90 "target_user_login": "uncool_viewer",
91 "message_id": "ab24e0b0-2260-4bac-94e4-05eedd4ecd0e"
92 }
93 }
94 "##;
95
96 let val = dbg!(crate::eventsub::Event::parse(payload).unwrap());
97 crate::tests::roundtrip(&val)
98}