Skip to main content

WhatsMate is a class that provides a wrapper around the WhatsApp Cloud API, allowing you to send various types of messages to a phone number using the WhatsApp messaging service.

Here's a brief description of each method in the class:

from whatsmate import WhatsMate
ms = WhatsMate(token='your_whatsapp_token', '+91xxxxxxxxx')

# use methods as 
ms.method() # [pass params as documented]

__init__(self, token, phone_number_id)

Constructor for the WhatsMate class. Initializes the token and phone_number_id instance variables, which represent the WhatsApp Cloud API token and the phone number ID of the recipient, respectively.

say(self, message, phone_number, recipient_type="individual", preview_url=None)

Sends a text message to the recipient.

Parameters:

  • message (str): The message to be sent.
  • phone_number (str): The phone number of the recipient.
  • recipient_type (str, optional): The recipient type. Defaults to "individual".
  • preview_url (str, optional): The URL of the preview image to be sent with the message. Defaults to None.

Returns:

  • A JSON object containing the response from the API.

send_image(self, image_url, phone_number, recipient_type="individual", preview_url=None)

Sends an image to the recipient.

Parameters:

  • image_url (str): The URL of the image to be sent.
  • phone_number (str): The phone number of the recipient.
  • recipient_type (str, optional): The recipient type. Defaults to "individual".
  • preview_url (str, optional): The URL of the preview image to be sent with the message. Defaults to None.

Returns:

  • A JSON object containing the response from the API.

send_video(self, video_url, phone_number, recipient_type="individual", preview_url=None)

Sends a video to the recipient.

Parameters:

  • video_url (str): The URL of the video to be sent.
  • phone_number (str): The phone number of the recipient.
  • recipient_type (str, optional): The recipient type. Defaults to "individual".
  • preview_url (str, optional): The URL of the preview image to be sent with the message. Defaults to None.

Returns:

  • A JSON object containing the response from the API.

send_audio(self, audio_url, phone_number, recipient_type="individual", preview_url=None)

Sends an audio file to the recipient.

Parameters:

  • audio_url (str): The URL of the audio file to be sent.
  • phone_number (str): The phone number of the recipient.
  • recipient_type (str, optional): The recipient type. Defaults to "individual".
  • preview_url (str, optional): The URL of the preview image to be sent with the message. Defaults to None.

Returns:

  • A JSON object containing the response from the API.

send_file(self, file_url, phone_number, recipient_type="individual", preview_url=None)

Sends a file to the recipient.

Parameters:

  • file_url (str): The URL of the file to be sent.
  • phone_number (str): The phone number of the recipient.
  • recipient_type (str, optional): The recipient type. Defaults to "individual".
  • caption (str, optional): The caption needs to be sent with the file. Defaults to None.
  • filename (str, optional): The name to be set to the file/document. Defaults to None.

Returns:

  • A JSON object containing the response from the API.

send_location(self, latitude, longitude, phone_number, recipient_type="individual", preview_url=None)

Sends a location to the recipient.

Method: send_template

def send_template(self, template, phone_number, recipient_type="individual", preview_url=None):
  • Sends a WhatsApp message using a custom template.

Parameters

  • template (dict): The template to use. The format of the template is described in the WhatsApp Business API documentation.
  • phone_number (str): The phone number of the recipient.
  • recipient_type (str, optional): The recipient type. Possible values are "individual" (default) and "group".
  • preview_url (str, optional): The URL of a link to include in the message.

Returns

  • A JSON object containing the response from the WhatsApp server.

Example

template = {
        "namespace": "your-namespace",
        "name": "your-template-name",
        "language": {
            "policy": "deterministic",
            "code": "en"
        },
        "components": [
            {
                "type": "body",
                "parameters": [
                    {
                        "type": "text",
                        "text": "Hello {{1}}! This is a {{2}} message from {{3}}."
                    }
                ]
            }
        ]
    }
    response = whatsMate.send_template(template, "+14155552671")

Method: send_button_template

def send_button_template(self, text, buttons, phone_number, recipient_type="individual", preview_url=None):
  • Sends a WhatsApp message using a button template.

Parameters

  • text (str): The text of the message.
  • buttons (list): A list of dictionaries representing the buttons to include in the template. Each button should have a type and title field.
  • phone_number (str): The phone number of the recipient.
  • recipient_type (str, optional): The recipient type. Possible values are "individual" (default) and "group".
  • preview_url (str, optional): The URL of a link to include in the message.

Returns

  • A JSON object containing the response from the WhatsApp server.

Example

buttons = [
        {"type": "url", "title": "Visit Website", "url": "https://example.com"},
        {"type": "text", "title": "More Information", "payload": "more_info"}
    ]
    response = whatsMate.send_button_template("Welcome to our store!", buttons, "+14155552671")

Method: send_list_template

def send_list_template(self, elements, buttons, phone_number, recipient_type="individual", preview_url=None):
  • Sends a WhatsApp message using a list template.

