whatsapp-python 3.1.1__tar.gz → 3.1.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. whatsapp_python-3.1.5/.github/workflows/python-publish.yml +39 -0
  2. whatsapp_python-3.1.5/CODE_OF_CONDUCT.md +128 -0
  3. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/CONTRIBUTING.md +1 -3
  4. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/PKG-INFO +30 -12
  5. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/README.md +13 -4
  6. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/SECURITY.md +2 -2
  7. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/examples/standalone_hook.py +11 -0
  8. whatsapp_python-3.1.5/pyproject.toml +49 -0
  9. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/whatsapp/__init__.py +18 -23
  10. whatsapp_python-3.1.5/whatsapp/constants.py +4 -0
  11. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/whatsapp/ext/_buttons.py +1 -1
  12. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/whatsapp/ext/_media.py +1 -1
  13. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/whatsapp/ext/_static.py +19 -0
  14. whatsapp_python-3.1.1/.version +0 -1
  15. whatsapp_python-3.1.1/pyproject.toml +0 -32
  16. whatsapp_python-3.1.1/whatsapp/constants.py +0 -3
  17. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/.github/FUNDING.yml +0 -0
  18. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  19. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/.github/ISSUE_TEMPLATE/custom.md +0 -0
  20. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  21. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/.github/dependabot.yml +0 -0
  22. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/.github/workflows/codeql.yml +0 -0
  23. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/.github/workflows/dependency-review.yml +0 -0
  24. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/.gitignore +0 -0
  25. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/LICENSE +0 -0
  26. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/examples/reply_to_message_obj.py +0 -0
  27. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/examples/sending_audio.py +0 -0
  28. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/examples/sending_button.py +0 -0
  29. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/examples/sending_document.py +0 -0
  30. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/examples/sending_image.py +0 -0
  31. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/examples/sending_location.py +0 -0
  32. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/examples/sending_message.py +0 -0
  33. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/examples/sending_template_message.py +0 -0
  34. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/examples/sending_video.py +0 -0
  35. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/whatsapp/ext/_message.py +0 -0
  36. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/whatsapp/ext/_property.py +0 -0
  37. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/whatsapp/ext/_send_media.py +0 -0
  38. {whatsapp_python-3.1.1 → whatsapp_python-3.1.5}/whatsapp/ext/_send_others.py +0 -0
