Skip to content

Commit 6e41d9a

Browse files
committed
feat: add user.whisper.message
1 parent 564cb2b commit 6e41d9a

File tree

5 files changed

+126
-2
lines changed

5 files changed

+126
-2
lines changed

src/eventsub/event.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ macro_rules! fill_events {
9494
user::UserAuthorizationGrantV1;
9595
user::UserAuthorizationRevokeV1;
9696
user::UserUpdateV1;
97+
user::UserWhisperMessageV1;
9798
)
9899
};
99100
}
@@ -316,6 +317,8 @@ make_event_type!("Event Types": pub enum EventType {
316317
UserAuthorizationRevoke => "user.authorization.revoke",
317318
"a user’s authorization has been granted to your client id.":
318319
UserAuthorizationGrant => "user.authorization.grant",
320+
"a user receives a whisper.":
321+
UserWhisperMessage => "user.whisper.message",
319322
},
320323
to_str: r#"Get the event string of this event.
321324
```
@@ -499,6 +502,8 @@ pub enum Event {
499502
UserAuthorizationGrantV1(Payload<user::UserAuthorizationGrantV1>),
500503
/// User Authorization Revoke V1 Event
501504
UserAuthorizationRevokeV1(Payload<user::UserAuthorizationRevokeV1>),
505+
/// User Whisper Message V1 Event
506+
UserWhisperMessageV1(Payload<user::UserWhisperMessageV1>),
502507
/// Channel Subscription End V1 Event
503508
ChannelSubscriptionEndV1(Payload<channel::ChannelSubscriptionEndV1>),
504509
/// Channel Subscription Gift V1 Event

src/eventsub/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,14 @@
197197
//!
198198
//! </details>
199199
//!
200-
//! <details><summary style="cursor: pointer"><code style="color: var(--link-color)">user.*</code> 🟡 3/4</summary>
200+
//! <details><summary style="cursor: pointer"><code style="color: var(--link-color)">user.*</code> 🟢 4/4</summary>
201201
//!
202202
//! | Name | Subscription<br>Payload |
203203
//! |---|:---|
204204
//! | [`user.authorization.grant`](https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#userauthorizationgrant) (v1) | [UserAuthorizationGrantV1](user::UserAuthorizationGrantV1)<br>[UserAuthorizationGrantV1Payload](user::UserAuthorizationGrantV1Payload) |
205205
//! | [`user.authorization.revoke`](https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#userauthorizationrevoke) (v1) | [UserAuthorizationRevokeV1](user::UserAuthorizationRevokeV1)<br>[UserAuthorizationRevokeV1Payload](user::UserAuthorizationRevokeV1Payload) |
206206
//! | [`user.update`](https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#userupdate) (v1) | [UserUpdateV1](user::UserUpdateV1)<br>[UserUpdateV1Payload](user::UserUpdateV1Payload) |
207-
//! | [`user.whisper.message`](https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#userwhispermessage) (v1) | -<br>- |
207+
//! | [`user.whisper.message`](https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#userwhispermessage) (v1) | [UserWhisperMessageV1](user::UserWhisperMessageV1)<br>[UserWhisperMessageV1Payload](user::UserWhisperMessageV1Payload) |
208208
//!
209209
//! </details>
210210
//!

src/eventsub/user/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ use serde_derive::{Deserialize, Serialize};
66

77
pub mod authorization;
88
pub mod update;
9+
pub mod whisper;
910

1011
#[doc(inline)]
1112
pub use authorization::{UserAuthorizationGrantV1, UserAuthorizationGrantV1Payload};
1213
#[doc(inline)]
1314
pub use authorization::{UserAuthorizationRevokeV1, UserAuthorizationRevokeV1Payload};
1415
#[doc(inline)]
1516
pub use update::{UserUpdateV1, UserUpdateV1Payload};
17+
#[doc(inline)]
18+
pub use whisper::{UserWhisperMessageV1, UserWhisperMessageV1Payload};
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#![doc(alias = "user.whisper.message")]
2+
//! A user receives a whisper
3+
use super::*;
4+
5+
/// [`user.whisper.message`](https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/#userwhispermessage): a user receives a whisper.
6+
#[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]
10+
pub struct UserWhisperMessageV1 {
11+
/// The user ID of the person receiving whispers.
12+
#[cfg_attr(feature = "typed-builder", builder(setter(into)))]
13+
pub user_id: types::UserId,
14+
}
15+
16+
impl UserWhisperMessageV1 {
17+
/// The user ID of the person receiving whispers.
18+
pub fn new(user_id: impl Into<types::UserId>) -> Self {
19+
Self {
20+
user_id: user_id.into(),
21+
}
22+
}
23+
}
24+
25+
impl EventSubscription for UserWhisperMessageV1 {
26+
type Payload = UserWhisperMessageV1Payload;
27+
28+
const EVENT_TYPE: EventType = EventType::UserWhisperMessage;
29+
#[cfg(feature = "twitch_oauth2")]
30+
const SCOPE: twitch_oauth2::Validator = twitch_oauth2::validator![any(
31+
twitch_oauth2::Scope::UserReadWhispers,
32+
twitch_oauth2::Scope::UserManageWhispers
33+
)];
34+
const VERSION: &'static str = "1";
35+
}
36+
37+
/// [`user.whisper.message`](UserWhisperMessageV1) response payload.
38+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
39+
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
40+
#[non_exhaustive]
41+
pub struct UserWhisperMessageV1Payload {
42+
/// The ID of the user sending the message.
43+
pub from_user_id: types::UserId,
44+
/// The name of the user sending the message.
45+
pub from_user_name: types::DisplayName,
46+
/// The login of the user sending the message.
47+
pub from_user_login: types::UserName,
48+
/// The ID of the user receiving the message.
49+
pub to_user_id: types::UserId,
50+
/// The name of the user receiving the message.
51+
pub to_user_name: types::DisplayName,
52+
/// The login of the user receiving the message.
53+
pub to_user_login: types::UserName,
54+
/// The whisper ID.
55+
pub whisper_id: types::WhisperId,
56+
/// Object containing whisper information.
57+
pub whisper: Whisper,
58+
}
59+
60+
/// Object containing whisper information.
61+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
62+
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
63+
#[non_exhaustive]
64+
pub struct Whisper {
65+
/// The body of the whisper message.
66+
pub text: String,
67+
}
68+
69+
#[cfg(test)]
70+
#[test]
71+
fn parse_payload() {
72+
let payload = r#"
73+
{
74+
"subscription": {
75+
"id": "7297f7eb-3bf5-461f-8ae6-7cd7781ebce3",
76+
"status": "enabled",
77+
"type": "user.whisper.message",
78+
"version": "1",
79+
"condition": {
80+
"user_id": "423374343"
81+
},
82+
"transport": {
83+
"method": "webhook",
84+
"callback": "https://example.com/webhooks/callback"
85+
},
86+
"created_at": "2024-02-23T21:12:33.771005262Z",
87+
"cost": 0
88+
},
89+
"event": {
90+
"from_user_id": "423374343",
91+
"from_user_login": "glowillig",
92+
"from_user_name": "glowillig",
93+
"to_user_id": "424596340",
94+
"to_user_login": "quotrok",
95+
"to_user_name": "quotrok",
96+
"whisper_id": "some-whisper-id",
97+
"whisper": {
98+
"text": "a secret"
99+
}
100+
}
101+
}
102+
"#;
103+
104+
let val = dbg!(crate::eventsub::Event::parse(payload).unwrap());
105+
crate::tests::roundtrip(&val)
106+
}

src/eventsub/user/whisper/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![doc(alias = "user.whisper")]
2+
//! Notifications for whispers (private messages)
3+
use super::{EventSubscription, EventType};
4+
use crate::types;
5+
use serde_derive::{Deserialize, Serialize};
6+
7+
pub mod message;
8+
9+
#[doc(inline)]
10+
pub use message::{UserWhisperMessageV1, UserWhisperMessageV1Payload, Whisper};

0 commit comments

Comments
 (0)