Common methods#
- property BaseUserUpdate.sender: str#
The WhatsApp ID of the sender. - Shortcut for
.from_user.wa_id.
- property BaseUserUpdate.message_id_to_reply: str#
The ID of the message to reply to.
If you want to
wa.send_xwithreply_to_message_idin order to reply to a message, use this property instead ofidto prevent errors.
- BaseUserUpdate.reply_text(text: str, header: str | None = None, footer: str | None = None, keyboard: Iterable[Button] | SectionList | None = None, quote: bool = False, preview_url: bool = False) str#
- Reply to the message with text.
Shortcut for
send_message()withtoandreply_to_message_id.
Example
>>> msg.reply_text( ... text="Hello from PyWa! (https://github.com/david-lev/pywa)", ... quote=True, ... )
Example with keyboard buttons:
>>> from pywa.types import Button >>> msg.reply_text( ... header="Hello from PyWa!", ... text="What can I help you with?", ... footer="Powered by PyWa", ... keyboard=[ ... Button("Help", data="help"), ... Button("About", data="about"), ... ], ... quote=True ... )
Example with a section list:
>>> from pywa.types import SectionList, Section, SectionRow >>> msg.reply_text( ... header="Hello from PyWa!", ... text="What can I help you with?", ... footer="Powered by PyWa", ... keyboard=SectionList( ... button_title="Choose an option", ... sections=[ ... Section( ... title="Help", ... rows=[ ... SectionRow( ... title="Help", ... callback_data="help", ... description="Get help with PyWa", ... ), ... SectionRow( ... title="About", ... callback_data="about", ... description="Learn more about PyWa", ... ), ... ], ... ), ... Section( ... title="Other", ... rows=[ ... SectionRow( ... title="GitHub", ... callback_data="github", ... description="View the PyWa GitHub repository", ... ), ... ], ... ), ... ], ... ), ... quote=True ... )
- Parameters:
text β The text to reply with (markdown allowed, max 4096 characters).
header β The header of the reply (if keyboard is provided, optional, up to 60 characters, no markdown allowed).
footer β The footer of the reply (if keyboard is provided, optional, up to 60 characters, markdown has no effect).
keyboard β The keyboard to send with the reply (optional).
quote β Whether to quote the replied message (default: False).
preview_url β Whether to show a preview of the URL in the message (if any).
- Returns:
The ID of the sent reply.
- BaseUserUpdate.reply_image(image: str | bytes | BinaryIO, caption: str | None = None, body: str | None = None, footer: str | None = None, buttons: Iterable[Button] | None = None, quote: bool = False) str#
- Reply to the message with an image.
Shortcut for
send_image()withtoandreply_to_message_id.Images must be 8-bit, RGB or RGBA.
Example
>>> msg.reply_image( ... image="https://example.com/image.png", ... caption="This is an image!", ... quote=True, ... )
- Parameters:
image β The image to reply with (either a media ID, URL, file path, bytes, or an open file object).
caption β The caption of the image (optional, markdown allowed).
body β The body of the reply (optional, up to 1024 characters, markdown allowed, if buttons are provided and body is not provided, caption will be used as the body)
footer β The footer of the reply (if buttons is provided, optional, markdown has no effect).
buttons β The buttons to send with the image (optional).
quote β Whether to quote the replied message (default: False).
- Returns:
The ID of the sent reply.
- BaseUserUpdate.reply_video(video: str | bytes | BinaryIO, caption: str | None = None, body: str | None = None, footer: str | None = None, buttons: Iterable[Button] | None = None, quote: bool = False) str#
- Reply to the message with a video.
Shortcut for
send_video()withtoandreply_to_message_id.Only H.264 video codec and AAC audio codec is supported.
Videos with a single audio stream or no audio stream are supported.
Example
>>> msg.reply_video( ... video="https://example.com/video.mp4", ... caption="This is a video", ... quote=True, ... )
- Parameters:
video β The video to reply with (either a media ID, URL, file path, bytes, or an open file object).
caption β The caption of the video (optional, markdown allowed).
body β The body of the reply (optional, up to 1024 characters, markdown allowed, if buttons are provided and body is not provided, caption will be used as the body)
footer β The footer of the reply (if buttons is provided, optional, markdown has no effect).
buttons β The buttons to send with the video (optional).
quote β Whether to quote the replied message (default: False).
- Returns:
The ID of the sent reply.
- BaseUserUpdate.reply_audio(audio: str | bytes | BinaryIO) str#
- Reply to the message with an audio.
Shortcut for
send_audio()withtoandreply_to_message_id.
Example
>>> msg.reply_audio( ... audio='https://example.com/audio.mp3', ... )
- Parameters:
audio β The audio file to reply with (either a media ID, URL, file path, bytes, or an open file object).
- Returns:
The ID of the sent message.
- BaseUserUpdate.reply_document(document: str | bytes | BinaryIO, filename: str | None = None, caption: str | None = None, body: str | None = None, footer: str | None = None, buttons: Iterable[Button] | None = None, quote: bool = False) str#
- Reply to the message with a document.
Shortcut for
send_document()withtoandreply_to_message_id.
Example
>>> msg.reply_document( ... document="https://example.com/example_123.pdf", ... filename="example.pdf", ... caption="Example PDF", ... quote=True, ... )
- Parameters:
document β The document to reply with (either a media ID, URL, file path, bytes, or an open file object).
filename β The filename of the document (optional, The extension of the filename will specify what format the document is displayed as in WhatsApp).
caption β The caption of the document (optional).
body β The body of the reply (optional, up to 1024 characters, markdown allowed, if buttons are provided and body is not provided, caption will be used as the body)
footer β The footer of the reply (if buttons is provided, optional, markdown has no effect).
buttons β The buttons to send with the document (optional).
quote β Whether to quote the replied message (default: False).
- Returns:
The ID of the sent reply.
- BaseUserUpdate.reply_location(latitude: float, longitude: float, name: str | None = None, address: str | None = None) str#
- Reply to the message with a location.
Shortcut for
send_location()withtoandreply_to_message_id.
Example
>>> msg.reply_location( ... latitude=37.4847483695049, ... longitude=--122.1473373086664, ... name='WhatsApp HQ', ... address='Menlo Park, 1601 Willow Rd, United States', ... )
- Parameters:
latitude β The latitude of the location.
longitude β The longitude of the location.
name β The name of the location (optional).
address β The address of the location (optional).
- Returns:
The ID of the sent reply.
- BaseUserUpdate.reply_contact(contact: Contact | Iterable[Contact], quote: bool = False) str#
- Reply to the message with a contact/s.
Shortcut for
send_contact()withtoandreply_to_message_id.
Example
>>> from pywa.types import Contact >>> msg.reply_contact( ... contact=Contact( ... name=Contact.Name(formatted_name='David Lev', first_name='David'), ... phones=[Contact.Phone(phone='1234567890', wa_id='1234567890', type='MOBILE')], ... emails=[Contact.Email(email='test@test.com', type='WORK')], ... urls=[Contact.Url(url='https://exmaple.com', type='HOME')], ... ), ... quote=True, ... )
- Parameters:
contact β The contact/s to send.
quote β Whether to quote the replied message (default: False).
- Returns:
The ID of the sent reply.
- BaseUserUpdate.reply_sticker(sticker: str | bytes | BinaryIO) str#
- Reply to the message with a sticker.
Shortcut for
send_sticker()withtoandreply_to_message_id.A static sticker needs to be 512x512 pixels and cannot exceed 100 KB.
An animated sticker must be 512x512 pixels and cannot exceed 500 KB.
Example
>>> msg.reply_sticker( ... sticker='https://example.com/sticker.webp', ... )
- Parameters:
sticker β The sticker to reply with (either a media ID, URL, file path, bytes, or an open file object).
- Returns:
The ID of the sent reply.
- BaseUserUpdate.reply_template(template: Template, quote: bool = False) str#
Reply to the message with a template.
β Shortcut for
send_template()withtoandreply_to_message_id.Example
>>> from pywa.types import Template as Temp >>> wa = WhatsApp(...) >>> wa.send_template( ... to='1234567890', ... template=Temp( ... name='buy_new_iphone_x', ... language=Temp.Language.ENGLISH_US, ... header=Temp.TextValue(value='15'), ... body=[ ... Temp.TextValue(value='John Doe'), ... Temp.TextValue(value='WA_IPHONE_15'), ... Temp.TextValue(value='15%'), ... ], ... buttons=[ ... Temp.UrlButtonValue(value='iphone15'), ... Temp.QuickReplyButtonData(data='unsubscribe_from_marketing_messages'), ... Temp.QuickReplyButtonData(data='unsubscribe_from_all_messages'), ... ], ... ), ... )
Example for Authentication Template:
>>> from pywa.types import Template as Temp >>> msg.reply_template( ... template=Temp( ... name='auth_with_otp', ... language=Temp.Language.ENGLISH_US, ... buttons=Temp.OTPButtonCode(code='123456'), ... ), ... quote=True ... )
- Parameters:
template β The template to send.
quote β Whether to quote the replied message (default: False).
- Returns:
The ID of the sent reply.
Raises:
- BaseUserUpdate.reply_catalog(body: str, footer: str | None = None, thumbnail_product_sku: str | None = None, quote: bool = False) str#
- Reply to the message with a catalog.
Shortcut for
send_catalog()withtoandreply_to_message_id.
Example
>>> msg.reply_catalog( ... body='This is a catalog', ... footer='Powered by PyWa', ... thumbnail_product_sku='SKU123', ... )
- Parameters:
body β Text to appear in the message body (up to 1024 characters).
footer β Text to appear in the footer of the message (optional, up to 60 characters).
thumbnail_product_sku β The thumbnail of this item will be used as the messageβs header image (optional, if not provided, the first item in the catalog will be used).
quote β Whether to quote the replied message (default: False).
- Returns:
The ID of the sent reply.
- BaseUserUpdate.reply_product(catalog_id: str, sku: str, body: str | None = None, footer: str | None = None, quote: bool = False) str#
- Reply to the message with a product.
Shortcut for
send_product()withtoandreply_to_message_id.To reply with multiple products, use
reply_products().
- Parameters:
catalog_id β The ID of the catalog to send the product from. (To get the catalog ID use
get_commerce_settings()or in the Commerce Manager).sku β The product SKU to send.
body β Text to appear in the message body (up to 1024 characters).
footer β Text to appear in the footer of the message (optional, up to 60 characters).
quote β Whether to quote the replied message (default: False).
- Returns:
The ID of the sent reply.
- BaseUserUpdate.reply_products(catalog_id: str, product_sections: Iterable[ProductsSection], title: str, body: str, footer: str | None = None, quote: bool = False) str#
- Reply to the message with a product.
Shortcut for
send_products()withtoandreply_to_message_id.To reply with multiple products, use
reply_products().
Example
>>> from pywa.types import ProductsSection >>> msg.reply_products( ... catalog_id='1234567890', ... title='Tech Products', ... body='Check out our products!', ... product_sections=[ ... ProductsSection( ... title='Smartphones', ... skus=['IPHONE12', 'GALAXYS21'], ... ), ... ProductsSection( ... title='Laptops', ... skus=['MACBOOKPRO', 'SURFACEPRO'], ... ), ... ], ... footer='Powered by PyWa', ... quote=True, ... )
- Parameters:
catalog_id β
The ID of the catalog to send the product from (To get the catalog ID use
get_commerce_settings()or in the Commerce Manager).product_sections β The product sections to send (up to 30 products across all sections).
title β The title of the product list (up to 60 characters).
body β Text to appear in the message body (up to 1024 characters).
footer β Text to appear in the footer of the message (optional, up to 60 characters).
quote β Whether to quote the replied message (default: False).
- Returns:
The ID of the sent reply.
- BaseUserUpdate.react(emoji: str) str#
- React to the message with an emoji.
Shortcut for
send_reaction()withtoandmessage_id.
Example
>>> msg.react('π')
- Parameters:
emoji β The emoji to react with.
- Returns:
The ID of the sent reaction.
- BaseUserUpdate.unreact() str#
- Remove the reaction from the message.
Shortcut for
remove_reaction()withtoandmessage_id.
Example
>>> msg.unreact()
- Returns:
The ID of the sent unreaction.
- BaseUserUpdate.mark_as_read() bool#
- Mark the message as read.
Shortcut for
mark_message_as_read()withmessage_id.
- Returns:
Whether it was successful.