Others#
- class pywa.types.sent_update.SentMessage#
Represents a message that was sent to WhatsApp user.
- Variables:
id β The ID of the message.
to_user β The user the message was sent to.
from_phone_id β The WhatsApp ID of the sender who sent the message.
input (str) β The input (phone number) of the recipient.
- class pywa.types.sent_update.SentTemplate#
Bases:
SentMessageRepresents a template message that was sent to WhatsApp user.
- Variables:
id β The ID of the message.
to_user β The user the message was sent to.
from_phone_id β The WhatsApp ID of the sender who sent the message.
status (SentTemplateStatus | None) β The status of the sent template.
input β The input (phone number) of the recipient.
- class pywa.types.sent_update.SentMediaMessage#
Bases:
SentMessageRepresents a media message that was sent to WhatsApp user.
- Variables:
id β The ID of the message.
to_user β The user the message was sent to.
from_phone_id β The WhatsApp ID of the sender who sent the message.
input β The input (phone number) of the recipient.
uploaded_media (Media | None) β The media that was uploaded and sent in the message (only available if the media was not Media ID or URL).
- class pywa.types.sent_update.SentVoiceMessage#
Bases:
SentMediaMessageRepresents a voice message that was sent to WhatsApp user.
- Variables:
id β The ID of the message.
to_user β The user the message was sent to.
from_phone_id β The WhatsApp ID of the sender who sent the message.
input β The input (phone number) of the recipient.
uploaded_media β The media that was uploaded and sent in the message (only available if the media was not Media ID or URL).
- class pywa.types.sent_update.SentLocationRequest#
Bases:
SentMessageRepresents a location request message that was sent to WhatsApp user.
- Variables:
id β The ID of the message.
to_user β The user the message was sent to.
from_phone_id β The WhatsApp ID of the sender who sent the message.
input β The input (phone number) of the recipient.
- class pywa.types.sent_update.SentReaction#
Bases:
SentMessageRepresents a reaction message that was sent to WhatsApp user.
- Variables:
id β The ID of the reaction.
message_id (str) β The ID of the message that was reacted/unreacted to.
to_user β The user the message was sent to.
from_phone_id β The WhatsApp ID of the sender who sent the message.
input β The input (phone number) of the recipient.
- class pywa.types.sent_update.SentTemplateStatus#
Represents the status of a sent template.
Read more about template pacing on developers.facebook.com.
- Variables:
ACCEPTED β The template was accepted.
HELD_FOR_QUALITY_ASSESSMENT β The template was held for quality assessment.
- class pywa.types.others.SuccessResult#
Represents a simple success result.
This is used for operations that do not return any data, but only indicate success or failure.
You can use this class to check if an operation was successful or not:
>>> wa = WhatsApp(...) >>> if wa.update_template(...): # update_template returns SuccessResult so we can check it directly ... print("Template updated successfully")
- Variables:
success (bool) β Whether the operation was successful.
- class pywa.types.others.Result#
This class is used to handle paginated results from the WhatsApp API. You can iterate over the results, and also access the next and previous pages of results.
When using the
next()orprevious()methods, the results are returned as a new instance of theResultclass.You can access the cursors using the
beforeandafterproperties and use them later in thePaginationobject.
Example
>>> from pywa import WhatsApp, types >>> wa = WhatsApp(...) >>> res = wa.get_blocked_users(pagination=types.Pagination(limit=100)) >>> for user in res: ... print(user.name, user.wa_id) ... >>> if res.has_next: ... next_res = res.next() ... >>> print(res.all())
- property before: str | None#
Cursor that points to the start of the page of data that has been returned.
- property after: str | None#
Cursor that points to the end of the page of data that has been returned.
- next()#
Get the next page of results. if there is no next page, it returns empty Result.
Check if there is a next page using the
has_nextproperty before calling this method.
- Return type:
Result[_T]
- previous()#
Get the previous page of results. if there is no previous page, it returns empty Result.
Check if there is a previous page using the
has_previousproperty before calling this method.
- Return type:
Result[_T]
- all(*, sleep=0.0)#
Get all results from the current page, previous pages, and next pages.
Make sure to provide higher limit in the
Paginationparameter to avoid hitting rate limits.Also consider using the
sleepparameter to avoid hitting rate limits.
- class pywa.types.others.Pagination#
Represents pagination parameters for fetching data.
See Paginated Results.
Cursor-based Pagination
Cursor-based pagination is the most efficient method of paging and should always be used when possible. A cursor refers to a random string of characters which marks a specific item in a list of data. The cursor will always point to the item, however it will be invalidated if the item is deleted or removed. Therefore, your app shouldnβt store cursors or assume that they will be valid in the future.
Donβt store cursors. Cursors can quickly become invalid if items are added or deleted.
Time-based Pagination
Time pagination is used to navigate through results data using Unix timestamps which point to specific times in a list of data.
For consistent results, specify both since and until parameters. Also, it is recommended that the time difference is a maximum of 6 months.
Offset-based Pagination
Offset pagination can be used when you do not care about chronology and just want a specific number of objects returned. Only use this if the edge does not support cursor or time-based pagination. Note that if new objects are added to the list of items being paged, the contents of each offset-based page will change.
Offset based pagination is not supported for all API calls. To get consistent results, we recommend you to paginate using the previous/next links we return in the response.
- Variables:
before (str | None) β This is the cursor that points to the start of the page of data that has been returned.
after (str | None) β This is the cursor that points to the end of the page of data that has been returned.
limit (int | None) β This is the maximum number of objects that may be returned. A query may return fewer than the value of limit due to filtering. Do not depend on the number of results being fewer than the limit value to indicate that your query reached the end of the list of data, use the
has_nextinstead as described below. For example, if you set limit to10and9results are returned, there may be more data available, but one item was removed due to privacy filtering. Some edges may also have a maximum on the limit value for performance reasons.offset (int | None) β This offsets the start of each page by the number specified.
until (int | datetime.datetime | None) β A Unix timestamp or datetime obj value that points to the end of the range of time-based data.
since (int | datetime.datetime | None) β A Unix timestamp or datetime obj value that points to the start of the range of time-based data.
- class pywa.types.others.BusinessVerificationStatus#
Represents the business verification status.
- Variables:
EXPIRED β The business verification has expired.
FAILED β The business verification has failed.
INELIGIBLE β The business is not eligible for verification.
NOT_VERIFIED β The business is not verified.
PENDING β The business verification is pending.
PENDING_NEED_MORE_INFO β The business verification is pending and needs more information.
PENDING_SUBMISSION β The business verification is pending submission.
REJECTED β The business verification has been rejected.
REVOKED β The business verification has been revoked.
VERIFIED β The business is verified.
- class pywa.types.others.MarketingMessagesLiteAPIStatus#
Represents the WhatsApp Business Accountβs status for onboarding onto Marketing Messages Lite.
- Variables:
INELIGIBLE β The WABA has not met all eligibility requirements.
ELIGIBLE β The WABA has met all eligibility requirements.
ONBOARDED β The WABA is eligible to use MM Lite API and has signed MM Lite Terms of Service, has a valid payment method attached, and is linked to an Ad account.
UNKNOWN β An unknown status. Please contact support for assistance.
- class pywa.types.others.MarketingMessagesOnboardingStatus#
Represents the WhatsApp Business Accountβs status for onboarding onto Marketing Messages Lite API.
- Variables:
INELIGIBLE_ON_BEHALF_OF_WABA β The WhatsApp Business Account (βWABAβ) uses the βOBOβ model which is not supported. You must either first transfer ownership of the WABA to the customer or onboard using the Intent API.
INELIGIBLE_INACTIVE_OR_RESTRICTED β The WhatsApp Business Account is inactive or is restricted from messaging due to a policy enforcement issue.
INELIGIBLE_COUNTRY_NOT_SUPPORTED β The WhatsApp Business Account is in a region that does not support the MM Lite API.
INELIGIBLE_USING_WHATSAPP_BUSINESS_APP β The WhatsApp Business phone number is being used within the WhatsApp Business app.
ELIGIBLE β WhatsApp Business Account is eligible to onboard and use the MM Lite API.
PENDING_VALID_PAYMENT_METHOD β The WhatsApp Business Account requires setting up a valid payment method.
PENDING_INTERNAL_SETUP β WhatsApp Business Account is in the configuration process of using the MM Lite API and requires no further action from the business customer or partner.
ONBOARDED β The WhatsApp Business Account has successfully onboarded and is ready to use the MM Lite API.
- class pywa.types.others.BusinessProfile#
Represents a business profile.
- Variables:
about (str) β This text appears in the businessβs profile, beneath its profile image, phone number, and contact buttons.
address (str | None) β Address of the business. Character limit 256.
description (str | None) β Description of the business. Character limit 512.
email (str | None) β The contact email address (in valid email format) of the business. Character limit 128.
industry (pywa.types.others.Industry) β The industry of the business.
profile_picture_url (str | None) β URL of the profile picture that was uploaded to Meta.
websites (tuple[str, ...] | None) β The URLs associated with the business. For instance, a website, Facebook Page, or Instagram. There is a maximum of 2 websites with a maximum of 256 characters each.
- class pywa.types.others.BusinessPhoneNumber#
Represents a WhatsApp Business Phone Number.
See WhatsApp Business Phone Number.
- Variables:
id (str) β The ID of the phone number.
verified_name (str | None) β The name that appears in WhatsApp Manager and WhatsApp client chat thread headers, chat lists, and profile, if display criteria is met.
display_phone_number (str | None) β International format representation of the phone number.
conversational_automation (pywa.types.others.ConversationalAutomation | None) β Conversational Automation feature config for this phone number.
status (str | None) β The operating status of the phone number (eg. connected, rate limited, warned).
quality_rating (str | None) β The quality rating of the phone number.
quality_score (dict[str, str] | None) β Quality score of the phone.
webhook_configuration (dict[str, str] | None) β The webhook configuration of the phone number.
name_status (str | None) β The status of the name review.
new_name_status (str | None) β The status of the review of the new name requested.
code_verification_status (str | None) β Indicates the phone numberβs one-time password (OTP) verification status. Values can be NOT_VERIFIED, VERIFIED, or EXPIRED. Only phone numbers with a VERIFIED status can be registered. See Manage Phone Numbers and Certificates.
account_mode (str | None) β The account mode of the phone number. See Filtering Phone Numbers.
is_on_biz_app (bool) β Indicates if the customerβs business phone number is registered for WhatsApp Business app.
is_official_business_account (bool) β Indicates if phone number is associated with an Official Business Account.
is_pin_enabled (bool) β Returns True if a pin for two-step verification is enabled.
is_preverified_number (bool) β Returns true if the phone number was pre-verified
messaging_limit_tier (str | None) β Current messaging limit tier.
search_visibility (str | None) β The availability of the phone_number in the WhatsApp Business search.
platform_type (str | None) β Platform the business phone number is registered with. Values can be CLOUD_API, ON_PREMISE, or NOT_APPLICABLE. If NOT_APPLICABLE, the number is not registered with Cloud API or On-Premises API.
throughput (dict[str, str] | None) β The business phone numberβs Cloud API throughput level. See Phone Number Throughput.
eligibility_for_api_business_global_search (str | None) β Status of eligibility in the API Business Global Search.
health_status (dict | None) β health_status
certificate (str | None) β Certificate of the phone number
new_certificate (str | None) β Certificate of the new name that was requested
last_onboarded_time (str | None) β Indicates when the user added the business phone number to their WhatsApp Business Account (when the user completed the Embedded Signup flow).
- class pywa.types.calls.BusinessPhoneNumberSettings#
Represents the settings of a WhatsApp Business Phone Number.
- Variables:
calling (pywa.types.calls.CallingSettings | None) β The calling settings of the phone number.
storage_configuration (pywa.types.others.StorageConfiguration | None) β The storage configuration for the phone number.
- class pywa.types.others.StorageConfiguration#
Local storage offers an additional layer of data management control, by giving you the option to specify where your message data is stored at rest. If your company is in a regulated industry such as finance, government, or healthcare, you may prefer to have your message data stored in a specific country when at rest because of regulatory or company policies.
Read more at developers.facebook.com.
- Variables:
status (pywa.types.others.StorageStatus) β The storage status of the WhatsApp Business Phone Number.
data_localization_region (str | None) β The region where message data is stored at rest. Required if status is
IN_COUNTRY_STORAGE_ENABLED.retention_minutes (int | None) β The duration (in minutes) for which message data is retained. Required if status is
NO_STORAGE_ENABLED.
- class pywa.types.others.ConversationalAutomation#
Represents a conversational automation.
See Conversational Automation.
- Variables:
id (str) β The ID of the WhatsApp Business Phone Number.
chat_opened_enabled (bool) β Whether the welcome message is enabled (if so, you can listen to the
ChatOpenedevent).ice_breakers (tuple[str] | None) β See Ice Breakers.
commands (tuple[pywa.types.others.Command, ...] | None) β The commands.
- class pywa.types.others.QRCode#
Customers can scan a QR code from their phone to quickly begin a conversation with your business. The WhatsApp Business Management API allows you to create and access these QR codes and associated short links.
- Variables:
code (str) β The code of the QR code.
prefilled_message (str) β The message that will be prefilled when the user starts a conversation with the business using the QR code.
deep_link_url (str) β The deep link URL of the QR code.
qr_image_url (str | None) β The URL of the QR code image (return only when creating a QR code).
- fetch_image(image_type)#
Returns the same QRCode object with the specified image type.
Useful for getting different image formats or if the original QR code was retrieved without an image.
>>> from pywa import WhatsApp >>> wa = WhatsApp(...) >>> qr_codes = wa.get_qr_codes() # image_type is None by default for faster retrieval >>> svg_qr = qr_codes[0].fetch_image(QRCodeImageType.SVG) # Get the SVG version of the QR code
- Parameters:
image_type (QRCodeImageType) β The type of the image (e.g., PNG, SVG).
- Returns:
A new QRCode object with the specified image type.
- Return type:
- update(*, prefilled_message)#
Updates the QR code with a new prefilled message.
- delete()#
Deletes the QR code.
- Returns:
A SuccessResult indicating whether the deletion was successful.
- Return type:
- class pywa.types.others.QRCodeImageType#
Represents the image type of a QR code.
- Variables:
PNG β PNG image type.
SVG β SVG image type.
- class pywa.types.others.Command#
Represents a command in a conversational automation.
- class pywa.types.others.CommerceSettings#
Represents the WhatsApp commerce settings.
- class pywa.types.others.Industry#
Represents the industry of a business.
- Variables:
UNDEFINED β Undefined.
OTHER β Other.
AUTO β Automotive.
BEAUTY β Beauty.
APPAREL β Apparel.
EDU β Education.
ENTERTAIN β Entertainment.
EVENT_PLAN β Event planning.
FINANCE β Finance.
GROCERY β Grocery store.
GOVT β Government.
HOTEL β Hotel.
HEALTH β Health.
NONPROFIT β Nonprofit.
PROF_SERVICES β Professional services.
RETAIL β Retail.
TRAVEL β Travel.
RESTAURANT β Restaurant.
NOT_A_BIZ β Not a business.
- class pywa.types.others.WhatsAppBusinessAccount#
Represents a WhatsApp Business Account.
- Variables:
id (str) β The ID of the account.
status (str | None) β The status of the WhatsApp Business Account (e.g. ACTIVE).
message_template_namespace (str) β Namespace string for the message templates that belong to the WhatsApp Business Account
name (str) β User-friendly name to differentiate WhatsApp Business Accounts.
timezone_id (str) β The timezone of the WhatsApp Business Account (See Timezone IDs).
business_verification_status (pywa.types.others.BusinessVerificationStatus | None) β Current status of business verification of Meta Business Account which owns this WhatsApp Business Account
is_enabled_for_insights (bool | None) β If true, indicates the WhatsApp Business Account enabled template analytics. See Analytics.
marketing_messages_lite_api_status (pywa.types.others.MarketingMessagesLiteAPIStatus | None) β WhatsApp Business Accountβs status for onboarding onto Marketing Messages Lite.
marketing_messages_onboarding_status (pywa.types.others.MarketingMessagesOnboardingStatus | None) β Onboarding status of the WhatsApp Business account into Marketing Messages Lite API.
ownership_type (str | None) β Ownership type of the WhatsApp Business Account.
currency (str | None) β The currency in which the payment transactions for the WhatsApp Business Account will be processed
country (str | None) β country of the WhatsApp Business Accountβs owning Meta Business account
- class pywa.types.others.FacebookApplication#
Represents a Facebook Application.
- class pywa.types.others.UsersBlockedResult#
Represents the result of blocking users operation.
- Variables:
added_users (tuple[pywa.types.others.User, ...]) β The users that were successfully blocked.
failed_users (tuple[pywa.types.others.BlockUserFailure, ...]) β The users that failed to be blocked. You can access the .errors attribute in each failure to get the error details.
errors (pywa.errors.WhatsAppError | None) β The errors that occurred during the operation (if any).
- class pywa.types.others.UsersUnblockedResult#
Represents the result of unblocking users operation.
- Variables:
removed_users (tuple[pywa.types.others.User, ...]) β The users that were successfully unblocked.
- class pywa.types.others.BlockUserFailure#
Represents a failure to block a user.
- Variables:
input (str) β The phone number/wa_id input that failed to be blocked.
errors (tuple[pywa.errors.WhatsAppError, ...]) β The errors that occurred during the operation.
- class pywa.Version#
Enum for the latest and minimum versions of the Graph API and WhatsApp Flows.
Use the constant to get the latest version. Example:
WhatsApp(..., api_version=Version.GRAPH_API)Using the latest version can break your code if the API changes. Use constants for stability.
Use the
minattribute to get the minimum version. Example: Version.GRAPH_API.min
- Variables:
GRAPH_API β (MIN_VERSION: str, LATEST_VERSION: str)
FLOW_JSON β (MIN_VERSION: str, LATEST_VERSION: str)
FLOW_DATA_API β (MIN_VERSION: str, LATEST_VERSION: str)
FLOW_MSG β (MIN_VERSION: str, LATEST_VERSION: str)
- class pywa.types.StopHandling#
Raise this exception to stop handling an update.
You can call
stop_handling()on every update object to raise this exception.Example
>>> from pywa import WhatsApp >>> from pywa.types import Message >>> wa = WhatsApp(...)
>>> @wa.on_message ... def callback(_: WhatsApp, msg: Message): ... msg.reply_text("Hello from PyWa!") ... msg.stop_handling() # or raise StopHandling
>>> @wa.on_message ... def not_called(_: WhatsApp, msg: Message): ... msg.reply_text("This message will not be sent")
- class pywa.types.ContinueHandling#
Raise this exception to continue handling an update.
You can call
continue_handling()on every update object to raise this exception.Example
>>> from pywa import WhatsApp >>> from pywa.types import Message >>> wa = WhatsApp(...)
>>> @wa.on_message ... def callback(_: WhatsApp, msg: Message): ... msg.reply_text("Hello from PyWa!") ... msg.continue_handling() # or raise ContinueHandling
>>> @wa.on_message ... def not_called(_: WhatsApp, msg: Message): ... msg.reply_text("This message will be sent")
- class pywa.utils.CallbackURLScope#
Enum for the callback URL scopes.
- Variables: