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:
```python
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**
```python
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
```python
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**
```python
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
```python
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**
```python
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:
```python
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:
```python
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.
Raw data
{
"_id": null,
"home_page": "https://github.com/iamharshdev/whatsmate",
"name": "whatsmate",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "whatsapp automation chatbot api",
"author": "Harsh Vardhan Goswami",
"author_email": "me@iamharsh.dev",
"download_url": "https://files.pythonhosted.org/packages/47/0c/8a716ac50ff0eb267b992afaab9188845f3bf0c172d1d6b122be283b2a8c/whatsmate-1.3.tar.gz",
"platform": null,
"description": "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.\n\nHere's a brief description of each method in the class:\n\n```python\nfrom whatsmate import WhatsMate\nms = WhatsMate(token='your_whatsapp_token', '+91xxxxxxxxx')\n\n# use methods as \nms.method() # [pass params as documented]\n\n```\n\n## **`__init__(self, token, phone_number_id)`**\n\nConstructor 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.\n\n## **`say(self, message, phone_number, recipient_type=\"individual\", preview_url=None)`**\n\nSends a text message to the recipient.\n\n**Parameters:**\n\n- **`message`** (str): The message to be sent.\n- **`phone_number`** (str): The phone number of the recipient.\n- **`recipient_type`** (str, optional): The recipient type. Defaults to \"individual\".\n- **`preview_url`** (str, optional): The URL of the preview image to be sent with the message. Defaults to None.\n\n**Returns:**\n\n- A JSON object containing the response from the API.\n\n## **`send_image(self, image_url, phone_number, recipient_type=\"individual\", preview_url=None)`**\n\nSends an image to the recipient.\n\n**Parameters:**\n\n- **`image_url`** (str): The URL of the image to be sent.\n- **`phone_number`** (str): The phone number of the recipient.\n- **`recipient_type`** (str, optional): The recipient type. Defaults to \"individual\".\n- **`preview_url`** (str, optional): The URL of the preview image to be sent with the message. Defaults to None.\n\n**Returns:**\n\n- A JSON object containing the response from the API.\n\n## **`send_video(self, video_url, phone_number, recipient_type=\"individual\", preview_url=None)`**\n\nSends a video to the recipient.\n\n**Parameters:**\n\n- **`video_url`** (str): The URL of the video to be sent.\n- **`phone_number`** (str): The phone number of the recipient.\n- **`recipient_type`** (str, optional): The recipient type. Defaults to \"individual\".\n- **`preview_url`** (str, optional): The URL of the preview image to be sent with the message. Defaults to None.\n\n**Returns:**\n\n- A JSON object containing the response from the API.\n\n## **`send_audio(self, audio_url, phone_number, recipient_type=\"individual\", preview_url=None)`**\n\nSends an audio file to the recipient.\n\n**Parameters:**\n\n- **`audio_url`** (str): The URL of the audio file to be sent.\n- **`phone_number`** (str): The phone number of the recipient.\n- **`recipient_type`** (str, optional): The recipient type. Defaults to \"individual\".\n- **`preview_url`** (str, optional): The URL of the preview image to be sent with the message. Defaults to None.\n\n**Returns:**\n\n- A JSON object containing the response from the API.\n\n## **`send_file(self, file_url, phone_number, recipient_type=\"individual\", preview_url=None)`**\n\nSends a file to the recipient.\n\n**Parameters:**\n\n- **`file_url`** (str): The URL of the file to be sent.\n- **`phone_number`** (str): The phone number of the recipient.\n- **`recipient_type`** (str, optional): The recipient type. Defaults to \"individual\".\n- **`caption`** (str, optional): The caption needs to be sent with the file. Defaults to None.\n- **`filename`** (str, optional): The name to be set to the file/document. Defaults to None.\n\n**Returns:**\n\n- A JSON object containing the response from the API.\n\n## **`send_location(self, latitude, longitude, phone_number, recipient_type=\"individual\", preview_url=None)`**\n\nSends a location to the recipient.\n\n### **Method: send_template**\n\n```python\ndef send_template(self, template, phone_number, recipient_type=\"individual\", preview_url=None):\n```\n\n- Sends a WhatsApp message using a custom template.\n\n### Parameters\n\n- **`template`** (dict): The template to use. The format of the template is described in the WhatsApp Business API documentation.\n- **`phone_number`** (str): The phone number of the recipient.\n- **`recipient_type`** (str, optional): The recipient type. Possible values are \"individual\" (default) and \"group\".\n- **`preview_url`** (str, optional): The URL of a link to include in the message.\n\n### Returns\n\n- A JSON object containing the response from the WhatsApp server.\n\n### Example\n\n```python\ntemplate = {\n \"namespace\": \"your-namespace\",\n \"name\": \"your-template-name\",\n \"language\": {\n \"policy\": \"deterministic\",\n \"code\": \"en\"\n },\n \"components\": [\n {\n \"type\": \"body\",\n \"parameters\": [\n {\n \"type\": \"text\",\n \"text\": \"Hello {{1}}! This is a {{2}} message from {{3}}.\"\n }\n ]\n }\n ]\n }\n response = whatsMate.send_template(template, \"+14155552671\")\n\n```\n\n### **Method: send_button_template**\n\n```python\ndef send_button_template(self, text, buttons, phone_number, recipient_type=\"individual\", preview_url=None):\n```\n\n- Sends a WhatsApp message using a button template.\n\n### Parameters\n\n- **`text`** (str): The text of the message.\n- **`buttons`** (list): A list of dictionaries representing the buttons to include in the template. Each button should have a **`type`** and **`title`** field.\n- **`phone_number`** (str): The phone number of the recipient.\n- **`recipient_type`** (str, optional): The recipient type. Possible values are \"individual\" (default) and \"group\".\n- **`preview_url`** (str, optional): The URL of a link to include in the message.\n\n### Returns\n\n- A JSON object containing the response from the WhatsApp server.\n\n### Example\n\n```python\nbuttons = [\n {\"type\": \"url\", \"title\": \"Visit Website\", \"url\": \"https://example.com\"},\n {\"type\": \"text\", \"title\": \"More Information\", \"payload\": \"more_info\"}\n ]\n response = whatsMate.send_button_template(\"Welcome to our store!\", buttons, \"+14155552671\")\n\n```\n\n### **Method: send_list_template**\n\n```python\ndef send_list_template(self, elements, buttons, phone_number, recipient_type=\"individual\", preview_url=None):\n```\n\n- Sends a WhatsApp message using a list template.\n\n### Parameters\n\n- **`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.\n- **`buttons`** (list): A list of dictionaries representing the buttons to include in the template. Each button should have a **`type`** and **`title`** field.\n- **`phone_number`** (str): The phone number of the recipient.\n- **`recipient_type`** (str, optional): The recipient type. Possible values are \"individual\" (default) and \"group\".\n- **`preview_url`** (str, optional): The URL of a link to include in the message.\n\n### Returns\n\n- A JSON object containing the response from the WhatsApp server.\n\n**`send_list_template(self, elements, buttons, phone_number, recipient_type=\"individual\", preview_url=None)`**: Sends a list template message to a phone number.\n\nExample usage:\n\n```python\n\nelements = [\n {\n \"title\": \"Element 1\",\n \"subtitle\": \"Subtitle 1\",\n \"image_url\": \"https://example.com/image1.jpg\",\n \"default_action\": {\n \"type\": \"web_url\",\n \"url\": \"https://example.com/1\",\n \"messenger_extensions\": True,\n \"webview_height_ratio\": \"tall\",\n \"fallback_url\": \"https://example.com/fallback\"\n }\n },\n {\n \"title\": \"Element 2\",\n \"subtitle\": \"Subtitle 2\",\n \"image_url\": \"https://example.com/image2.jpg\",\n \"default_action\": {\n \"type\": \"web_url\",\n \"url\": \"https://example.com/2\",\n \"messenger_extensions\": True,\n \"webview_height_ratio\": \"tall\",\n \"fallback_url\": \"https://example.com/fallback\"\n }\n }\n]\n\nbuttons = [\n {\n \"type\": \"web_url\",\n \"url\": \"https://example.com\",\n \"title\": \"Button 1\"\n },\n {\n \"type\": \"postback\",\n \"title\": \"Button 2\",\n \"payload\": \"Payload for button 2\"\n }\n]\n\nresponse = whatsMate.send_list_template(elements, buttons, \"1234567890\")\n\n```\n\n**`send_media_template(self, elements, buttons, phone_number, recipient_type=\"individual\", preview_url=None)`**: Sends a media template message to a phone number.\n\nExample usage:\n\n```python\n\nelements = [\n {\n \"media_type\": \"image\",\n \"url\": \"https://example.com/image.jpg\",\n \"buttons\": [\n {\n \"type\": \"web_url\",\n \"url\": \"https://example.com\",\n \"title\": \"Button 1\"\n },\n {\n \"type\": \"postback\",\n \"title\": \"Button 2\",\n \"payload\": \"Payload for button 2\"\n }\n ]\n }\n]\n\nbuttons = [\n {\n \"type\": \"web_url\",\n \"url\": \"https://example.com\",\n \"title\": \"Button 1\"\n },\n {\n \"type\": \"postback\",\n \"title\": \"Button 2\",\n \"payload\": \"Payload for button 2\"\n }\n]\n\nresponse = whatsMate.send_media_template(elements, buttons, \"1234567890\")\n\n```\n\n**`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.\n\n**`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.\n\n**`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.\n\n**`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.\n\n**`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.\n\n**`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.\n\nI hope this helps! Let me know if you have any further questions.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "The ultimate WhatsApp Wrapper for Python",
"version": "1.3",
"project_urls": {
"Homepage": "https://github.com/iamharshdev/whatsmate"
},
"split_keywords": [
"whatsapp",
"automation",
"chatbot",
"api"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "357e3cd65df218a0efb782b33a65c233acc2c6092116fee17a7697c464eb90e6",
"md5": "6a93e4e511cf5d18c387981c2a0f5eaa",
"sha256": "e6e1f395722dd41ee2f135a9f5d8248544e4311c7c185d5cc97a4cf416360ce6"
},
"downloads": -1,
"filename": "whatsmate-1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6a93e4e511cf5d18c387981c2a0f5eaa",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 4675,
"upload_time": "2024-06-28T15:09:41",
"upload_time_iso_8601": "2024-06-28T15:09:41.337063Z",
"url": "https://files.pythonhosted.org/packages/35/7e/3cd65df218a0efb782b33a65c233acc2c6092116fee17a7697c464eb90e6/whatsmate-1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "470c8a716ac50ff0eb267b992afaab9188845f3bf0c172d1d6b122be283b2a8c",
"md5": "399e0f1ebf006c2a857c3d17cab1319e",
"sha256": "907cb545caca654509d44ecb71311ea5d713731382a839018efd888a03012034"
},
"downloads": -1,
"filename": "whatsmate-1.3.tar.gz",
"has_sig": false,
"md5_digest": "399e0f1ebf006c2a857c3d17cab1319e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4793,
"upload_time": "2024-06-28T15:09:43",
"upload_time_iso_8601": "2024-06-28T15:09:43.353838Z",
"url": "https://files.pythonhosted.org/packages/47/0c/8a716ac50ff0eb267b992afaab9188845f3bf0c172d1d6b122be283b2a8c/whatsmate-1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-28 15:09:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "iamharshdev",
"github_project": "whatsmate",
"github_not_found": true,
"lcname": "whatsmate"
}