whatsapp-python 4.2.0__tar.gz → 4.3.0__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 (51) hide show
  1. whatsapp_python-4.3.0/CONTRIBUTING.md +22 -0
  2. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/PKG-INFO +16 -17
  3. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/README.md +13 -15
  4. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/examples/reply_to_message_obj.py +2 -2
  5. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/examples/sending_audio.py +2 -3
  6. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/examples/sending_button.py +2 -3
  7. whatsapp_python-4.3.0/examples/sending_button_async.py +40 -0
  8. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/examples/sending_document.py +2 -3
  9. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/examples/sending_image.py +3 -0
  10. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/examples/sending_location.py +2 -3
  11. whatsapp_python-4.3.0/examples/sending_message.py +14 -0
  12. whatsapp_python-4.3.0/examples/sending_message_async.py +19 -0
  13. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/examples/sending_template_message.py +3 -3
  14. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/examples/sending_video.py +2 -3
  15. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/examples/standalone_hook.py +4 -8
  16. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/pyproject.toml +1 -1
  17. whatsapp_python-4.3.0/tests/async_tests.py +180 -0
  18. whatsapp_python-4.3.0/tests/tests.py +123 -0
  19. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/whatsapp/__init__.py +213 -82
  20. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/whatsapp/async_ext/_buttons.py +9 -5
  21. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/whatsapp/async_ext/_media.py +24 -24
  22. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/whatsapp/async_ext/_message.py +24 -10
  23. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/whatsapp/async_ext/_send_media.py +53 -38
  24. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/whatsapp/async_ext/_send_others.py +10 -6
  25. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/whatsapp/async_ext/_static.py +2 -0
  26. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/whatsapp/constants.py +1 -1
  27. whatsapp_python-4.3.0/whatsapp/errors.py +290 -0
  28. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/whatsapp/ext/_buttons.py +6 -3
  29. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/whatsapp/ext/_media.py +11 -6
  30. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/whatsapp/ext/_message.py +17 -7
  31. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/whatsapp/ext/_send_media.py +41 -30
  32. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/whatsapp/ext/_send_others.py +3 -2
  33. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/whatsapp/ext/_static.py +2 -0
  34. whatsapp_python-4.2.0/CONTRIBUTING.md +0 -19
  35. whatsapp_python-4.2.0/async_test.py +0 -142
  36. whatsapp_python-4.2.0/examples/sending_message.py +0 -15
  37. whatsapp_python-4.2.0/tests.py +0 -128
  38. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/.github/FUNDING.yml +0 -0
  39. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  40. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/.github/ISSUE_TEMPLATE/custom.md +0 -0
  41. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  42. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/.github/dependabot.yml +0 -0
  43. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/.github/workflows/codeql.yml +0 -0
  44. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/.github/workflows/dependency-review.yml +0 -0
  45. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/.github/workflows/python-publish.yml +0 -0
  46. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/.gitignore +0 -0
  47. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/CODE_OF_CONDUCT.md +0 -0
  48. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/LICENSE +0 -0
  49. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/SECURITY.md +0 -0
  50. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/whatsapp/async_ext/_property.py +0 -0
  51. {whatsapp_python-4.2.0 → whatsapp_python-4.3.0}/whatsapp/ext/_property.py +0 -0
@@ -0,0 +1,22 @@
1
+ # How to contribute
2
+
3
+ First of all, thank you for considering contributing to this project! It's people like you that make it a reality and help me keep it alive and updated.
4
+
5
+ If you are unsure about anything, feel free to ask me. I am here to help you.
6
+
7
+ Any bug report, feature request, or code contribution is welcome. Here are some guidelines to help you get started.
8
+
9
+ ## Submitting changes
10
+
11
+ Please open a [Pull Request](https://github.com/filipporomani/whatsapp-python/pull/new/master) with a list of what you've done (read more about [pull requests](http://help.github.com/pull-requests/)). Make sure, if possible, that all of your commits are atomic (one feature per commit).
12
+
13
+ Always write a clear log message for your commits. One-line messages are fine for small changes, but bigger changes should look like this:
14
+
15
+ $ git commit -m "feat: a brief summary of the commit
16
+ >
17
+ > A paragraph describing what changed and its impact."
18
+
19
+
20
+ * This is an open source software. Keep in mind to make your code readable to others. 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.
21
+
22
+ There isn't any other particular guideline, feel free to contribute!
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: whatsapp-python
3
- Version: 4.2.0
3
+ Version: 4.3.0
4
4
  Summary: Open source Python wrapper for the WhatsApp Cloud API
5
5
  Project-URL: Homepage, https://github.com/filipporomani/whatsapp-python
6
6
  Project-URL: Docs, https://github.com/filipporomani/whatsapp-python/wiki
@@ -26,10 +26,11 @@ Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application
26
26
  Classifier: Topic :: Software Development :: Build Tools
27
27
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
28
28
  Requires-Python: >=3.10
29
+ Requires-Dist: aiohttp
30
+ Requires-Dist: asyncio
29
31
  Requires-Dist: beautifulsoup4
30
32
  Requires-Dist: fastapi
31
33
  Requires-Dist: python-dotenv
32
- Requires-Dist: requests
33
34
  Requires-Dist: requests-toolbelt
34
35
  Requires-Dist: uvicorn
35
36
  Description-Content-Type: text/markdown
@@ -37,7 +38,8 @@ Description-Content-Type: text/markdown
37
38
  <div align="center">
38
39
  <img src="https://gist.githubusercontent.com/boywithkeyboard/e8dc5b1810bd29e1d70346ca11d7f09d/raw/7f7eeea482f5047e62944e54182aa26c89cc299a/whatsapp_python.svg" alt="logo" width="128px">
39
40
  <h1>whatsapp-python</h1>
40
- <p>Free, open-source Python wrapper for the <a href="https://developers.facebook.com/docs/whatsapp/cloud-api">WhatsApp Cloud API</a>.<br>Forked from <a href="https://github.com/Neurotech-HQ/heyoo">Neurotech-HQ/heyoo</a>.</p>
41
+ <p>Free, open-source Python wrapper for the <a href="https://developers.facebook.com/docs/whatsapp/cloud-api">WhatsApp Cloud API</a>.<br>Forked from <a href="https://github.com/Neurotech-HQ/heyoo">Neurotech-HQ/heyoo</a>.
42
+ </p>
41
43
  <img src="https://img.shields.io/badge/made%20in-italy-008751.svg?style=flat-square" alt="Made in Italy">
42
44
  <a href="https://pepy.tech/project/whatsapp-python"><img src="https://static.pepy.tech/personalized-badge/whatsapp-python?period=total&units=none&left_color=grey&right_color=blue&left_text=Downloads" alt="Downloads"></a>
43
45
  <a href="https://pepy.tech/project/whatsapp-python"><img src="https://pepy.tech/badge/whatsapp-python/month" alt="Monthly Downloads"></a>
@@ -69,27 +71,24 @@ hatch shell
69
71
 
70
72
  Documentation is available in the [wiki](https://github.com/filipporomani/whatsapp/wiki) here on GitHub.
71
73
 
72
- ## Why choose this library?
74
+ ### Key features:
75
+ - Modern interface using `async` and `await`
76
+ - Full support for Graph API error handling
77
+ - Optimized for high-load workflows using asyncronous programming
78
+ - Always up to date
79
+ - All of the WhatsApp chat UI features supported
73
80
 
74
- The main reason why I decided to fork the original `heyoo` library is that it uses an old version of the API, it's missing many and it's not mantained anymore.
75
81
 
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.
77
- The API version is always up to date and I'm always adding new features and fixing bugs.
78
-
79
- I also added a full asyncronous version of the library, which is faster and more efficient than the syncronous one.
80
-
81
- I fixed some bugs and added many features, however the library can still be improved.
82
-
83
- ### Supported features:
84
-
85
- - Listening to events (messages, media, etc.)
86
- - Async version available
82
+ ### All features
83
+ - Event listener (incoming messages)
84
+ - Async ready
85
+ - Error handling
87
86
  - Sending messages
88
87
  - Sending messages from different numbers individually
89
88
  - Marking messages as read
90
89
  - Replying to messages
91
90
  - Reacting to messages
92
- - Sending Media (images, audio, video and documents)
91
+ - Sending medias (images, audios, videos, links and documents)
93
92
  - Sending location
94
93
  - Sending interactive buttons
95
94
  - Sending template messages
@@ -1,7 +1,8 @@
1
1
  <div align="center">
2
2
  <img src="https://gist.githubusercontent.com/boywithkeyboard/e8dc5b1810bd29e1d70346ca11d7f09d/raw/7f7eeea482f5047e62944e54182aa26c89cc299a/whatsapp_python.svg" alt="logo" width="128px">
3
3
  <h1>whatsapp-python</h1>
4
- <p>Free, open-source Python wrapper for the <a href="https://developers.facebook.com/docs/whatsapp/cloud-api">WhatsApp Cloud API</a>.<br>Forked from <a href="https://github.com/Neurotech-HQ/heyoo">Neurotech-HQ/heyoo</a>.</p>
4
+ <p>Free, open-source Python wrapper for the <a href="https://developers.facebook.com/docs/whatsapp/cloud-api">WhatsApp Cloud API</a>.<br>Forked from <a href="https://github.com/Neurotech-HQ/heyoo">Neurotech-HQ/heyoo</a>.
5
+ </p>
5
6
  <img src="https://img.shields.io/badge/made%20in-italy-008751.svg?style=flat-square" alt="Made in Italy">
6
7
  <a href="https://pepy.tech/project/whatsapp-python"><img src="https://static.pepy.tech/personalized-badge/whatsapp-python?period=total&units=none&left_color=grey&right_color=blue&left_text=Downloads" alt="Downloads"></a>
7
8
  <a href="https://pepy.tech/project/whatsapp-python"><img src="https://pepy.tech/badge/whatsapp-python/month" alt="Monthly Downloads"></a>
@@ -33,27 +34,24 @@ hatch shell
33
34
 
34
35
  Documentation is available in the [wiki](https://github.com/filipporomani/whatsapp/wiki) here on GitHub.
35
36
 
36
- ## Why choose this library?
37
+ ### Key features:
38
+ - Modern interface using `async` and `await`
39
+ - Full support for Graph API error handling
40
+ - Optimized for high-load workflows using asyncronous programming
41
+ - Always up to date
42
+ - All of the WhatsApp chat UI features supported
37
43
 
38
- The main reason why I decided to fork the original `heyoo` library is that it uses an old version of the API, it's missing many and it's not mantained anymore.
39
44
 
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.
41
- The API version is always up to date and I'm always adding new features and fixing bugs.
42
-
43
- I also added a full asyncronous version of the library, which is faster and more efficient than the syncronous one.
44
-
45
- I fixed some bugs and added many features, however the library can still be improved.
46
-
47
- ### Supported features:
48
-
49
- - Listening to events (messages, media, etc.)
50
- - Async version available
45
+ ### All features
46
+ - Event listener (incoming messages)
47
+ - Async ready
48
+ - Error handling
51
49
  - Sending messages
52
50
  - Sending messages from different numbers individually
53
51
  - Marking messages as read
54
52
  - Replying to messages
55
53
  - Reacting to messages
56
- - Sending Media (images, audio, video and documents)
54
+ - Sending medias (images, audios, videos, links and documents)
57
55
  - Sending location
58
56
  - Sending interactive buttons
59
57
  - Sending template messages
@@ -4,11 +4,11 @@ from dotenv import load_dotenv
4
4
 
5
5
  if __name__ == "__main__":
6
6
  load_dotenv()
7
- messenger = WhatsApp(token=getenv("TOKEN"), phone_number_id={1:"1234", 2: "5678"})
7
+ messenger = WhatsApp(token=getenv("TOKEN"), phone_number_id={1: "1234", 2: "5678"})
8
8
 
9
9
  data = {"your": "data"}
10
10
 
11
- msg = Message(data=data, instance=messenger,sender=1)
11
+ msg = Message(data=data, instance=messenger, sender=1)
12
12
  msg.reply("lol")
13
13
 
14
14
  print(msg)
@@ -4,13 +4,12 @@ from dotenv import load_dotenv
4
4
 
5
5
  if __name__ == "__main__":
6
6
  load_dotenv()
7
- messenger = WhatsApp(token=getenv("TOKEN"),
8
- phone_number_id={1:"1234", 2: "5678"})
7
+ messenger = WhatsApp(token=getenv("TOKEN"), phone_number_id={1: "1234", 2: "5678"})
9
8
 
10
9
  response = messenger.send_audio(
11
10
  audio="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3",
12
11
  recipient_id="255757xxxxxx",
13
- sender=1
12
+ sender=1,
14
13
  )
15
14
 
16
15
  print(response)
@@ -4,8 +4,7 @@ from dotenv import load_dotenv
4
4
 
5
5
  if __name__ == "__main__":
6
6
  load_dotenv()
7
- messenger = WhatsApp(token=getenv("TOKEN"),
8
- phone_number_id={1:"1234", 2: "5678"})
7
+ messenger = WhatsApp(token=getenv("TOKEN"), phone_number_id={1: "1234", 2: "5678"})
9
8
 
10
9
  response = messenger.send_button(
11
10
  recipient_id="255757xxxxxx",
@@ -30,5 +29,5 @@ if __name__ == "__main__":
30
29
  ],
31
30
  },
32
31
  },
33
- sender=1
32
+ sender=1,
34
33
  )