@@ -0,0 +1,39 @@
1
+ # This workflow will upload a Python Package using Twine when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3
+
4
+ # This workflow uses actions that are not certified by GitHub.
5
+ # They are provided by a third-party and are governed by
6
+ # separate terms of service, privacy policy, and support
7
+ # documentation.
8
+
9
+ name: Upload Python Package
10
+
11
+ on:
12
+ release:
13
+ types: [published]
14
+
15
+ permissions:
16
+ contents: read
17
+
18
+ jobs:
19
+ deploy:
20
+
21
+ runs-on: ubuntu-latest
22
+
23
+ steps:
24
+ - uses: actions/checkout@v4
25
+ - name: Set up Python
26
+ uses: actions/setup-python@v3
27
+ with:
28
+ python-version: '3.12'
29
+ - name: Install dependencies
30
+ run: |
31
+ python -m pip install --upgrade pip
32
+ pip install build
33
+ - name: Build package
34
+ run: python -m build
35
+ - name: Publish package
36
+ uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
37
+ with:
38
+ user: __token__
39
+ password: ${{ secrets.PYPI_API_TOKEN }}
@@ -0,0 +1,128 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ mail@filipporomani.it.
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120
+
121
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
+ enforcement ladder](https://github.com/mozilla/diversity).
123
+
124
+ [homepage]: https://www.contributor-covenant.org
125
+
126
+ For answers to common questions about this code of conduct, see the FAQ at
127
+ https://www.contributor-covenant.org/faq. Translations are available at
128
+ https://www.contributor-covenant.org/translations.
@@ -4,7 +4,7 @@ I'm really glad you're reading this, because we need developers to help this pro
4
4
 
5
5
  ## Submitting changes
6
6
 
7
- Please send a [GitHub Pull Request](https://github.com/filipporomani/whatsapp/pull/new/master) with a clear list of what you've done (read more about [pull requests](http://help.github.com/pull-requests/)). Please follow our coding conventions (below) and make sure all of your commits are atomic (one feature per commit).
7
+ Please open a [Pull Request](https://github.com/filipporomani/whatsapp/pull/new/master) with a clear list of what you've done (read more about [pull requests](http://help.github.com/pull-requests/)). Please make sure all of your commits are atomic (one feature per commit).
8
8
 
9
9
  Always write a clear log message for your commits. One-line messages are fine for small changes, but bigger changes should look like this:
10
10
 
@@ -12,9 +12,7 @@ Always write a clear log message for your commits. One-line messages are fine fo
12
12
  >
13
13
  > A paragraph describing what changed and its impact."
14
14
 
15
- ## Coding conventions
16
15
 
17
- Start reading our code and you'll get the hang of it. We optimize for readability:
18
16
  * This is open source software. Consider the people who will read your code, and make it look nice for them. It's sort of like driving a car: Perhaps you love doing donuts when you're alone, but with passengers the goal is to make the ride as smooth as possible.
19
17
 
20
18
  There isn't any other particular guideline, feel free to contribute!
@@ -1,22 +1,31 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: whatsapp-python
3
- Version: 3.1.1
3
+ Version: 3.1.5
4
4
  Summary: Open source Python wrapper for the WhatsApp Cloud API
5
- Project-URL: Homepage, https://github.com/filipporomani/whatsapp
6
- Project-URL: Bug Tracker, https://github.com/filipporomani/whatsapp/issues
7
- Project-URL: Download, https://github.com/filipporomani/whatsapp/releases/latest
5
+ Project-URL: Homepage, https://github.com/filipporomani/whatsapp-python
6
+ Project-URL: Docs, https://github.com/filipporomani/whatsapp-python/wiki
7
+ Project-URL: Issues Reporting, https://github.com/filipporomani/whatsapp-python/issues
8
+ Project-URL: Download, https://github.com/filipporomani/whatsapp-python/releases/latest
9
+ Project-URL: Changelog, https://github.com/filipporomani/whatsapp-python/releases
8
10
  Author-email: Filippo Romani <mail@filipporomani.it>
9
11
  License-File: LICENSE
10
12
  Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Customer Service
11
14
  Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Education
16
+ Classifier: Intended Audience :: Telecommunications Industry
12
17
  Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Programming Language :: Python :: 3.6
14
- Classifier: Programming Language :: Python :: 3.7
15
- Classifier: Programming Language :: Python :: 3.8
16
- Classifier: Programming Language :: Python :: 3.9
17
18
  Classifier: Programming Language :: Python :: 3.10
18
19
  Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Communications :: Chat
24
+ Classifier: Topic :: Communications :: Telephony
25
+ Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
26
+ Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application
19
27
  Classifier: Topic :: Software Development :: Build Tools
28
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
29
  Requires-Python: >=3.10
21
30
  Requires-Dist: fastapi
22
31
  Requires-Dist: python-dotenv
@@ -46,18 +55,27 @@ You can also install the development GitHub version (always up to date):
46
55
  ```bash
47
56
  git clone https://github.com/filipporomani/whatsapp.git
48
57
  cd whatsapp
49
- python3 setup.py install
58
+ pip install .
59
+ ```
60
+
61
+ If you want to use a local enviroment you can also use hatch:
62
+
63
+ ```bash
64
+ git clone https://github.com/filipporomani/whatsapp.git
65
+ cd whatsapp
66
+ pip install hatch
67
+ hatch shell
50
68
  ```
51
69
 
52
70
  Documentation is available in the [wiki section](https://github.com/filipporomani/whatsapp/wiki) on GitHub.
53
71
 
54
72
  ## Why choose this library?
55
73
 
56
- The main reason why I decided to fork the original library is that it uses an old version of the API and doesn't support many features.
74
+ The main reason why I decided to fork the original library is that it uses an old version of the API, it's missing many useful features and it's almost not mantained anymore.
57
75
 
58
- In this library I added app events (to listen to incoming messages) and implemented an easier way to send/receive messages and media by creating the `Message` object.
76
+ In this fork I added app events (to listen to incoming messages) and implemented an easier way to send/receive messages and media by using the `Message` object.
59
77
 
60
- I fixed some bugs and added some features, but the library still needs a lot of work to be done even if it's working and usable.
78
+ I fixed some bugs and added many features, however the library still needs a lot of work to be done even if it's working and usable.
61
79
 
62
80
  ### Supported features:
63
81
 
@@ -19,18 +19,27 @@ You can also install the development GitHub version (always up to date):
19
19
  ```bash
20
20
  git clone https://github.com/filipporomani/whatsapp.git
21
21
  cd whatsapp
22
- python3 setup.py install
22
+ pip install .
23
+ ```
24
+
25
+ If you want to use a local enviroment you can also use hatch:
26
+
27
+ ```bash
28
+ git clone https://github.com/filipporomani/whatsapp.git
29
+ cd whatsapp
30
+ pip install hatch
31
+ hatch shell
23
32
  ```
24
33
 
25
34
  Documentation is available in the [wiki section](https://github.com/filipporomani/whatsapp/wiki) on GitHub.
26
35
 
27
36
  ## Why choose this library?
28
37
 
29
- The main reason why I decided to fork the original library is that it uses an old version of the API and doesn't support many features.
38
+ The main reason why I decided to fork the original library is that it uses an old version of the API, it's missing many useful features and it's almost not mantained anymore.
30
39
 
31
- In this library I added app events (to listen to incoming messages) and implemented an easier way to send/receive messages and media by creating the `Message` object.
40
+ In this fork I added app events (to listen to incoming messages) and implemented an easier way to send/receive messages and media by using the `Message` object.
32
41
 
33
- I fixed some bugs and added some features, but the library still needs a lot of work to be done even if it's working and usable.
42
+ I fixed some bugs and added many features, however the library still needs a lot of work to be done even if it's working and usable.
34
43
 
35
44
  ### Supported features:
36
45
 
@@ -4,8 +4,8 @@
4
4
 
5
5
  | Version | Supported |
6
6
  | ------- | ------------------ |
7
- | >=1.0.2 | :white_check_mark: |
8
- | <1.0.2 | :x: |
7
+ | >=2.2.2 | :white_check_mark: |
8
+ | <2.2.2 | :x: |
9
9
 
10
10
  ## Reporting a Vulnerability
11
11
 
@@ -85,6 +85,17 @@ def hook():
85
85
  image_filename = messenger.download_media(image_url, mime_type)
86
86
  logging.info(f"{mobile} sent image {image_filename}")
87
87
 
88
+ elif message_type == "sticker":
89
+ sticker = msg.sticker
90
+ if sticker is None:
91
+ return Response(status=400)
92
+ sticker_id, mime_type = sticker["id"], sticker["mime_type"]
93
+ sticker_url = messenger.query_media_url(sticker_id)
94
+ if sticker_url is None:
95
+ return Response(status=400)
96
+ sticker_filename = messenger.download_media(sticker_url, mime_type)
97
+ logging.info(f"{mobile} sent sticker {sticker_filename}")
98
+
88
99
  elif message_type == "video":
89
100
  video = msg.video
90
101
  if video is None:
@@ -0,0 +1,49 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name="whatsapp-python"
7
+ authors = [{name="Filippo Romani", email="mail@filipporomani.it"}]
8
+ description="Open source Python wrapper for the WhatsApp Cloud API"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ classifiers=[
12
+ "Development Status :: 4 - Beta",
13
+ "Intended Audience :: Developers",
14
+ "Intended Audience :: Customer Service",
15
+ "Intended Audience :: Education",
16
+ "Intended Audience :: Telecommunications Industry",
17
+ "Topic :: Software Development :: Build Tools",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Programming Language :: Python :: 3.14",
24
+ "Topic :: Communications :: Chat",
25
+ "Topic :: Communications :: Telephony",
26
+ "Topic :: Internet :: WWW/HTTP :: HTTP Servers",
27
+ "Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
28
+ "Topic :: Software Development :: Libraries :: Python Modules",
29
+
30
+ ]
31
+ dynamic = [
32
+ "version"
33
+ ]
34
+ dependencies = ["fastapi", "uvicorn", "requests_toolbelt", "requests", "python-dotenv"]
35
+
36
+ [project.urls]
37
+ Homepage = "https://github.com/filipporomani/whatsapp-python"
38
+ Docs = "https://github.com/filipporomani/whatsapp-python/wiki"
39
+ "Issues Reporting" = "https://github.com/filipporomani/whatsapp-python/issues"
40
+ Download = "https://github.com/filipporomani/whatsapp-python/releases/latest"
41
+ Changelog = "https://github.com/filipporomani/whatsapp-python/releases"
42
+
43
+
44
+ [tool.hatch.version]
45
+ path = "whatsapp/constants.py"
46
+ variable = "VERSION"
47
+
48
+ [tool.hatch.build.targets.wheel]
49
+ packages = ["whatsapp"]
@@ -8,18 +8,18 @@ import logging
8
8
  from fastapi import FastAPI, HTTPException, Request
9
9
  from uvicorn import run as _run
10
10
  from .constants import VERSION
11
- from . import ext
12
11
  from .ext._property import authorized
13
12
  from .ext._send_others import send_custom_json, send_contacts
14
13
  from .ext._message import send_template
15
14
  from .ext._send_media import send_image, send_video, send_audio, send_location, send_sticker, send_document
16
15
  from .ext._media import upload_media, query_media_url, download_media, delete_media
17
16
  from .ext._buttons import send_button, create_button, send_reply_button
18
- from .ext._static import is_message, get_mobile, get_author, get_name, get_message, get_message_id, get_message_type, get_message_timestamp, get_audio, get_delivery, get_document, get_image, get_interactive_response, get_location, get_video, changed_field
17
+ from .ext._static import is_message, get_mobile, get_author, get_name, get_message, get_message_id, get_message_type, get_message_timestamp, get_audio, get_delivery, get_document, get_image, get_sticker, get_interactive_response, get_location, get_video, changed_field
19
18
  import json
20
19
 
20
+
21
21
  class WhatsApp(object):
22
- def __init__(self, token: str = "", phone_number_id: str = "", logger: bool = True, update_check: bool = True, verify_token: str = ""):
22
+ def __init__(self, token: str = "", phone_number_id: str = "", logger: bool = True, update_check: bool = True, verify_token: str = "", debug: bool = True):
23
23
  """
24
24
  Initialize the WhatsApp Object
25
25
 
@@ -50,21 +50,12 @@ class WhatsApp(object):
50
50
  else:
51
51
  logging.critical(
52
52
  f"Whatsapp-python is out of date. Please update to the latest version {latest}. READ THE CHANGELOG BEFORE UPDATING. NEW VERSIONS MAY BREAK YOUR CODE IF NOT PROPERLY UPDATED.")
53
- if version_int > latest_int:
54
- latest_beta = int(str(requests.get(
55
- "https://raw.githubusercontent.com/filipporomani/whatsapp/main/.version").text).replace(".", ""))
56
- if latest_beta > version_int:
57
- logging.critical(
58
- "A new beta version is available. Please update to the latest version. READ THE CHANGELOG BEFORE UPDATING. NEW VERSIONS MAY BREAK YOUR CODE IF NOT PROPERLY UPDATED.")
59
- logging.critical(
60
- f"You are using a development version of whatsapp-python. Please report any issue on GitHub.")
61
53
 
62
-
63
54
  if token == "":
64
55
  logging.error("Token not provided")
65
56
  raise ValueError("Token not provided but required")
66
57
  if phone_number_id == "":
67
- logging.error("Phone number id not provided")
58
+ logging.error("Phone number ID not provided")
68
59
  raise ValueError(
69
60
  "Phone number ID not provided but required")
70
61
  self.token = token
@@ -72,7 +63,6 @@ class WhatsApp(object):
72
63
  self.base_url = "https://graph.facebook.com/v18.0"
73
64
  self.url = f"{self.base_url}/{phone_number_id}/messages"
74
65
  self.verify_token = verify_token
75
-
76
66
 
77
67
  async def base(*args):
78
68
  pass
@@ -86,6 +76,9 @@ class WhatsApp(object):
86
76
  if logger is False:
87
77
  logging.disable(logging.INFO)
88
78
  logging.disable(logging.ERROR)
79
+ if debug is False:
80
+ logging.disable(logging.DEBUG)
81
+ logging.disable(logging.ERROR)
89
82
 
90
83
  self.app = FastAPI()
91
84
 
@@ -94,12 +87,12 @@ class WhatsApp(object):
94
87
  @self.app.get("/")
95
88
  async def verify_endpoint(r: Request):
96
89
  if r.query_params.get("hub.verify_token") == self.verify_token:
97
- logging.info("Verified webhook")
90
+ logging.debug("Webhook verified successfully")
98
91
  challenge = r.query_params.get("hub.challenge")
99
92
  self.verification_handler(challenge)
100
93
  self.other_handler(challenge)
101
94
  return int(challenge)
102
- logging.error("Webhook Verification failed")
95
+ logging.error("Webhook Verification failed - token mismatch")
103
96
  await self.verification_handler(False)
104
97
  await self.other_handler(False)
105
98
  return {"success": False}
@@ -111,10 +104,10 @@ class WhatsApp(object):
111
104
  data = await r.json()
112
105
  if data is None:
113
106
  return {"success": False}
114
- logging.info("Received webhook data: %s", data)
115
107
  data_str = json.dumps(data, indent=4)
108
+ # log the data received only if the log level is debug
116
109
  logging.debug(f"Received webhook data: {data_str}")
117
-
110
+
118
111
  changed_field = self.changed_field(data)
119
112
  if changed_field == "messages":
120
113
  new_message = self.is_message(data)
@@ -130,9 +123,6 @@ class WhatsApp(object):
130
123
  "error": str(e)
131
124
  })
132
125
 
133
-
134
-
135
-
136
126
  # all the files starting with _ are imported here, and should not be imported directly.
137
127
 
138
128
  is_message = staticmethod(is_message)
@@ -146,6 +136,7 @@ class WhatsApp(object):
146
136
  get_delivery = staticmethod(get_delivery)
147
137
  get_document = staticmethod(get_document)
148
138
  get_image = staticmethod(get_image)
139
+ get_sticker = staticmethod(get_sticker)
149
140
  get_interactive_response = staticmethod(get_interactive_response)
150
141
  get_location = staticmethod(get_location)
151
142
  get_video = staticmethod(get_video)
@@ -219,7 +210,7 @@ class Message(object):
219
210
  self.instance = instance
220
211
  self.url = self.instance.url
221
212
  self.headers = self.instance.headers
222
-
213
+
223
214
  try:
224
215
  self.id = instance.get_message_id(data)
225
216
  except:
@@ -250,6 +241,11 @@ class Message(object):
250
241
  self.image = self.instance.get_image(data)
251
242
  except:
252
243
  self.image = None
244
+ if self.type == "sticker":
245
+ try:
246
+ self.sticker = self.instance.get_sticker(data)
247
+ except:
248
+ self.sticker = None
253
249
  elif self.type == "video":
254
250
  try:
255
251
  self.video = self.instance.get_video(data)
@@ -275,6 +271,5 @@ class Message(object):
275
271
  self.interactive = self.instance.get_interactive_response(data)
276
272
  except:
277
273
  pass
278
-
279
274
 
280
275
  from .ext._message import send, reply, mark_as_read
@@ -0,0 +1,4 @@
1
+ # This file contains the constants used in the project.
2
+ # The VERSION constant is used to store the version of the project - it's not only used in the __init__.py file, but also in the pyproject.toml file.
3
+
4
+ VERSION = "3.1.5"
@@ -64,7 +64,7 @@ def send_reply_button(
64
64
  """
65
65
  if len(button["action"]["buttons"]) > 3:
66
66
  raise ValueError("The maximum number of buttons is 3.")
67
-
67
+
68
68
  data = {
69
69
  "messaging_product": "whatsapp",
70
70
  "recipient_type": "individual",
@@ -44,7 +44,7 @@ def upload_media(self, media: str) -> Union[Dict[Any, Any], None]:
44
44
  return r.json()
45
45
  logging.info(f"Error uploading media {media}")
46
46
  logging.info(f"Status code: {r.status_code}")
47
- logging.info(f"Response: {r.json()}")
47
+ logging.debug(f"Response: {r.json()}")
48
48
  return None
49
49
 
50
50
 
@@ -180,6 +180,25 @@ def get_image(data: Dict[Any, Any]) -> Union[Dict, None]:
180
180
  if "image" in data["messages"][0]:
181
181
  return data["messages"][0]["image"]
182
182
 
183
+ @staticmethod
184
+ def get_sticker(data: Dict[Any, Any]) -> Union[Dict, None]:
185
+ """ "
186
+ Extracts the sticker of the sender from the data received from the webhook.
187
+
188
+ Args:
189
+ data[dict]: The data received from the webhook
190
+ Returns:
191
+ dict: The sticker_id of an sticker sent by the sender
192
+
193
+ Example:
194
+ >>> from whatsapp import WhatsApp
195
+ >>> whatsapp = WhatsApp(token, phone_number_id)
196
+ >>> sticker_id = whatsapp.get_sticker(data)
197
+ """
198
+ data = data["entry"][0]["changes"][0]["value"]
199
+ if "messages" in data:
200
+ if "sticker" in data["messages"][0]:
201
+ return data["messages"][0]["sticker"]
183
202
 
184
203
  @staticmethod
185
204
  def get_document(data: Dict[Any, Any]) -> Union[Dict, None]:
@@ -1 +0,0 @@
1
- 3.1.1
@@ -1,32 +0,0 @@
1
- [build-system]
2
- requires = ["hatchling"]
3
- build-backend = "hatchling.build"
4
-
5
- [project]
6
- name="whatsapp-python"
7
- version="3.1.1"
8
- authors = [{name="Filippo Romani", email="mail@filipporomani.it"}]
9
- description="Open source Python wrapper for the WhatsApp Cloud API"
10
- readme = "README.md"
11
- requires-python = ">=3.10"
12
- classifiers=[
13
- "Development Status :: 4 - Beta",
14
- "Intended Audience :: Developers",
15
- "Topic :: Software Development :: Build Tools",
16
- "License :: OSI Approved :: MIT License",
17
- "Programming Language :: Python :: 3.6",
18
- "Programming Language :: Python :: 3.7",
19
- "Programming Language :: Python :: 3.8",
20
- "Programming Language :: Python :: 3.9",
21
- "Programming Language :: Python :: 3.10",
22
- "Programming Language :: Python :: 3.11",
23
- ]
24
- dependencies = ["fastapi", "uvicorn","requests_toolbelt", "requests", "python-dotenv"]
25
-
26
- [project.urls]
27
- "Homepage" = "https://github.com/filipporomani/whatsapp"
28
- "Bug Tracker" = "https://github.com/filipporomani/whatsapp/issues"
29
- "Download" = "https://github.com/filipporomani/whatsapp/releases/latest"
30
-
31
- [tool.hatch.build.targets.wheel]
32
- packages = ["whatsapp"]
@@ -1,3 +0,0 @@
1
- # internal use only - numbers and . only
2
-
3
- VERSION = "3.1.1"
File without changes