The Profile feature provides methods for managing your own account’s display name, status text (about), and profile picture.
Access
Access profile operations through the client:
let profile = client.profile();
Methods
set_push_name
Set your display name (push name).
pub async fn set_push_name(&self, name: &str) -> Result<(), ProfileError>
Parameters:
name - The new display name (cannot be empty)
Updates the local device store, sends a presence stanza with the new name, and propagates the change via app state sync for cross-device synchronization.
Example:
client.profile().set_push_name("My Bot").await?;
The push name change takes effect immediately via presence, but app state sync may fail if keys aren’t available yet (e.g., right after pairing before initial sync completes).
set_status_text
Set your status text (about).
pub async fn set_status_text(&self, text: &str) -> Result<(), ProfileError>
Parameters:
text - The new status text
Sets the profile “About” text. This is different from ephemeral text status updates.
Example:
client.profile().set_status_text("Available 24/7").await?;
set_profile_picture
Set your profile picture.
pub async fn set_profile_picture(
&self,
image_data: Vec<u8>
) -> Result<SetProfilePictureResponse, ProfileError>
Parameters:
image_data - JPEG image bytes
Returns:
SetProfilePictureResponse - Contains the new picture ID
The image should already be properly sized/cropped by the caller. WhatsApp typically uses 640x640 images.
Example:
use std::fs;
let image_bytes = fs::read("profile.jpg")?;
let response = client.profile().set_profile_picture(image_bytes).await?;
println!("New picture ID: {:?}", response.id);
The image must be a valid JPEG. Other formats are not supported.
remove_profile_picture
Remove your profile picture.
pub async fn remove_profile_picture(&self) -> Result<SetProfilePictureResponse, ProfileError>
Returns:
SetProfilePictureResponse - Confirmation of removal
Example:
client.profile().remove_profile_picture().await?;
Since v0.6 the remove IQ omits the <picture/> child entirely, matching WA Web’s SendProfilePictureJob. Sending an empty <picture> child was rejected by some hosts.
Types
SetProfilePictureResponse
Response from profile picture operations.
pub struct SetProfilePictureResponse {
/// The new picture ID (or None if removed)
pub id: Option<String>,
}
Complete example
use whatsapp_rust::Client;
use std::sync::Arc;
use std::fs;
async fn setup_profile(client: &Arc<Client>) -> anyhow::Result<()> {
// Set display name
client.profile().set_push_name("My WhatsApp Bot").await?;
// Set status text
client.profile().set_status_text("Automated responses").await?;
// Set profile picture
let image_bytes = fs::read("bot_avatar.jpg")?;
let response = client.profile().set_profile_picture(image_bytes).await?;
if let Some(id) = response.id {
println!("Profile picture updated: {}", id);
}
Ok(())
}
Error handling
All methods return Result<T, ProfileError>:
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum ProfileError {
#[error(transparent)]
Iq(#[from] IqError),
#[error(transparent)]
Client(#[from] ClientError),
#[error("invalid argument: {0}")]
InvalidArgument(String),
#[error(transparent)]
Internal(#[from] anyhow::Error),
}
Common errors:
InvalidArgument — e.g., empty push name
Iq — server rejected the status text or picture IQ
Client(ClientError::NotLoggedIn) — not authenticated
Internal — network errors, encoding failures
use whatsapp_rust::ProfileError;
match client.profile().set_push_name("").await {
Ok(_) => println!("Name updated"),
Err(ProfileError::InvalidArgument(msg)) => eprintln!("Invalid: {}", msg),
Err(e) => eprintln!("Failed: {}", e),
}
See also
- Contacts - Get profile pictures for other users
- Presence - Set online/offline status