@@ -0,0 +1,40 @@
1
+ from os import getenv
2
+ from whatsapp import AsyncWhatsApp, AsyncMessage
3
+ import asyncio
4
+ from dotenv import load_dotenv
5
+
6
+ if __name__ == "__main__":
7
+ load_dotenv()
8
+ messenger = AsyncWhatsApp(token=getenv("TOKEN"), phone_number_id={1: "1234", 2: "5678"})
9
+
10
+ async def run_test():
11
+ response = await messenger.send_button(
12
+ recipient_id="255757xxxxxx",
13
+ button={
14
+ "header": "Header Testing",
15
+ "body": "Body Testing",
16
+ "footer": "Footer Testing",
17
+ "action": {
18
+ "button": "Button Testing",
19
+ "sections": [
20
+ {
21
+ "title": "iBank",
22
+ "rows": [
23
+ {"id": "row 1", "title": "Send Money", "description": ""},
24
+ {
25
+ "id": "row 2",
26
+ "title": "Withdraw money",
27
+ "description": "",
28
+ },
29
+ ],
30
+ }
31
+ ],
32
+ },
33
+ },
34
+ sender=1,
35
+ )
36
+ while not response.done():
37
+ await asyncio.sleep(.1)
38
+ print(response.result())
39
+
40
+ asyncio.run(run_test())
@@ -5,13 +5,12 @@ from dotenv import load_dotenv
5
5
  if __name__ == "__main__":
