wa_me.core package

Submodules

wa_me.core.client module

class wa_me.core.client.Client(**kwargs)[source]

Bases: object

Represents a client connection that connects to Whatsapp. This class is used to interact with the WhatsApp Business Cloud API.

Note

The Cloud API supports up to 80 messages per second (mps) combined sending and receiving of text and media messages by default, and up to 500 mps by request.

Note

Cloud API follows Business Use Case Rate Limits. Each WhatsApp Business Account (WABA) has a call count rate limit and each call made by your app counts toward the limit. An app’s call count for a WABA is the number of calls it can make to business accounts under this WABA during a rolling one hour window and is calculated as follows:

Calls within one hour for a WABA = 1800000 * Number of Registered Numbers under this WABA

You will receive an 80007 error code when you hit call limits.

clear() None[source]

Clears the internal HTTP session.

close() None[source]

Closes the internal HTTP session.

is_closed() bool[source]

Indicates if the internal HTTP session is closed.

start(phone_id: str, token: str) None[source]

Starts the internal HTTP session of the client.

Parameters

phone_id: str

ID for the phone number connected to the WhatsApp Business API.

token: str

Your user access token after signing up at developers.facebook.com.

wa_me.core.converter module

wa_me.core.converter.as_dict(data: T) Dict[str, Any][source]

Create a dictionary from a data class instance.

Parameters

data: Type[T]

An instance of a data class.

Returns

Dict[str, Any]

A dictionary mapping field names to field values of a input dataclass instance.

wa_me.core.converter.from_dict(data_class: Type[T], data: Dict[str, Any]) T[source]

Create a data class instance from a dictionary.

Parameters

data_class: Type[T]

A data class type.

data: Dict[str, Any]

A dictionary of a input data.

Returns

T

An instance of a data class.

wa_me.core.errors module

exception wa_me.core.errors.BadRequest(response: Response, content: Optional[Union[str, Dict[str, Any]]])[source]

Bases: HTTPException

Exception that’s raised for when status code 400 occurs.

exception wa_me.core.errors.Forbidden(response: Response, content: Optional[Union[str, Dict[str, Any]]])[source]

Bases: HTTPException

Exception that’s raised for when status code 403 occurs.

exception wa_me.core.errors.HTTPException(response: Response, content: Optional[Union[str, Dict[str, Any]]])[source]

Bases: WaMeException

Exception that’s raised when an HTTP request operation fails.

Parameters

response: requests.Response

The response of the failed HTTP request. This is an instance of requests.Response.

content: Optional[Union[str, Dict[str, Any]]]

The content response of the failed HTTP request.

Attributes

status: int

The status code of the HTTP request.

code: int

The WhatsApp Business Cloud API specific error code for the failure.

subcode: int

The WhatsApp Business Cloud API specific error subcode for the failure.

text: Optional[str]

The text of the error. Could be an empty string.

type: Optional[str]

The type of the error. Could be an empty string.

exception wa_me.core.errors.NotFound(response: Response, content: Optional[Union[str, Dict[str, Any]]])[source]

Bases: HTTPException

Exception that’s raised for when status code 404 occurs.

exception wa_me.core.errors.Unauthorized(response: Response, content: Optional[Union[str, Dict[str, Any]]])[source]

Bases: HTTPException

Exception that’s raised for when status code 401 occurs.

exception wa_me.core.errors.ValidationError[source]

Bases: WaMeException

An Exception that is raised when there is a Validation Error.

exception wa_me.core.errors.WaMeException[source]

Bases: Exception

Base exception class for wa_me.

exception wa_me.core.errors.WhatsappServerError(response: Response, content: Optional[Union[str, Dict[str, Any]]])[source]

Bases: HTTPException

Exception that’s raised for when a 500 range status code occurs.

wa_me.core.http module

class wa_me.core.http.HTTPClient(*, proxy: Optional[str] = None, proxy_auth: Optional[HTTPBasicAuth] = None)[source]

Bases: object

Represents an HTTP client sending HTTP requests to the WhatsApp API.

close() None[source]
download_media(media_url: str) bytes[source]
fetch_business_profile() Dict[str, Any][source]
fetch_media_url(media_id: str) Dict[str, Any][source]
read_message(message_id: str) Dict[str, Any][source]
request(route: Route, **kwargs) Any[source]
restart() None[source]
send_message(payload: Dict[str, Any]) Dict[str, Any][source]
start(phone_id: str, token: str) Dict[str, Any][source]
class wa_me.core.http.Route(method: str, path: str, **kwargs)[source]

Bases: object

Represents an HTTP route to the WhatsApp Business Cloud API.

property base: str

Module contents