whatsapp.bot

class whatsapp.bot.State(avaiable_states: list[tuple[~collections.abc.Callable, ~whatsapp.bot.STATE_TRIGGERS]] = <factory>, invalid_state: ~collections.abc.Callable = None)

Bases: object

State class to store handler triggers

avaiable_states: list[tuple[Callable, STATE_TRIGGERS]]

List of avaiable states

invalid_state: Callable = None

Triggered when don’t trigger any state

class whatsapp.bot.WhatsappBot(whatsapp_token: str, verify_token: str | None = None, endpoint: str = 'https://graph.facebook.com', api_version: str = 'v19.0', welcome_message: str = "Hello, I'm using python-whatsapp-wrapper!", flask_config: object | None = None, flask_app: ~flask.app.Flask | None = None, _is_running: bool = False, _server_queue: ~queue.Queue = <factory>, _state_handlers: dict[str, ~whatsapp.bot.State] = <factory>, _user_states: dict[str, str] = <factory>, _initial_state: dict[str, ~whatsapp.bot.State] | None = None, _can_run_empty: bool = False)

Bases: object

Whatsapp Bot class

add_invalid_state(state: str, on_invalid_state_func: Callable)

Adds a command to the invalid state handler. If none wait for a valid state

Parameters:
  • state – State name

  • on_invalid_state_func – function to handle state

Raises:

UnknownEvent – If state are not valid

add_new_state(state: USER_STATE, on_state_func: Callable, handler_trigger: str | MessageTypes | STATE_TRIGGERS)

Adds a new state to the bot.

Parameters:
  • state – state name

  • on_state_func – function to handle state

  • handler_trigger – triggers for state

Raises:

UnknownEvent – When don’t reache any trigger

api_version: str = 'v19.0'

Meta API version

property bearer_token: str

Returns the bearer token

create_app(config: object = None)

Creates a Flask app for bot

Parameters:

config – Flask config, defaults to None

Returns:

Flask app

endpoint: str = 'https://graph.facebook.com'

META API endpoint

enqueue_update(update: Incoming)

Enqueues an update, change this if you want to use a different queue (like redis).

Parameters:

update – Incoming message

external_endpoint(bot_number_id: str, service: str) str

Returns the external endpoint.

Parameters:

bot_number_id – The bot number ID.

Returns:

The external endpoint.

flask_app: Flask | None = None

Flask app (created by create_app method)

flask_config: object | None = None

Flask config from object

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
get_update() Incoming | None

Gets an update from the queue (In-memory, mongodb, redis etc).

Returns:

Incoming message

handle_message(request: Request)

Handles incoming messages from META or ignores

Parameters:

request – Request object

Raises:

UnknownEvent – When not a META API event

Returns:

A dict with status =’ok’ if POST else verify token

async process_update(incoming: Incoming)

Handle updates popped from queue.

Parameters:

incoming – Incoming message

Raises:

UnknownEvent – If state are not in state handlers

async run_forever(interval: float = 0.1)

Runs bot forever

Parameters:

interval – Interval to verify new incomings, defaults to 0.1

Raises:

EmptyState – If bot are empty of states

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
async send_message(message: dict[str, Any], bot_number_id: str, client: AsyncClient = None)

Sends a message.

Parameters:
  • message – Message (from object) as dict

  • bot_number_id – Bot number ID

start_webhook(host: str = '127.0.0.1', port: int = 8000, debug: bool = False, load_dot_env: bool = False, **server_options: dict[str, Any])

Starts the webhook server.

Parameters:
  • host – Server host, defaults to “127.0.0.1”

  • port – Server port, defaults to 8000

  • debug – Flask hot reload and other features, defaults to False

  • load_dot_env – Loads .env file, defaults to False

to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
verify_token: str | None = None

Verify token for set webhook url

webhook_verify_token(request: Request) str

Verifies webhook token

Parameters:

request – Incoming request

Raises:
Returns:

String challenge

welcome_message: str = "Hello, I'm using python-whatsapp-wrapper!"

Welcome message to send when user start a conversation

whatsapp_token: str

Whatsapp API token

whatsapp.config_account

class whatsapp.config_account.ProfileCommand(command_name: str, command_description: str)

Bases: object

command_description: str

Command description. Max 256 characters, emojis are not supported

command_name: str

Command name. Max 32 characters

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
class whatsapp.config_account.ProfileComponents(welcome_message: bool = False, commands: list[whatsapp.config_account.ProfileCommand] = <factory>, prompts: list[str] = <factory>)

Bases: object

add_command(command_name: str, command_description: str)

Add a command to a given Profile

Parameters:
  • command_name – Command name that will appear when user tap profile or keyboard

  • command_description – Command description for help user

commands: list[ProfileCommand]

Commands like ‘/comamnd’. Max 32 commands

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
async classmethod get_current_config(bot: WhatsappBot, bot_number_id: str, client: AsyncClient = None) dict[str, Any]
classmethod load_profile(bot: WhatsappBot, bot_number_id: str) Self
prompts: list[str]
classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
async set_current_config(bot: WhatsappBot, bot_number_id: str, client: AsyncClient = None) dict[str, Any]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
welcome_message: bool = False

Enable/disable welcome message

whatsapp.crypto

async whatsapp.crypto.decrypt_media_content(encryption_metadata: str, cdn_url: str = None, media_content: str = None, client: AsyncClient = None)

Downloads and decrypts encrypted media content from a given CDN URL.

This function verifies the SHA256 hash and HMAC of the encrypted content, decrypts the media using AES-CBC with a provided IV, and validates the decrypted content hash against the provided plaintext hash.

Parameters:
  • encryption_metadata – Dictionary containing encryption details (keys and hashes).

  • cdn_url – The URL to download the encrypted media content from. Ignored if media_content is provided.

  • media_content – Encrypted media content in bytes. If None, the content is downloaded from cdn_url.

  • client – Optional HTTP client for making the download request.

Returns:

The decrypted media content as a base64-encoded string.

Raises:

ValueError – If hash or HMAC validation fails, or if neither cdn_url nor media_content are provided.

whatsapp.crypto.decrypt_request(encrypted_flow_data_b64: str, encrypted_aes_key_b64: str, initial_vector_b64: str, meta_private_key: str, private_key_password: str) tuple[Any, bytes, bytes]

Decrypt an encrypted request containing AES-GCM encrypted data with an RSA-encrypted AES key.

This function uses the provided private RSA key to decrypt the AES key, then uses the AES-GCM algorithm to decrypt the main flow data.

Parameters:
  • encrypted_flow_data_b64 – Base64-encoded AES-GCM encrypted data

  • encrypted_aes_key_b64 – Base64-encoded RSA-encrypted AES key

  • initial_vector_b64 – Base64-encoded initialization vector (IV) used for AES-GCM

  • meta_private_key – RSA private key in PEM format as a string

  • private_key_password – Password for the RSA private key

Returns:

Tuple containing the decrypted data (as a dictionary), AES key, and IV

whatsapp.crypto.encrypt_response(response: dict[str, Any], aes_key: bytes, iv: bytes) str

Encrypt a response dictionary using AES-GCM with a modified initialization vector (IV).

The IV bytes are bitwise inverted, and the resulting AES-GCM ciphertext and authentication tag are concatenated and returned as a Base64-encoded string.

Parameters:
  • response – Dictionary containing the data to be encrypted

  • aes_key – AES encryption key in bytes

  • iv – Initialization vector (IV) in bytes, which will be inverted before use

Returns:

Base64-encoded string of the encrypted response including ciphertext and authentication tag

whatsapp.crypto.extract_public_key_from_private(private_key_pem: str, password: str) str

Extracts the RSA public key from a private key PEM and returns it as a PEM-formatted string.

Parameters:
  • private_key_pem – PEM-formatted private key as a string.

  • password – Password to decrypt the private key.

Returns:

Public key in PEM format as a string.

whatsapp.crypto.generate_rsa_private_key(password: str) str

Generates a private RSA key, encrypts it with Triple DES (DES-EDE3-CBC) and a password, and returns it as a PEM-formatted string.

Parameters:

password – Password to encrypt the private key.

Returns:

Encrypted private key in PEM format as a string.

whatsapp.error

exception whatsapp.error.EmptyState(message: str)

Bases: WhatsAppError

exception whatsapp.error.MissingParameters(message: str)

Bases: WhatsAppError

exception whatsapp.error.NotImplementedMsgType(message: str)

Bases: WhatsAppError

exception whatsapp.error.UnknownEvent(message: str)

Bases: WhatsAppError

exception whatsapp.error.VerificationFailed(message: str)

Bases: WhatsAppError

exception whatsapp.error.WhatsAppError(message: str)

