#![doc(alias = "channel.chat.user_message_update")]
use super::*;
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "typed-builder", derive(typed_builder::TypedBuilder))]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct ChannelChatUserMessageUpdateV1 {
#[cfg_attr(feature = "typed-builder", builder(setter(into)))]
pub broadcaster_user_id: types::UserId,
#[cfg_attr(feature = "typed-builder", builder(setter(into)))]
pub user_id: types::UserId,
}
impl ChannelChatUserMessageUpdateV1 {
pub fn new(
broadcaster_user_id: impl Into<types::UserId>,
user_id: impl Into<types::UserId>,
) -> Self {
Self {
broadcaster_user_id: broadcaster_user_id.into(),
user_id: user_id.into(),
}
}
}
impl EventSubscription for ChannelChatUserMessageUpdateV1 {
type Payload = ChannelChatUserMessageUpdateV1Payload;
const EVENT_TYPE: EventType = EventType::ChannelChatUserMessageUpdate;
#[cfg(feature = "twitch_oauth2")]
const SCOPE: twitch_oauth2::Validator =
twitch_oauth2::validator![twitch_oauth2::Scope::UserReadChat];
const VERSION: &'static str = "1";
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct ChannelChatUserMessageUpdateV1Payload {
pub broadcaster_user_id: types::UserId,
pub broadcaster_user_login: types::UserName,
pub broadcaster_user_name: types::DisplayName,
pub user_id: types::UserId,
pub user_login: types::UserName,
pub user_name: types::DisplayName,
pub status: crate::eventsub::automod::message::AutomodMessageStatus,
pub message_id: types::MsgId,
pub message: crate::eventsub::automod::message::AutomodMessage,
}
#[cfg(test)]
#[test]
fn parse_payload() {
use crate::eventsub::{Event, Message};
let payload = r##"
{
"subscription": {
"id": "f1c2a387-161a-49f9-a165-0f21d7a4e1c4",
"type": "channel.chat.user_message_update",
"version": "1",
"status": "enabled",
"cost": 0,
"condition": {
"broadcaster_user_id": "1337",
"user_id": "9001"
},
"transport": {
"method": "webhook",
"callback": "https://example.com/webhooks/callback"
},
"created_at": "2023-04-11T10:11:12.123Z"
},
"event": {
"broadcaster_user_id": "123",
"broadcaster_user_login": "bob",
"broadcaster_user_name": "Bob",
"user_id": "456",
"user_login": "tom",
"user_name": "Tommy",
"status": "approved",
"message_id": "789",
"message": {
"text": "hey world",
"fragments": [
{
"type": "emote",
"text": "hey world",
"cheermote": null,
"emote": {
"id": "foo",
"emote_set_id": "7"
}
},
{
"type": "cheermote",
"text": "bye world",
"cheermote": {
"prefix": "prefix",
"bits": 100,
"tier": 1
},
"emote": null
},
{
"type": "text",
"text": "surprise",
"cheermote": null,
"emote": null
}
]
}
}
}
"##;
let val = Event::parse(payload).unwrap();
crate::tests::roundtrip(&val);
let Event::ChannelChatUserMessageUpdateV1(val) = val else {
panic!("invalid event type");
};
let Message::Notification(notif) = val.message else {
panic!("invalid message type");
};
assert_eq!(notif.broadcaster_user_id.as_str(), "123");
assert_eq!(notif.user_id.as_str(), "456");
assert_eq!(
notif.status,
crate::eventsub::automod::message::AutomodMessageStatus::Approved
);
assert_eq!(notif.message_id.as_str(), "789");
assert_eq!(notif.message.text, "hey world");
}