Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(whatsapp): reject DMs to numbers not on WhatsApp instead of reporting unknown (#9169)
Wolf Mermelstein99f7676c6f4d
diff --git a/apps/web/src/features/external-chat/core/chat.ts b/apps/web/src/features/external-chat/core/chat.tsindex 8cb5d5bae8..a237881d6a 100644--- a/apps/web/src/features/external-chat/core/chat.ts+++ b/apps/web/src/features/external-chat/core/chat.ts@@ -203,6 +203,15 @@ function deliveryFailure(progress: SendProgress, label: string): string {'disconnected',() => `Your ${label} disconnected before this was sent.`)+ .with(+ 'recipient_not_on_provider',+ () => `This person isn't on ${label}, so this wasn't sent.`+ )+ .with(+ 'rate_limited',+ () =>+ `${label} is limiting messages right now. Try again in a few minutes.`+ ).otherwise(() => `${label} didn't accept this message.`);}diff --git a/apps/web/src/features/external-chat/primitives/conversation.test.ts b/apps/web/src/features/external-chat/primitives/conversation.test.tsindex 1f9b8b04a2..7479a52d82 100644--- a/apps/web/src/features/external-chat/primitives/conversation.test.ts+++ b/apps/web/src/features/external-chat/primitives/conversation.test.ts@@ -148,6 +148,25 @@ describe('sending to an external chat', () => {state.dispose();});+ it('tells the sender the recipient is not on WhatsApp', async () => {+ const state = mountConversation();+ await state.conversation+ .submit({ markdown: 'Hello', attachments: [] })+ ._unsafeUnwrap();+ const key = state.fake.capabilities.send.mock.calls[0]?.[1];+ state.fake.setDelivery([+ {+ id: `send-${key}`,+ state: 'failed',+ errorCode: 'recipient_not_on_provider',+ },+ ]);+ expect(state.notify).toHaveBeenCalledWith(+ "This person isn't on WhatsApp, so this wasn't sent."+ );+ state.dispose();+ });+it('keeps a draft WhatsApp could not take, without sending', () => {const state = mountConversation(createFakeChat({diff --git a/crates/whatsmeow/src/errors.rs b/crates/whatsmeow/src/errors.rsindex dba02758fe..c174b57409 100644--- a/crates/whatsmeow/src/errors.rs+++ b/crates/whatsmeow/src/errors.rs@@ -116,6 +116,9 @@ pub enum ClientError {/// `ErrRecipientADJID`.#[error("message recipient must be a user JID with no device part")]RecipientAdJid,+ /// `ErrRecipientNotOnWhatsApp`.+ #[error("recipient is not on WhatsApp")]+ RecipientNotOnWhatsApp,/// `ErrServerReturnedError`.#[error("server returned error")]ServerReturnedError,diff --git a/crates/whatsmeow/src/send.rs b/crates/whatsmeow/src/send.rsindex 0c01e0f1ee..3ade0755a5 100644--- a/crates/whatsmeow/src/send.rs+++ b/crates/whatsmeow/src/send.rs@@ -203,9 +203,7 @@ impl Client {.map(|info| info.lid.clone()).unwrap_or_default();if to_lid.is_empty() {- return Err(ClientError::Other(- "no LID found for recipient from server".to_owned(),- ));+ return Err(ClientError::RecipientNotOnWhatsApp);}}extra_params.peer_recipient_pn = to.clone();diff --git a/services/whatsapp_session_service/src/outbound/whatsapp.rs b/services/whatsapp_session_service/src/outbound/whatsapp.rsindex a72a91b6c3..bf3b599b29 100644--- a/services/whatsapp_session_service/src/outbound/whatsapp.rs+++ b/services/whatsapp_session_service/src/outbound/whatsapp.rs@@ -474,6 +474,9 @@ fn rejected(error: &ClientError) -> Option<&'static str> {ClientError::RecipientAdJid| ClientError::BroadcastListUnsupported| ClientError::UnknownServer => Some("invalid_recipient"),+ ClientError::RecipientNotOnWhatsApp => Some("recipient_not_on_provider"),+ // Only the queries before the message (recipient lookups) are IQs.+ _ if error.is_iq_code(429) => Some("rate_limited"),_ => None,}}diff --git a/services/whatsapp_session_service/src/outbound/whatsapp/test.rs b/services/whatsapp_session_service/src/outbound/whatsapp/test.rsindex 31cc3b50a0..00984e358e 100644--- a/services/whatsapp_session_service/src/outbound/whatsapp/test.rs+++ b/services/whatsapp_session_service/src/outbound/whatsapp/test.rs@@ -551,3 +551,21 @@ fn session_errors_never_show_the_jids_of_an_iq_response() {assert!(!message.contains(phone), "{message}");}}++#[test]+fn a_recipient_not_on_whatsapp_or_a_rate_limited_lookup_is_rejected_not_unknown() {+ use whatsmeow::errors::{ClientError, IqError};++ assert_eq!(+ super::rejected(&ClientError::RecipientNotOnWhatsApp),+ Some("recipient_not_on_provider")+ );+ let rate_limited = ClientError::from(IqError::from_status(IqError::RATE_OVER_LIMIT))+ .wrap("failed to send usync query")+ .wrap("failed to get user info to fill LID cache");+ assert_eq!(super::rejected(&rate_limited), Some("rate_limited"));+ assert_eq!(+ super::rejected(&ClientError::Other("anything else".to_owned())),+ None+ );+}