Bases: Exception

message: str

whatsapp.file_handler

async whatsapp.file_handler.delete_media(bot: WhatsappBot, media_id: str) dict

Deletes a specific media item.

Parameters:
  • bot – The WhatsappBot instance with access token and API endpoint information.

  • media_id – The ID of the media item to delete.

Returns:

The response JSON indicating success.

async whatsapp.file_handler.download_media(bot: WhatsappBot, media_url: str) bytes

Downloads media from a given media URL.

Parameters:
  • bot – The WhatsappBot instance with access token and API endpoint information.

  • media_url – The URL for the media file to download.

Returns:

The binary content of the downloaded media file.

async whatsapp.file_handler.get_whatsapp_business_encryption(bot_number_id: str, bot: WhatsappBot) dict

Sends a GET request to retrieve WhatsApp Business Encryption information.

Parameters:
  • phone_number_id – The phone number ID for the WhatsApp Business account.

  • access_token – The access token for authenticating with the WhatsApp Business API.

Returns:

The response JSON from the API.

async whatsapp.file_handler.retrieve_media_info(bot: WhatsappBot, media_id: str) dict

Retrieves the URL for a specific media item.

Parameters:
  • bot – The WhatsappBot instance with access token and API endpoint information.

  • media_id – The ID of the media item.

Returns:

The response JSON with the media URL and metadata.

async whatsapp.file_handler.send_whatsapp_business_encryption(bot_number_id: str, bot: WhatsappBot, public_key: str) dict

Sends a POST request to the WhatsApp Business Encryption endpoint with the business public key. Used for whatsapp flows

Parameters:
  • phone_number_id – The phone number ID for the WhatsApp Business account.

  • access_token – The access token for authenticating with the WhatsApp Business API.

  • business_public_key – The public key to register with the WhatsApp Business encryption.

Returns:

The response JSON from the API.

async whatsapp.file_handler.upload_media(bot: WhatsappBot, bot_number_id: str, file_data: bytes | BytesIO, media_type: str) dict[str, str]

Uploads media to WhatsApp Business.

Parameters:
  • bot – The WhatsappBot instance with access token and API endpoint information.

  • bot_number_id – The bot number ID for the WhatsApp Business account.

  • file_path – Path to the file to be uploaded.

  • media_type – The MIME type of the file (e.g., “image/jpeg”).

Supported file formats, MIME types, and size limitations:

Audio Formats:
  • AAC: audio/aac (.aac, 16 MB)

  • AMR: audio/amr (.amr, 16 MB)

  • MP3: audio/mpeg (.mp3, 16 MB)

  • MP4 Audio: audio/mp4 (.m4a, 16 MB)

  • OGG Audio: audio/ogg (OPUS codecs only; base audio/ogg not supported) (.ogg, 16 MB)

Document Formats:
  • Text: text/plain (.txt, 100 MB)

  • Microsoft Excel (.xls): application/vnd.ms-excel (.xls, 100 MB)

  • Microsoft Excel (.xlsx): application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (.xlsx, 100 MB)

  • Microsoft Word (.doc): application/msword (.doc, 100 MB)

  • Microsoft Word (.docx): application/vnd.openxmlformats-officedocument.wordprocessingml.document (.docx, 100 MB)

  • Microsoft PowerPoint (.ppt): application/vnd.ms-powerpoint (.ppt, 100 MB)

  • Microsoft PowerPoint (.pptx): application/vnd.openxmlformats-officedocument.presentationml.presentation (.pptx, 100 MB)

  • PDF: application/pdf (.pdf, 100 MB)

Image Formats:
  • JPEG: image/jpeg (.jpeg, 5 MB)

  • PNG: image/png (.png, 5 MB)

Sticker Formats:
  • Animated Sticker (WebP): image/webp (.webp, 500 KB)

  • Static Sticker (WebP): image/webp (.webp, 100 KB)

Video Formats:
  • 3GPP: video/3gp (.3gp, 16 MB)

  • MP4 Video: video/mp4 (.mp4, 16 MB)

Returns:

The response JSON with the media ID.

whatsapp.messages

class whatsapp.messages.AddressMessage(id: str, timestamp: str, type: MessageTypes, from_: str, context: Context | None = None)

Bases: ReceivedMessage

Handle ask address messages

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
class whatsapp.messages.AskForLocationMessage(*, body: str)

Bases: object

Max body text size: 4096 characters

body: str