6
6
  load_dotenv()
7
7
 
8
- messenger = WhatsApp(token=getenv("TOKEN"),
9
- phone_number_id={1:"1234", 2: "5678"})
8
+ messenger = WhatsApp(token=getenv("TOKEN"), phone_number_id={1: "1234", 2: "5678"})
10
9
 
11
10
  response = messenger.send_document(
12
11
  document="http://www.africau.edu/images/default/sample.pdf",
13
12
  recipient_id="255757294146",
14
- sender=1
13
+ sender=1,
15
14
  )
16
15
 
17
16
  print(response)
@@ -1,3 +1,6 @@
1
+
2
+
3
+
1
4
  from os import getenv
2
5
  from whatsapp import WhatsApp
3
6
  from dotenv import load_dotenv
@@ -4,8 +4,7 @@ from dotenv import load_dotenv
4
4
 
5
5
  if __name__ == "__main__":
6
6
  load_dotenv()
7
- messenger = WhatsApp(token=getenv("TOKEN"),
8
- phone_number_id={1:"1234", 2: "5678"})
7
+ messenger = WhatsApp(token=getenv("TOKEN"), phone_number_id={1: "1234", 2: "5678"})
9
8
 
10
9
  response = messenger.send_location(
11
10
  lat=1.29,
@@ -13,7 +12,7 @@ if __name__ == "__main__":
13
12
  name="Singapore",
14
13
  address="Singapore",
15
14
  recipient_id="255757294146",
16
- sender=1
15
+ sender=1,
17
16
  )