Parameters

  • elements (list): A list of dictionaries representing the items to include in the list. Each item should have a title, subtitle, and image_url field.
  • buttons (list): A list of dictionaries representing the buttons to include in the template. Each button should have a type and title field.
  • phone_number (str): The phone number of the recipient.
  • recipient_type (str, optional): The recipient type. Possible values are "individual" (default) and "group".
  • preview_url (str, optional): The URL of a link to include in the message.

Returns

  • A JSON object containing the response from the WhatsApp server.

send_list_template(self, elements, buttons, phone_number, recipient_type="individual", preview_url=None): Sends a list template message to a phone number.

Example usage:

elements = [
    {
        "title": "Element 1",
        "subtitle": "Subtitle 1",
        "image_url": "https://example.com/image1.jpg",
        "default_action": {
            "type": "web_url",
            "url": "https://example.com/1",
            "messenger_extensions": True,
            "webview_height_ratio": "tall",
            "fallback_url": "https://example.com/fallback"
        }
    },
    {
        "title": "Element 2",
        "subtitle": "Subtitle 2",
        "image_url": "https://example.com/image2.jpg",
        "default_action": {
            "type": "web_url",
            "url": "https://example.com/2",
            "messenger_extensions": True,
            "webview_height_ratio": "tall",
            "fallback_url": "https://example.com/fallback"
        }
    }
]

buttons = [
    {
        "type": "web_url",
        "url": "https://example.com",
        "title": "Button 1"
    },
    {
        "type": "postback",
        "title": "Button 2",
        "payload": "Payload for button 2"
    }
]

response = whatsMate.send_list_template(elements, buttons, "1234567890")

send_media_template(self, elements, buttons, phone_number, recipient_type="individual", preview_url=None): Sends a media template message to a phone number.

Example usage:

elements = [
    {
        "media_type": "image",
        "url": "https://example.com/image.jpg",
        "buttons": [
            {
                "type": "web_url",
                "url": "https://example.com",
                "title": "Button 1"
            },
            {
                "type": "postback",
                "title": "Button 2",
                "payload": "Payload for button 2"
            }
        ]
    }
]

buttons = [
    {
        "type": "web_url",
        "url": "https://example.com",
        "title": "Button 1"
    },
    {
        "type": "postback",
        "title": "Button 2",
        "payload": "Payload for button 2"
    }
]

response = whatsMate.send_media_template(elements, buttons, "1234567890")

send_open_graph_template(self, elements, buttons, phone_number, recipient_type="individual", preview_url=None): Sends an Open Graph template message to a phone number.

reply(message_id, text, phone_number, recipient_type="individual", preview_url=None): This method is used to send a reply to a message. The message_id parameter specifies the ID of the message to which the reply is being sent. The text parameter is the text of the message being sent as a reply. The phone_number parameter is the phone number of the recipient of the reply. The recipient_type parameter specifies the type of recipient, which can be either "individual" or "group". The preview_url parameter specifies whether to show a preview of any included URL. Returns the response in JSON format.

send_to_group(group_id, text, preview_url=None): This method is used to send a message to a group. The group_id parameter is the ID of the group to which the message is being sent. The text parameter is the text of the message being sent. The preview_url parameter specifies whether to show a preview of any included URL. Returns the response in JSON format.

send_to_broadcast(broadcast_id, text, preview_url=None): This method is used to send a message to a broadcast. The broadcast_id parameter is the ID of the broadcast to which the message is being sent. The text parameter is the text of the message being sent. The preview_url parameter specifies whether to show a preview of any included URL. Returns the response in JSON format.

send_to_contact(contact_id, text, preview_url=None): This method is used to send a message to a contact. The contact_id parameter is the ID of the contact to which the message is being sent. The text parameter is the text of the message being sent. The preview_url parameter specifies whether to show a preview of any included URL. Returns the response in JSON format.

mark_as_read(message_id, recipient_type="individual"): This method is used to mark a message as read. The message_id parameter specifies the ID of the message to mark as read. The recipient_type parameter specifies the type of recipient, which can be either "individual" or "group". Returns the response in JSON format.

I hope this helps! Let me know if you have any further questions.

Metadata

Release files for whatsmate 1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for whatsmate 1.3
File Size Uploaded Provenance
whatsmate-1.3.tar.gz 4.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for whatsmate 1.3
File Interpreter ABI Platform
whatsmate-1.3-py3-none-any.whl Python 3 none any Details

Total release size: 9.5 kB

Release files / whatsmate-1.3.tar.gz

Download URL whatsmate-1.3.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
907cb545caca654509d44ecb71311ea5d713731382a839018efd888a03012034
BLAKE2b-256 checksum
How to use checksums
470c8a716ac50ff0eb267b992afaab9188845f3bf0c172d1d6b122be283b2a8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.7

Release files / whatsmate-1.3-py3-none-any.whl

Download URL whatsmate-1.3-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e6e1f395722dd41ee2f135a9f5d8248544e4311c7c185d5cc97a4cf416360ce6
BLAKE2b-256 checksum
How to use checksums
357e3cd65df218a0efb782b33a65c233acc2c6092116fee17a7697c464eb90e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.7

Security for whatsmate 1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page