Text body of location request (Accepts URL link). Max 4096 characters

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
to_send(to: str, context: Context | dict[str, str] | None = None) dict[str, str]
class whatsapp.messages.AudioMessage(id: str, timestamp: str, type: MessageTypes, from_: str, context: Context | None = None, *, audio: DocumentMetadata, link: str | None = None)

Bases: ReceivedMessage

Send and receive audios.

Supoorted audio formats: aac, amr, mp3, mp4 audio, ogg (opus codecs, not audio/ogg) Max size: 16 MB

audio: DocumentMetadata

Audio metadata

property audio_id: str
classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A

Audio asset public url (not recommended)

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
classmethod to_send(to: str, audio_id: str = None, link: str = None, context: Context | dict[str, str] | None = None) dict[str, str]
class whatsapp.messages.ButtonUrlMessage(*, header: str, body: str, footer: str, button_display_text: str, button_url: str)

Bases: object

body: str

Body Text

button_display_text: str

Button text

button_url: str

URL that browser will open when user tap the button

footer: str

Message footer text

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
header: str

Header text

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
to_send(to: str, context: Context | dict[str, str] | None = None) dict[str, str]
class whatsapp.messages.ContactMessage(id: str, timestamp: str, type: MessageTypes, from_: str, context: Context | None = None, *, contacts: list[ReceivedContacts])

Bases: ReceivedMessage

Message with a list of Whatsapp Contacts, that contains infos like number, name, profile, picture etc. Can be saved or shared by user.

contacts: list[ReceivedContacts]
classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
classmethod to_send(to: str, contacts: list[ReceivedContacts], context: Context | dict[str, str] | None = None) dict[str, str]
class whatsapp.messages.ContactName(first_name: str, formatted_name: str, last_name: str | None = None, middle_name: str | None = None, suffix: str | None = None, prefix: str | None = None)

Bases: object

first_name: str

Customer first name

formatted_name: str

Customer name

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
last_name: str | None = None

Customer last name

middle_name: str | None = None

Customer middle name

prefix: str | None = None

Customer prefix, e.g Dr.

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
suffix: str | None = None

Customer suffix, e.g Esq.

to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
class whatsapp.messages.ContactPhone(phone: str, type: str, wa_id: str)

Bases: object

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
phone: str

Customer phone number

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
type: str

Phone number type

wa_id: str

Customer whatsapp ID

class whatsapp.messages.Contacts(wa_id: str, profile: dict[str, Any])

Bases: object

property customer_name

Customer’s name

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
profile: dict[str, Any]

Customer profile object (today has only name)

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
wa_id: str

Customer whatsapp ID (Can match customer phone number or not)

class whatsapp.messages.Context(from_: str, id: str, forwarded: bool | None = None, frequently_forwarded: bool | None = None)

Bases: object

forwarded: bool | None = None

True if the received message was been forwarded

frequently_forwarded: bool | None = None

True if the received message was been forwarded more than 5 times

from_: str

Customer whatsapp number

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
id: str

Message id (Used for replies for example)

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
class whatsapp.messages.Conversation(id: str, origin: dict[str, str], expiration_timestamp: str | None = None)

Bases: object

Information about the conversation

expiration_timestamp: str | None = None

Date when the conversation expires

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
id: str

Conversation ID

origin: dict[str, str]

Conversation category

property origin_type: Literal['authentication', 'marketing', 'utility', 'service', 'referral_conversion']

Convesation category (or entry point)

authentication: The conversation was opened by a business sending a ‘AUTHENTICATION’

marketing: The conversation was opened by a business sending a ‘MARKETING’

utility: The conversation was opened by a business sending a ‘UTILITY’

service: The conversation opened by a business replying to a customer within a customer service window

referral_conversion: Indicates a free entry point conversation

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
class whatsapp.messages.DocumentMessage(id: str, timestamp: str, type: MessageTypes, from_: str, context: Context | None = None, *, document: DocumentMetadata)

Bases: ReceivedMessage

Message that display a icon and can be downloaded by user when tapped

Max Size: 100 MB Supported MIMEs (message custom logo): - text/plain - application/vnd.ms-excel - application/vnd.openxmlformats-officedocument.spreadsheetml.sheet - application/msword - application/vnd.openxmlformats-officedocument.wordprocessingml.document - application/vnd.ms-powerpoint - application/vnd.openxmlformats-officedocument.presentationml.presentation - application/pdf