18
17
 
19
18
  print(response)
@@ -0,0 +1,14 @@
1
+ from os import getenv
2
+ from whatsapp import WhatsApp, Message
3
+ from dotenv import load_dotenv
4
+
5
+ if __name__ == "__main__":
6
+ load_dotenv()
7
+ messenger = WhatsApp(token=getenv("TOKEN"), phone_number_id={1: "1234", 2: "5678"})
8
+
9
+ msg = Message(
10
+ instance=messenger, content="Hello World!", to="919999999999", sender=1
11
+ )
12
+ response = msg.send()
13
+
14
+ print(response)
@@ -0,0 +1,19 @@
1
+ from os import getenv
2
+ from whatsapp import AsyncWhatsApp, AsyncMessage
3
+ import asyncio
4
+ from dotenv import load_dotenv
5
+
6
+ if __name__ == "__main__":
7
+ load_dotenv()
8
+ messenger = AsyncWhatsApp(token=getenv("TOKEN"), phone_number_id={1: "1234", 2: "5678"})
9
+
10
+ msg = AsyncMessage(
11
+ instance=messenger, content="Hello World!", to="919999999999", sender=1
12
+ )
13
+ async def run_test():
14
+ response = await msg.send()
15
+ while not response.done():
16
+ await asyncio.sleep(.1)
17
+ print(response.result())
18
+
19
+ asyncio.run(run_test())
@@ -4,10 +4,10 @@ from dotenv import load_dotenv
4
4
 
5
5
  if __name__ == "__main__":
6
6
  load_dotenv()
7
- messenger = WhatsApp(token=getenv("TOKEN"),
8
- phone_number_id={1:"1234", 2: "5678"})
7
+ messenger = WhatsApp(token=getenv("TOKEN"), phone_number_id={1: "1234", 2: "5678"})
9
8
 
10
9
  response = messenger.send_template(
11
- "hello_world", "255757xxxxxx", components=[], lang="en_US", sender=1)
10
+ "hello_world", "255757xxxxxx", components=[], lang="en_US", sender=1
11
+ )
12
12
 
13
13
  print(response)
@@ -4,13 +4,12 @@ from dotenv import load_dotenv
4
4
 
5
5
  if __name__ == "__main__":
6
6
  load_dotenv()
7
- messenger = WhatsApp(token=getenv("TOKEN"),
8
- phone_number_id={1:"1234", 2: "5678"})
7
+ messenger = WhatsApp(token=getenv("TOKEN"), phone_number_id={1: "1234", 2: "5678"})
9
8
 
10
9
  response = messenger.send_video(
11
10
  video="https://www.youtube.com/watch?v=K4TOrB7at0Y",
12
11
  recipient_id="255757xxxxxx",
13
- sender=1
12
+ sender=1,
14
13
  )
15
14
 
16
15
  print(response)
@@ -9,8 +9,7 @@ app = Flask(__name__)
9
9
 
10
10
  # Load .env file
11
11
  load_dotenv("../.env")
12
- messenger = WhatsApp(os.getenv("TOKEN"),
13
- phone_number_id=os.getenv("ID"))
12
+ messenger = WhatsApp(os.getenv("TOKEN"), phone_number_id=os.getenv("ID"))
14
13
  VERIFY_TOKEN = "30cca545-3838-48b2-80a7-9e43b1ae8ce4"
15
14
 
