Skip to content
This repository was archived by the owner on Jun 1, 2026. It is now read-only.

Commit 6e7853d

Browse files
committed
Block support pushes for private Chatwoot messages
1 parent 5a632aa commit 6e7853d

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

‎crates/support/src/client.rs‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl SupportClient {
3636
}
3737

3838
fn build_notification(device: &Device, payload: &ChatwootWebhookPayload) -> Option<GorushNotification> {
39-
if !payload.is_outgoing_message() {
39+
if !payload.is_public_outgoing_message() {
4040
return None;
4141
}
4242

@@ -73,4 +73,23 @@ mod tests {
7373

7474
assert!(notification.is_none());
7575
}
76+
77+
#[test]
78+
fn test_build_notification_private_message_created() {
79+
let payload: ChatwootWebhookPayload =
80+
serde_json::from_str(r#"{"event": "message_created", "message_type": "outgoing", "private": true, "content": "internal note"}"#).unwrap();
81+
82+
let notification = SupportClient::build_notification(&Device::mock(), &payload);
83+
84+
assert!(notification.is_none());
85+
}
86+
87+
#[test]
88+
fn test_build_notification_missing_private_message_created() {
89+
let payload: ChatwootWebhookPayload = serde_json::from_str(r#"{"event": "message_created", "message_type": "outgoing", "content": "unknown visibility"}"#).unwrap();
90+
91+
let notification = SupportClient::build_notification(&Device::mock(), &payload);
92+
93+
assert!(notification.is_none());
94+
}
7695
}

‎crates/support/src/model.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub struct Account {
3838
pub struct ChatwootWebhookPayload {
3939
pub event: String,
4040
pub message_type: Option<String>,
41+
pub private: Option<bool>,
4142
pub unread_count: Option<i32>,
4243
pub conversation: Option<Conversation>,
4344
pub account: Option<Account>,
@@ -61,6 +62,7 @@ pub struct Message {
6162
pub id: i64,
6263
pub content: Option<String>,
6364
pub message_type: MessageType,
65+
pub private: Option<bool>,
6466
pub sender: Option<Sender>,
6567
}
6668

@@ -103,6 +105,10 @@ impl ChatwootWebhookPayload {
103105
self.message_type.as_deref() == Some("incoming")
104106
}
105107

108+
pub fn is_public_outgoing_message(&self) -> bool {
109+
self.is_outgoing_message() && self.private == Some(false)
110+
}
111+
106112
pub fn get_account_id(&self) -> Option<i64> {
107113
self.account.as_ref().map(|a| a.id)
108114
}

‎crates/support/tests/model_tests.rs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ fn test_parse_conversation_updated_payload() {
1313
let message = &messages[0];
1414
assert_eq!(message.content, Some("Test message".to_string()));
1515
assert!(!message.is_incoming());
16+
assert_eq!(message.private, Some(false));
1617

1718
let sender = message.sender.as_ref().unwrap();
1819
assert!(sender.custom_attributes.is_none());
@@ -33,12 +34,14 @@ fn test_parse_message_created_payload() {
3334
assert_eq!(payload.get_device_id(), Some("test-device-id".to_string()));
3435
assert_eq!(payload.get_unread(), Some(1));
3536
assert!(payload.is_outgoing_message());
37+
assert!(payload.is_public_outgoing_message());
3638

3739
let messages = payload.get_messages();
3840
assert_eq!(messages.len(), 1);
3941

4042
let message = &messages[0];
4143
assert!(!message.is_incoming());
44+
assert_eq!(message.private, Some(false));
4245
}
4346

4447
#[test]
@@ -77,6 +80,21 @@ fn test_is_incoming_message() {
7780
assert!(!payload.is_incoming_message());
7881
}
7982

83+
#[test]
84+
fn test_is_public_outgoing_message() {
85+
let payload: ChatwootWebhookPayload = serde_json::from_str(r#"{"event": "message_created", "message_type": "outgoing", "private": false}"#).unwrap();
86+
assert!(payload.is_public_outgoing_message());
87+
88+
let payload: ChatwootWebhookPayload = serde_json::from_str(r#"{"event": "message_created", "message_type": "outgoing", "private": true}"#).unwrap();
89+
assert!(!payload.is_public_outgoing_message());
90+
91+
let payload: ChatwootWebhookPayload = serde_json::from_str(r#"{"event": "message_created", "message_type": "incoming", "private": false}"#).unwrap();
92+
assert!(!payload.is_public_outgoing_message());
93+
94+
let payload: ChatwootWebhookPayload = serde_json::from_str(r#"{"event": "message_created", "message_type": "outgoing"}"#).unwrap();
95+
assert!(!payload.is_public_outgoing_message());
96+
}
97+
8098
#[test]
8199
fn test_get_account_id() {
82100
let payload: ChatwootWebhookPayload = serde_json::from_str(include_str!("testdata/chatwoot_message_created.json")).unwrap();

0 commit comments

Comments
 (0)