document: DocumentMetadata
property filename: str
classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
classmethod to_send(to: str, document_id: str = None, link: str = None, caption: str = None, filename: str = None, context: Context | dict[str, str] | None = None) dict[str, str]
class whatsapp.messages.DocumentMetadata(mime_type: str, sha256: str, id: str, filename: str | None = None, *, voice: bool | None = None, animated: bool | None = None)

Bases: object

animated: bool | None = None

Exclusive for sticker media

filename: str | None = None

Exclusive for document media

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
id: str

File Media ID (Only if using uploaded media, recommended)

mime_type: str

Document MIME type, used for magic bytes and logo

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
sha256: str

SHA-256 hash

to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
voice: bool | None = None

Exclusive for voice/audio media

class whatsapp.messages.Errors(code: int, title: str, message: str, error_data: dict[str, Any])

Bases: object

code: int

Error code. Example: ‘130429’

error_data: dict[str, Any]
property error_details

Describes the error

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
message: str

Error code with title. Example: ‘(#130429) Rate limit hit’

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
title: str

Error code title. Example: ‘Rate limit hit’

to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
class whatsapp.messages.FlowIncoming

Bases: object

alert_state: Literal['DEACTIVATED', 'ACTIVATED'] = Field(name=None,type=None,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=<dataclasses._MISSING_TYPE object>,_field_type=None)
availability: int = Field(name=None,type=None,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=<dataclasses._MISSING_TYPE object>,_field_type=None)
event: str = Field(name=None,type=None,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=<dataclasses._MISSING_TYPE object>,_field_type=None)
flow_id: str = Field(name=None,type=None,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=<dataclasses._MISSING_TYPE object>,_field_type=None)
message: str = Field(name=None,type=None,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=<dataclasses._MISSING_TYPE object>,_field_type=None)
threshold: int = Field(name=None,type=None,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=<dataclasses._MISSING_TYPE object>,_field_type=None)
class whatsapp.messages.FlowMessage(id: str, timestamp: str, type: MessageTypes, from_: str, context: Context | None = None)

Bases: ReceivedMessage

class whatsapp.messages.ImageMessage(id: str, timestamp: str, type: MessageTypes, from_: str, context: Context | None = None, *, image: DocumentMetadata, link: str | None = None, caption: str | None = None)

Bases: ReceivedMessage

Display a single image with an optional caption

caption: str | None = None

Image caption. Max 1024 characters

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
image: DocumentMetadata

Image metadata

property image_id: str

Audio asset public url (not recommended)

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
classmethod to_send(to: str, image_id: str = None, link: str = None, caption: str = None, context: Context | dict[str, str] | None = None) dict[str, str]
class whatsapp.messages.Incoming(messaging_product: Literal['whatsapp'], metadata: whatsapp.messages.Metadata, contacts: list[whatsapp.messages.Contacts] = <factory>, errors: list[whatsapp.messages.Errors] = <factory>, messages: list[whatsapp.messages.ReceivedMessage] = <factory>, statuses: list[whatsapp.messages.Statuses] = <factory>, _message_idx: int = 0, _status_idx: int = 0)

Bases: object

contacts: list[Contacts]

Information about who sents the message

errors: list[Errors]

Objects that describes errors

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
property message: ReceivedMessage

Message that will be handled now (Selected by _message_idx)

messages: list[ReceivedMessage]

Triggered when a customer updates their profile information or sends a message

messaging_product: Literal['whatsapp']

Product used to send the message. (Always whatsap)

metadata: Metadata

Business account webhook metadata

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
property status: Statuses

Status that will be handled now (Selected by _status_idx)

statuses: list[Statuses]

Triggered when a message is sent or delivered to a customer or he reads the message

to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
to_send()
class whatsapp.messages.InteractiveButtonsMessage(*, header: str, body: str, footer: str, buttons: list[whatsapp.messages.Item])

Bases: object

body: str

Body Text. Max 1024 characters

buttons: list[Item]
footer: str

Message footer text that supports emojis, markdown and links. Max 60 characters

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
header: str

Header text

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
to_send(to: str, context: Context | dict[str, str] | None = None) dict[str, str]
class whatsapp.messages.InteractiveListMessage(*, header: str, body: str, footer: str, button_title: str, sections: list[whatsapp.messages.Section])

Bases: object

body: str

Body Text

button_title: str

Button title

footer: str

Message footer text

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
header: str

Header text

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
sections: list[Section]

Min 1 and max 10 sections

to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
to_send(to: str, context: Context | dict[str, str] | None = None) dict[str, str]
class whatsapp.messages.InteractiveReply(id: str, timestamp: str, type: whatsapp.messages.MessageTypes, from_: str, context: whatsapp.messages.Context | None = None, *, interactive: dict[str, str] = None)

Bases: ReceivedMessage

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
interactive: dict[str, str] = None
property message_value: str
classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
classmethod to_send(to: str, *args, **kwargs)
property user_reply: Item
class whatsapp.messages.Item(id: str, title: str, description: str = '')

Bases: object

description: str = ''

Used for section item description (Optional)

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
id: str

Button unique ID

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
title: str

Button title

to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
class whatsapp.messages.Location(latitude: float, longitude: float, address: str | None = None, name: str | None = None, url: str | None = None)

Bases: object

address: str | None = None

location address (Optional)

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
latitude: float

Location latitude in decimal degrees.

longitude: float

Location longitude in decimal degrees.

name: str | None = None

location name (Optional)

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
url: str | None = None

Location guide url (Optional)

class whatsapp.messages.LocationMessage(id: str, timestamp: str, type: whatsapp.messages.MessageTypes, from_: str, context: whatsapp.messages.Context | None = None, *, location: whatsapp.messages.Location)

Bases: ReceivedMessage

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
location: Location
classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
classmethod to_send(to: str, latitude: str, longitude: str, address: str = None, name: str = None, context: Context | dict[str, str] | None = None)
class whatsapp.messages.MessageTypes(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: str, Enum

Whatsapp Business API message types

ADDRESS: str = 'address'
AUDIO: str = 'audio'
CONTACTS: str = 'contacts'
DOCUMENT: str = 'document'
FLOW: str = 'flow'
IMAGE: str = 'image'
INTERACTIVE: str = 'interactive'
LOCATION: str = 'location'
REACTION: str = 'reaction'
STICKER: str = 'sticker'
TEMPLATE: str = 'template'
TEXT: str = 'text'
VIDEO: str = 'video'
class whatsapp.messages.Metadata(display_phone_number: str, phone_number_id: str)

Bases: object

display_phone_number: str

Phone number that customer will see in chat

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
phone_number_id: str

Phone number id. Need to be used to respond an message

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
class whatsapp.messages.Pricing(category: Literal['authentication', 'marketing', 'utility', 'service', 'referral_conversion'], pricing_model: Literal['CBP'], billable: bool | None = None)

Bases: object

billable: bool | None = None

False if it’s a free message entry point

category: Literal['authentication', 'marketing', 'utility', 'service', 'referral_conversion']

Conversation category

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
pricing_model: Literal['CBP']

Pricing model type

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
class whatsapp.messages.ReactMessage(id: str, timestamp: str, type: MessageTypes, from_: str, context: Context | None = None, *, reaction: Reaction)

Bases: ReceivedMessage

Emoji reaction message to a specific message

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
reaction: Reaction
classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
classmethod to_send(to: str, message_id: str, emoji: str, context: Context | dict[str, str] | None = None) dict[str, str]
class whatsapp.messages.Reaction(message_id: str, emoji: str)

Bases: object

emoji: str

Escaped unicode emoji or emoji (e.g. 😀)

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
message_id: str

Message id

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
class whatsapp.messages.ReadMessage

Bases: object

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
classmethod to_send(message_id: str) dict[str, Any]
class whatsapp.messages.ReceivedContacts(name: whatsapp.messages.ContactName, phones: list[whatsapp.messages.ContactPhone])

Bases: object

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
name: ContactName

Contact name object

phones: list[ContactPhone]

Contact phone object

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
class whatsapp.messages.ReceivedMessage(id: str, timestamp: str, type: whatsapp.messages.MessageTypes, from_: str, context: whatsapp.messages.Context | None = None)

Bases: ABC

context: Context | None = None

Context object, if customer has replied a message

classmethod default_body_to_send(to: str, msg_type: MessageTypes, context: Context | dict[str, str] | None = None) dict[str, Any]
from_: str

Customer whatsapp number

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
id: str

Message id (Used for replies for example.)

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
timestamp: str

Unix timestamp

to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
abstract classmethod to_send(to: str, context: Context | dict[str, str] | None = None, *args, **kwargs) dict[str, str]
type: MessageTypes

Message Type (Specified in MessageTypes)

class whatsapp.messages.Section(title: str, rows: list[whatsapp.messages.Item] = <factory>)

Bases: object

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
rows: list[Item]

Section items

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
title: str

Section title

to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
class whatsapp.messages.Statuses(id: str, status: ~typing.Literal['delivered', 'read', 'sent'], timestamp: int, recipient_id: str, biz_opaque_callback_data: str | None = None, conversation: ~whatsapp.messages.Conversation | None = None, errors: list[~whatsapp.messages.Errors] = <factory>, pricing: ~whatsapp.messages.Pricing | None = None)

Bases: object

Triggered when a message are sent/delivered to a customer or the customer reads the delivered message

biz_opaque_callback_data: str | None = None

Arbitrary string

conversation: Conversation | None = None

Conversation info

errors: list[Errors]

List of objects describing errors

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
id: str

Message ID

pricing: Pricing | None = None

Pricing information

recipient_id: str

Customer’s WhatsApp ID. Can be used to respond a customer (Doesn’t match with phone number)

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
status: Literal['delivered', 'read', 'sent']

Message status

delivered: Webhook received when message was delivered

read: Webhook received when customer reads the message

sent: Webhook received when a business sends a message

timestamp: int

Message status Date

to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
class whatsapp.messages.StickerMessage(id: str, timestamp: str, type: MessageTypes, from_: str, context: Context | None = None, *, sticker: DocumentMetadata)

Bases: ReceivedMessage

Sends a sticker message (supports animated stickers)

property animated: bool
classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
sticker: DocumentMetadata
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
classmethod to_send(to: str, sticker_id: str = None, link: str = None, context: Context | dict[str, str] | None = None) dict[str, str]
class whatsapp.messages.TextMessage(id: str, timestamp: str, type: MessageTypes, from_: str, context: Context | None = None, *, text: dict[str, str])

Bases: ReceivedMessage

Text message. Contains information about sent and received texts. Shows a website preview if message has a url (startswith http:// or https://) and preview_url is True, the url will be previewed. Max text size: 4096 characters

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
property message_value: str
classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
text: dict[str, str]

Dict that contains message value

to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
classmethod to_send(to: str, message: str, preview_url: bool = None, context: Context | dict[str, str] | None = None) dict[str, str]

Send an text message.

Parameters:
  • to – Whatsapp number to send the message

  • message – Text message to send, max 4096 characters

  • preview_url – Show website preview if has an url (http/s) and is True, defaults to None

Returns:

Dictionary representing the reply message

class whatsapp.messages.VideoMessage(id: str, timestamp: str, type: MessageTypes, from_: str, context: Context | None = None, *, video: DocumentMetadata)

Bases: ReceivedMessage

Video message with an optinal caption.

Supoorted audio formats: 3gp and mp4 Max size: 16 MB

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
classmethod to_send(to: str, video_id: str = None, link: str = None, caption: str = None, context: Context | dict[str, str] | None = None) dict[str, str]

Creates a video reply message.

Parameters:
  • to – Recipient’s phone number.

  • video_id – Video ID, if available.

  • link – Video link, if available.

  • caption – Video caption, if available.

Returns:

Dictionary representing the reply message.

video: DocumentMetadata
class whatsapp.messages.WhatsappChanges(id: str, changes: list[whatsapp.messages.Incoming] = <factory>, time: int | None = None)

Bases: object

changes: list[Incoming]

Changed objects array

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
id: str

Whatsapp business ID

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
time: int | None = None

Unix timestamp (Used in flow changes)

to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
whatsapp.messages.map_received_msg_to_obj(messages: list[dict[str, Any]] | None) list[RECEIVED_MESSAGE_T]

Converts a list of received messages as dictionaries to respective message objects.

Parameters:

messages – List of received messages as dictionaries.

Raises:

NotImplementedMsgType – If message type is not supported.

Returns:

List of converted messages.

whatsapp.messages.register_message_type(msg_type: str) Callable

Decorator to register a message type to a class

Parameters:

msg_type – Message type to be registered

Returns:

Same object

whatsapp.utils

whatsapp.utils.middleware(f: Callable)

Decorator for normalize responses, handle exceptions.

Parameters:

f – View function

Returns:

Decorated function

whatsapp.utils.read_message(f: Callable)

Decorator read messages when state are reached

Parameters:

f – State handler function

Returns:

Decorated state handler function