16
15
  # Logging
@@ -51,8 +50,7 @@ def hook():
51
50
  message = msg.content
52
51
  name = msg.name
53
52
  logging.info("Message: %s", message)
54
- m = Message(instance=messenger, to=mobile,
55
- content="Hello World")
53
+ m = Message(instance=messenger, to=mobile, content="Hello World")
56
54
  m.send()
57
55
 
58
56
  elif message_type == "interactive":
@@ -62,8 +60,7 @@ def hook():
62
60
  interactive_type = message_response.get("type")
63
61
  message_id = message_response[interactive_type]["id"]
64
62
  message_text = message_response[interactive_type]["title"]
65
- logging.info(
66
- f"Interactive Message; {message_id}: {message_text}")
63
+ logging.info(f"Interactive Message; {message_id}: {message_text}")
67
64
 
68
65
  elif message_type == "location":
69
66
  message_location = msg.location
@@ -71,8 +68,7 @@ def hook():
71
68
  return Response(status=400)
72
69
  message_latitude = message_location["latitude"]
73
70
  message_longitude = message_location["longitude"]
74
- logging.info("Location: %s, %s",
75
- message_latitude, message_longitude)
71
+ logging.info("Location: %s, %s", message_latitude, message_longitude)
76
72
 
77
73
  elif message_type == "image":
78
74
  image = msg.image
