Skip to main content

send_message

Send a message to a chat.
pub async fn send_message(
    &self,
    to: Jid,
    message: wa::Message,
) -> Result<String, anyhow::Error>
to
Jid
required
Recipient JID. Can be:
  • Direct message: 15551234567@s.whatsapp.net
  • Group: 120363040237990503@g.us
  • Newsletter: 120363999999999999@newsletter
message
wa::Message
required
Protobuf message to send. Set one of the message fields:
  • conversation - Plain text message
  • extended_text_message - Text with formatting/links
  • image_message - Image with caption
  • video_message - Video with caption
  • document_message - Document/file
  • audio_message - Audio/voice note
  • sticker_message - Sticker
  • location_message - GPS location
  • contact_message - Contact card
message_id
String
Unique message ID generated for this message. Use this ID to track delivery receipts and edit/revoke the message.

Example: Text Message

use waproto::whatsapp as wa;

let message = wa::Message {
    conversation: Some("Hello, world!".to_string()),
    ..Default::default()
};

let message_id = client.send_message(
    "15551234567@s.whatsapp.net".parse()?,
    message
).await?;

println!("Message sent with ID: {}", message_id);

Example: Image with Caption

use waproto::whatsapp as wa;

// First upload the image
let upload_result = client.upload(image_bytes, MediaType::Image).await?;

let message = wa::Message {
    image_message: Some(Box::new(wa::message::ImageMessage {
        url: Some(upload_result.url),
        direct_path: Some(upload_result.direct_path),
        media_key: Some(upload_result.media_key),
        file_enc_sha256: Some(upload_result.file_enc_sha256),
        file_sha256: Some(upload_result.file_sha256),
        file_length: Some(upload_result.file_length),
        caption: Some("Check out this image!".to_string()),
        mimetype: Some("image/jpeg".to_string()),
        ..Default::default()
    })),
    ..Default::default()
};

let message_id = client.send_message(chat_jid, message).await?;

send_message_with_options

Send a message with additional customization options.
pub async fn send_message_with_options(
    &self,
    to: Jid,
    message: wa::Message,
    options: SendOptions,
) -> Result<String, anyhow::Error>
to
Jid
required
Recipient JID
message
wa::Message
required
Protobuf message to send
options
SendOptions
required
Additional send options (see below)
message_id
String
Unique message ID

SendOptions

Options for customizing message sending behavior.
pub struct SendOptions {
    /// Extra XML nodes to add to the message stanza
    pub extra_stanza_nodes: Vec<Node>,
}
extra_stanza_nodes
Vec<Node>
default:"[]"
Additional XML nodes to include in the message stanza. Used for advanced protocol features like quoted replies, mentions, or custom metadata.

Example: Send with Custom Options

use wacore_binary::builder::NodeBuilder;

let options = SendOptions {
    extra_stanza_nodes: vec![
        NodeBuilder::new("custom-tag")
            .attr("key", "value")
            .build()
    ],
};

let message_id = client.send_message_with_options(
    chat_jid,
    message,
    options
).await?;

revoke_message

Delete a message for everyone in the chat (revoke). This sends a revoke protocol message that removes the message for all participants. The message will show as “This message was deleted” for recipients.
pub async fn revoke_message(
    &self,
    to: Jid,
    message_id: impl Into<String>,
    revoke_type: RevokeType,
) -> Result<(), anyhow::Error>
to
Jid
required
Chat JID (direct message or group)
message_id
String
required
ID of the message to delete (from send_message return value)
revoke_type
RevokeType
required
Who is revoking the message:
  • RevokeType::Sender - Delete your own message
  • RevokeType::Admin { original_sender } - Admin deleting another user’s message in a group

RevokeType

Specifies who is revoking (deleting) the message.
pub enum RevokeType {
    /// The message sender deleting their own message
    Sender,
    /// A group admin deleting another user's message
    /// `original_sender` is the JID of the user who sent the message
    Admin { original_sender: Jid },
}
Sender
variant
Default variant. Use when deleting your own message. Works in both DMs and groups.
Admin
variant
Use when a group admin is deleting another user’s message. Only valid in groups. Requires original_sender JID.

Example: Revoke Own Message

// Send a message
let message_id = client.send_message(
    chat_jid,
    message
).await?;

// Delete it (sender revoke)
client.revoke_message(
    chat_jid,
    &message_id,
    RevokeType::Sender
).await?;

Example: Admin Revoke in Group

use wacore_binary::jid::Jid;

// Admin deleting another user's message
let original_sender: Jid = "15551234567@s.whatsapp.net".parse()?;

client.revoke_message(
    group_jid,
    &message_id,
    RevokeType::Admin { original_sender }
).await?;
Admin revoke is only valid for group chats. Attempting to use it in a direct message will return an error.

Message Types

The wa::Message protobuf supports various message types. Set exactly one of these fields:

Text Messages

conversation
String
Simple text message without formatting
extended_text_message
ExtendedTextMessage
Text with formatting, links, quoted replies, or mentionsKey fields:
  • text - Message text
  • contextInfo - Quoted message, mentions
  • previewType - Link preview behavior

Media Messages

image_message
ImageMessage
Image with optional caption. Upload the image first using client.upload(), then populate:
  • url, direct_path, media_key, file_enc_sha256, file_sha256, file_length
  • caption - Image caption
  • mimetype - e.g., "image/jpeg"
video_message
VideoMessage
Video with optional caption. Same upload pattern as images.
audio_message
AudioMessage
Audio file or voice note:
  • ptt - Set to true for voice notes (Push-To-Talk)
  • mimetype - e.g., "audio/ogg; codecs=opus"
document_message
DocumentMessage
Document/file with metadata:
  • file_name - Original filename
  • mimetype - File MIME type
  • caption - Optional description
sticker_message
StickerMessage
Sticker image (WebP format)

Other Messages

location_message
LocationMessage
GPS location with latitude, longitude, and optional name/address
contact_message
ContactMessage
Contact card with vCard data
contacts_array_message
ContactsArrayMessage
Multiple contact cards
live_location_message
LiveLocationMessage
Real-time location sharing
reaction_message
ReactionMessage
Emoji reaction to another message

Example: Extended Text with Quote

use waproto::whatsapp as wa;

let message = wa::Message {
    extended_text_message: Some(Box::new(wa::message::ExtendedTextMessage {
        text: Some("Reply to your message".to_string()),
        context_info: Some(wa::ContextInfo {
            stanza_id: Some(quoted_message_id),
            participant: Some(quoted_sender_jid.to_string()),
            quoted_message: Some(Box::new(quoted_message)),
            ..Default::default()
        }),
        ..Default::default()
    })),
    ..Default::default()
};