@@ -31,7 +31,7 @@ classifiers=[
31
31
  dynamic = [
32
32
  "version"
33
33
  ]
34
- dependencies = ["fastapi", "uvicorn", "requests_toolbelt", "requests", "python-dotenv", "BeautifulSoup4"]
34
+ dependencies = ["fastapi", "uvicorn", "requests_toolbelt", "asyncio", "aiohttp", "python-dotenv", "BeautifulSoup4"]
35
35
 
36
36
  [project.urls]
37
37
  Homepage = "https://github.com/filipporomani/whatsapp-python"
@@ -0,0 +1,180 @@
1
+ from whatsapp import WhatsApp, Message, AsyncWhatsApp
2
+ from dotenv import load_dotenv
3
+ from os import getenv
4
+ import asyncio
5
+ from logging import getLogger, basicConfig, DEBUG
6
+
7
+ load_dotenv()
8
+ token = getenv("GRAPH_API_TOKEN")
9
+ phone_number_id = {1: getenv("TEST_PHONE_NUMBER_ID")}
10
+ dest_phone_number = getenv("DEST_PHONE_NUMBER")
11
+
12
+ app = AsyncWhatsApp(token=token, phone_number_id=phone_number_id, update_check=False, logger=True, debug=True)
13
+ syncapp = WhatsApp(token=token, phone_number_id=phone_number_id, update_check=False, logger=True, debug=True)
14
+ loop = asyncio.get_event_loop()
15
+ msg = app.create_message(to=dest_phone_number, content="Hello world")
16
+
17
+ basicConfig(level=DEBUG)
18
+ logger = getLogger(__name__)
19
+
20
+ async def run_test():
21
+
22
+ # test every single method and print the result
23
+ print("Testing send_text")
24
+ v = await msg.send()
25
+ # print(v)
26
+ # await asyncio.sleep(1)
27
+ # print("Getting request status")
28
+ # print(v.result())
29
+
30
+ print("Testing send_reply_button")
31
+ v = await app.send_reply_button(
32
+ button={
33
+ "type": "button",
34
+ "body": {"text": "This is a test button"},
35
+ "action": {
36
+ "buttons": [
37
+ {
38
+ "type": "reply",
39
+ "reply": {"id": "b1", "title": "This is button 1"},
40
+ },
41
+ {
42
+ "type": "reply",
43
+ "reply": {"id": "b2", "title": "this is button 2"},
44
+ },
45
+ ]
46
+ },
47
+ },
48
+ recipient_id=dest_phone_number,
49
+ sender=1,
50
+ )
51
+ print(f"send_reply_button: {v}")
52
+
53
+ print("Creating button")
54
+ v = app.create_button(
55
+ button={
56
+ "header": {"type": "text", "text": "your-header-content"},
57
+ "body": {"text": "your-text-message-content"},
58
+ "footer": {"text": "your-footer-content"},
59
+ "action": {
60
+ "button": "cta-button-content",
61
+ "sections": [
62
+ {
63
+ "title": "your-section-title-content",
64
+ "rows": [
65
+ {
66
+ "id": "unique-row-identifier",
67
+ "title": "row-title-content",
68
+ "description": "row-description-content",
69
+ }
70
+ ],
71
+ },
72
+ ],
73
+ },
74
+ },
75
+ )
76
+ print(f"create_button: {v}")
77
+ print("sending button")
78
+ v = await app.send_button(
79
+ {
80
+ "header": "Header Testing",
81
+ "body": "Body Testing",
82
+ "footer": "Footer Testing",
83
+ "action": {
84
+ "button": "cta-button-content",
85
+ "sections": [
86
+ {
87
+ "title": "your-secti",
88
+ "rows": [
89
+ {
90
+ "id": "unique-row-",
91
+ "title": "row-title-",
92
+ "description": "row-description-",
93
+ }
94
+ ],
95
+ },
96
+ ],
97
+ },
98
+ },
99
+ dest_phone_number,
100
+ sender=1,
101
+ )
102
+ while not v.done():
103
+ await asyncio.sleep(1)
104
+ try: app.handle(v.result())
105
+ except Exception as error:
106
+ print(f"error: {error}")
107
+ print("sending wrong button")
108
+ v = await app.send_button(
109
+ {
110
+ "header": "Header Testing",
111
+
112
+ },
113
+ dest_phone_number,
114
+ sender=1,
115
+ )
116
+ while not v.done():
117
+ await asyncio.sleep(1)
118
+ try: app.handle(v.result())
119
+ except Exception as error:
120
+ print(f"error: {error}")
121
+ raise Exception("Error")
122
+
123
+
124
+ print(f"send_button: {v}")
125
+ print("sending image")
126
+ v = await app.send_image(
127
+ "https://filesamples.com/samples/image/jpeg/sample_640%C3%97426.jpeg",
128
+ dest_phone_number,
129
+ sender=1,
130
+ )
131
+ print(f"send_image: {v}")
132
+ print("sending video")
133
+ v = await app.send_video(
134
+ "https://filesamples.com/samples/video/mp4/sample_1280x720_surfing_with_audio.mp4",
135
+ dest_phone_number,
136
+ sender=1,
137
+ )
138
+ print(f"send_video: {v}")
139
+ print("sending audio")
140
+ v = await app.send_audio(
141
+ "https://filesamples.com/samples/audio/mp3/Symphony%20No.6%20(1st%20movement).mp3",
142
+ dest_phone_number,
143
+ sender=1,
144
+ )
145
+ print(f"send_audio: {v}")
146
+ print("sending document")
147
+ v = await app.send_document(
148
+ "https://filesamples.com/samples/document/docx/sample1.docx",
149
+ dest_phone_number,
150
+ sender=1,
151
+ )
152
+ print(f"send_document: {v}")
153
+ print("sending location")
154
+ v = await app.send_location(
155
+ "37.7749", "-122.4194", "test", "test, test", dest_phone_number, sender=1
156
+ )
157
+ print(f"send_location: {v}")
158
+ print("sending template")
159
+ v = await app.send_template("hello_world", dest_phone_number, sender=1)
160
+ print(
161
+ f"send_template: {v}"
162
+ ) # this returns error if the phone number is not a test phone number
163
+
164
+
165
+
166
+
167
+ await asyncio.sleep(60)
168
+
169
+ async def upload():
170
+ print("uploading media")
171
+ f = await app.upload_media(
172
+ getenv("TEST_IMAGE_PATH"),
173
+ sender=1
174
+ )
175
+ print(f"upload_media: {f}")
176
+ print(f)
177
+
178
+
179
+ asyncio.run(run_test())
180
+ asyncio.run(upload())