whatsapp-python 3.0.4__py3-none-any.whl → 3.0.6__py3-none-any.whl
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.
- whatsapp/__init__.py +21 -12
- whatsapp/constants.py +2 -2
- {whatsapp_python-3.0.4.dist-info → whatsapp_python-3.0.6.dist-info}/METADATA +1 -1
- whatsapp_python-3.0.6.dist-info/RECORD +13 -0
- {whatsapp_python-3.0.4.dist-info → whatsapp_python-3.0.6.dist-info}/WHEEL +1 -1
- examples/example_hook_obj.py +0 -85
- examples/reply_to_message_obj.py +0 -14
- examples/sending_audio.py +0 -15
- examples/sending_button.py +0 -33
- examples/sending_document.py +0 -16
- examples/sending_image.py +0 -15
- examples/sending_location.py +0 -18
- examples/sending_message.py +0 -14
- examples/sending_template_message.py +0 -13
- examples/sending_video.py +0 -15
- examples/standalone_hook.py +0 -133
- whatsapp_python-3.0.4.dist-info/RECORD +0 -24
- {whatsapp_python-3.0.4.dist-info → whatsapp_python-3.0.6.dist-info}/licenses/LICENSE +0 -0
whatsapp/__init__.py
CHANGED
|
@@ -6,6 +6,7 @@ from __future__ import annotations
|
|
|
6
6
|
import requests
|
|
7
7
|
import logging
|
|
8
8
|
from fastapi import FastAPI, Request
|
|
9
|
+
from uvicorn import run as _run
|
|
9
10
|
from .constants import VERSION
|
|
10
11
|
from . import ext
|
|
11
12
|
from .ext._property import authorized
|
|
@@ -17,8 +18,6 @@ from .ext._buttons import send_button, create_button, send_reply_button
|
|
|
17
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
|
|
18
19
|
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
21
|
class WhatsApp(object):
|
|
23
22
|
def __init__(self, token: str = "", phone_number_id: str = "", logger: bool = True, update_check: bool = True):
|
|
24
23
|
"""
|
|
@@ -32,19 +31,25 @@ class WhatsApp(object):
|
|
|
32
31
|
|
|
33
32
|
# Check if the version is up to date
|
|
34
33
|
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
|
35
|
-
|
|
36
34
|
|
|
37
35
|
self.VERSION = VERSION
|
|
38
36
|
if update_check is True:
|
|
39
37
|
latest = str(requests.get(
|
|
40
38
|
"https://pypi.org/pypi/whatsapp-python/json").json()["info"]["version"])
|
|
41
39
|
if self.VERSION != latest:
|
|
42
|
-
|
|
40
|
+
try:
|
|
41
|
+
version_int = int(self.VERSION.replace(".", ""))
|
|
42
|
+
except:
|
|
43
|
+
version_int = 0
|
|
43
44
|
latest_int = int(latest.replace(".", ""))
|
|
44
45
|
# this is to avoid the case where the version is 1.0.10 and the latest is 1.0.2 (possible if user is using the github version)
|
|
45
46
|
if version_int < latest_int:
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
if version_int == 0:
|
|
48
|
+
logging.critical(
|
|
49
|
+
f"There was an error while checking for updates, please update the package manually or report the issue on GitHub.")
|
|
50
|
+
else:
|
|
51
|
+
logging.critical(
|
|
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.")
|
|
48
53
|
if version_int > latest_int:
|
|
49
54
|
latest_beta = int(str(requests.get(
|
|
50
55
|
"https://raw.githubusercontent.com/filipporomani/whatsapp/main/.version").text).replace(".", ""))
|
|
@@ -54,13 +59,17 @@ class WhatsApp(object):
|
|
|
54
59
|
logging.critical(
|
|
55
60
|
f"You are using a development version of whatsapp-python. Please report any issue on GitHub.")
|
|
56
61
|
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
|
|
63
|
+
if token == "":
|
|
64
|
+
logging.error("Token not provided")
|
|
65
|
+
raise ValueError("Token not provided but required")
|
|
66
|
+
if phone_number_id == "":
|
|
67
|
+
logging.error("Phone number id not provided")
|
|
59
68
|
raise ValueError(
|
|
60
|
-
"
|
|
69
|
+
"Phone number ID not provided but required")
|
|
61
70
|
self.token = token
|
|
62
71
|
self.phone_number_id = phone_number_id
|
|
63
|
-
self.base_url = "https://graph.facebook.com/
|
|
72
|
+
self.base_url = "https://graph.facebook.com/v18.0"
|
|
64
73
|
self.url = f"{self.base_url}/{phone_number_id}/messages"
|
|
65
74
|
|
|
66
75
|
async def base():
|
|
@@ -169,8 +178,8 @@ class WhatsApp(object):
|
|
|
169
178
|
"""
|
|
170
179
|
self.verification_handler = handler
|
|
171
180
|
|
|
172
|
-
def run(self, host: str = "localhost", port: int = 5000,
|
|
173
|
-
self.app
|
|
181
|
+
def run(self, host: str = "localhost", port: int = 5000, **options):
|
|
182
|
+
_run(self.app, host=host, port=port, **options)
|
|
174
183
|
|
|
175
184
|
|
|
176
185
|
class Message(object):
|
whatsapp/constants.py
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
# internal use only
|
|
1
|
+
# internal use only - numbers and . only
|
|
2
2
|
|
|
3
|
-
VERSION = "3.0.
|
|
3
|
+
VERSION = "3.0.6"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: whatsapp-python
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.6
|
|
4
4
|
Summary: Open source Python wrapper for the WhatsApp Cloud API
|
|
5
5
|
Project-URL: Homepage, https://github.com/filipporomani/whatsapp
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/filipporomani/whatsapp/issues
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
whatsapp/__init__.py,sha256=5yVkpN6lRK9L6H2xNyoMeoxZgXT-f-j5X_699vO2k_0,9994
|
|
2
|
+
whatsapp/constants.py,sha256=SkKPPmrV839dBFHzWlbmec3jAog5uZx23EmbCmGExUo,62
|
|
3
|
+
whatsapp/ext/_buttons.py,sha256=GKgxDsansBf4dm4UtZWa-Y-P5ag0TCo36badqyS5fFU,2922
|
|
4
|
+
whatsapp/ext/_media.py,sha256=S8kLfFbZQ1zDCNjdFr5jQYBnuo7tp9FMGsZOGb-h23o,4511
|
|
5
|
+
whatsapp/ext/_message.py,sha256=_0E47iqKdP6YsFXSbSFHJ7TLzL5cSfUiHqbG17FN0Lg,3792
|
|
6
|
+
whatsapp/ext/_property.py,sha256=QS4FjWw21lyLuHnXGy7-2MCP-p0VoMw0gRpgu0OByO8,128
|
|
7
|
+
whatsapp/ext/_send_media.py,sha256=aLdq4a0CyYa_ZNy8KOXEdX2rwA79RbCPp-thMjVxvh0,10036
|
|
8
|
+
whatsapp/ext/_send_others.py,sha256=9Z2zV64Ygxu0LmN9Oy_oomwtgUbk3ZIFEF_3RWxkUDM,2934
|
|
9
|
+
whatsapp/ext/_static.py,sha256=6T9CmHD3XBAH3e2T-w9je1mOfC1HwdBIMaRQjBdR_cQ,9513
|
|
10
|
+
whatsapp_python-3.0.6.dist-info/METADATA,sha256=wD4GA2KF9VnxNNSilWOctTBSm2mbSnW1ekf871_GDLk,5202
|
|
11
|
+
whatsapp_python-3.0.6.dist-info/WHEEL,sha256=TJPnKdtrSue7xZ_AVGkp9YXcvDrobsjBds1du3Nx6dc,87
|
|
12
|
+
whatsapp_python-3.0.6.dist-info/licenses/LICENSE,sha256=HnVLQg1StPmnEJfysP2uUtgEGJ2NsZjAT_5y1WsV8RU,1092
|
|
13
|
+
whatsapp_python-3.0.6.dist-info/RECORD,,
|
examples/example_hook_obj.py
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
from whatsapp import Message, Hook, WhatsApp
|
|
2
|
-
from flask import Response
|
|
3
|
-
from os import getenv
|
|
4
|
-
from dotenv import load_dotenv
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def handler(msg: Message):
|
|
8
|
-
message_type = msg.type
|
|
9
|
-
messenger = msg.instance
|
|
10
|
-
mobile = msg.sender
|
|
11
|
-
|
|
12
|
-
if message_type == "text":
|
|
13
|
-
message = msg.content
|
|
14
|
-
name = msg.name
|
|
15
|
-
m = Message(instance=messenger, to=mobile, content="Hello World")
|
|
16
|
-
m.send()
|
|
17
|
-
|
|
18
|
-
elif message_type == "interactive":
|
|
19
|
-
message_response = msg.interactive
|
|
20
|
-
if message_response is None:
|
|
21
|
-
return Response(status=400)
|
|
22
|
-
interactive_type = message_response.get("type")
|
|
23
|
-
message_id = message_response[interactive_type]["id"]
|
|
24
|
-
message_text = message_response[interactive_type]["title"]
|
|
25
|
-
# Do some action
|
|
26
|
-
|
|
27
|
-
elif message_type == "location":
|
|
28
|
-
message_location = msg.location
|
|
29
|
-
if message_location is None:
|
|
30
|
-
return Response(status=400)
|
|
31
|
-
message_latitude = message_location["latitude"]
|
|
32
|
-
message_longitude = message_location["longitude"]
|
|
33
|
-
# Do some action
|
|
34
|
-
|
|
35
|
-
elif message_type == "image":
|
|
36
|
-
image = msg.image
|
|
37
|
-
if image is None:
|
|
38
|
-
return Response(status=400)
|
|
39
|
-
image_id, mime_type = image["id"], image["mime_type"]
|
|
40
|
-
image_url = messenger.query_media_url(image_id)
|
|
41
|
-
if image_url is None:
|
|
42
|
-
return Response(status=400)
|
|
43
|
-
image_filename = messenger.download_media(image_url, mime_type)
|
|
44
|
-
# Do some action
|
|
45
|
-
|
|
46
|
-
elif message_type == "video":
|
|
47
|
-
video = msg.video
|
|
48
|
-
if video is None:
|
|
49
|
-
return Response(status=400)
|
|
50
|
-
video_id, mime_type = video["id"], video["mime_type"]
|
|
51
|
-
video_url = messenger.query_media_url(video_id)
|
|
52
|
-
if video_url is None:
|
|
53
|
-
return Response(status=400)
|
|
54
|
-
video_filename = messenger.download_media(video_url, mime_type)
|
|
55
|
-
# Do some action
|
|
56
|
-
|
|
57
|
-
elif message_type == "audio":
|
|
58
|
-
audio = msg.audio
|
|
59
|
-
if audio is None:
|
|
60
|
-
return Response(status=400)
|
|
61
|
-
audio_id, mime_type = audio["id"], audio["mime_type"]
|
|
62
|
-
audio_url = messenger.query_media_url(audio_id)
|
|
63
|
-
if audio_url is None:
|
|
64
|
-
return Response(status=400)
|
|
65
|
-
audio_filename = messenger.download_media(audio_url, mime_type)
|
|
66
|
-
# Do some action
|
|
67
|
-
|
|
68
|
-
elif message_type == "document":
|
|
69
|
-
file = msg.document
|
|
70
|
-
if file is None:
|
|
71
|
-
return Response(status=400)
|
|
72
|
-
file_id, mime_type = file["id"], file["mime_type"]
|
|
73
|
-
file_url = messenger.query_media_url(file_id)
|
|
74
|
-
if file_url is None:
|
|
75
|
-
return Response(status=400)
|
|
76
|
-
file_filename = messenger.download_media(file_url, mime_type)
|
|
77
|
-
# Do some action
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
messenger = WhatsApp(token=getenv("TOKEN"),
|
|
81
|
-
phone_number_id=getenv("PHONE_NUMBER_ID"))
|
|
82
|
-
hook = Hook(instance=messenger, handler=handler, port=5000,
|
|
83
|
-
host="0.0.0.0", verify_token=getenv("VERIFY_TOKEN"))
|
|
84
|
-
|
|
85
|
-
hook.run()
|
examples/reply_to_message_obj.py
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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=getenv("ID"))
|
|
8
|
-
|
|
9
|
-
data = {"your": "data"}
|
|
10
|
-
|
|
11
|
-
msg = Message(data=data, instance=messenger)
|
|
12
|
-
msg.reply("lol")
|
|
13
|
-
|
|
14
|
-
print(msg)
|
examples/sending_audio.py
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
from os import getenv
|
|
2
|
-
from whatsapp import WhatsApp
|
|
3
|
-
from dotenv import load_dotenv
|
|
4
|
-
|
|
5
|
-
if __name__ == "__main__":
|
|
6
|
-
load_dotenv()
|
|
7
|
-
messenger = WhatsApp(token=getenv("TOKEN"),
|
|
8
|
-
phone_number_id=getenv("PHONE_NUMBER_ID"))
|
|
9
|
-
|
|
10
|
-
response = messenger.send_audio(
|
|
11
|
-
audio="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3",
|
|
12
|
-
recipient_id="255757xxxxxx",
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
print(response)
|
examples/sending_button.py
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
from os import getenv
|
|
2
|
-
from whatsapp import WhatsApp
|
|
3
|
-
from dotenv import load_dotenv
|
|
4
|
-
|
|
5
|
-
if __name__ == "__main__":
|
|
6
|
-
load_dotenv()
|
|
7
|
-
messenger = WhatsApp(token=getenv("TOKEN"),
|
|
8
|
-
phone_number_id=getenv("PHONE_NUMBER_ID"))
|
|
9
|
-
|
|
10
|
-
response = messenger.send_button(
|
|
11
|
-
recipient_id="255757xxxxxx",
|
|
12
|
-
button={
|
|
13
|
-
"header": "Header Testing",
|
|
14
|
-
"body": "Body Testing",
|
|
15
|
-
"footer": "Footer Testing",
|
|
16
|
-
"action": {
|
|
17
|
-
"button": "Button Testing",
|
|
18
|
-
"sections": [
|
|
19
|
-
{
|
|
20
|
-
"title": "iBank",
|
|
21
|
-
"rows": [
|
|
22
|
-
{"id": "row 1", "title": "Send Money", "description": ""},
|
|
23
|
-
{
|
|
24
|
-
"id": "row 2",
|
|
25
|
-
"title": "Withdraw money",
|
|
26
|
-
"description": "",
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
}
|
|
30
|
-
],
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
)
|
examples/sending_document.py
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
from os import getenv
|
|
2
|
-
from whatsapp import WhatsApp
|
|
3
|
-
from dotenv import load_dotenv
|
|
4
|
-
|
|
5
|
-
if __name__ == "__main__":
|
|
6
|
-
load_dotenv()
|
|
7
|
-
|
|
8
|
-
messenger = WhatsApp(token=getenv("TOKEN"),
|
|
9
|
-
phone_number_id=getenv("PHONE_NUMBER_ID"))
|
|
10
|
-
|
|
11
|
-
response = messenger.send_document(
|
|
12
|
-
document="http://www.africau.edu/images/default/sample.pdf",
|
|
13
|
-
recipient_id="255757294146",
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
print(response)
|
examples/sending_image.py
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
from os import getenv
|
|
2
|
-
from whatsapp import WhatsApp
|
|
3
|
-
from dotenv import load_dotenv
|
|
4
|
-
|
|
5
|
-
if __name__ == "__main__":
|
|
6
|
-
load_dotenv()
|
|
7
|
-
messenger = WhatsApp(token=getenv("TOKEN"),
|
|
8
|
-
phone_number_id=getenv("PHONE_NUMBER_ID"))
|
|
9
|
-
|
|
10
|
-
response = messenger.send_image(
|
|
11
|
-
image="https://i.imgur.com/Fh7XVYY.jpeg",
|
|
12
|
-
recipient_id="255757294146",
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
print(response)
|
examples/sending_location.py
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
from os import getenv
|
|
2
|
-
from whatsapp import WhatsApp
|
|
3
|
-
from dotenv import load_dotenv
|
|
4
|
-
|
|
5
|
-
if __name__ == "__main__":
|
|
6
|
-
load_dotenv()
|
|
7
|
-
messenger = WhatsApp(token=getenv("TOKEN"),
|
|
8
|
-
phone_number_id=getenv("PHONE_NUMBER_ID"))
|
|
9
|
-
|
|
10
|
-
response = messenger.send_location(
|
|
11
|
-
lat=1.29,
|
|
12
|
-
long=103.85,
|
|
13
|
-
name="Singapore",
|
|
14
|
-
address="Singapore",
|
|
15
|
-
recipient_id="255757294146",
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
print(response)
|
examples/sending_message.py
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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"),
|
|
8
|
-
phone_number_id=getenv("PHONE_NUMBER_ID"))
|
|
9
|
-
|
|
10
|
-
msg = Message(instance=messenger,
|
|
11
|
-
content="Hello World!", to="919999999999")
|
|
12
|
-
response = msg.send()
|
|
13
|
-
|
|
14
|
-
print(response)
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
from os import getenv
|
|
2
|
-
from whatsapp import WhatsApp
|
|
3
|
-
from dotenv import load_dotenv
|
|
4
|
-
|
|
5
|
-
if __name__ == "__main__":
|
|
6
|
-
load_dotenv()
|
|
7
|
-
messenger = WhatsApp(token=getenv("TOKEN"),
|
|
8
|
-
phone_number_id=getenv("PHONE_NUMBER_ID"))
|
|
9
|
-
|
|
10
|
-
response = messenger.send_template(
|
|
11
|
-
"hello_world", "255757xxxxxx", components=[], lang="en_US")
|
|
12
|
-
|
|
13
|
-
print(response)
|
examples/sending_video.py
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
from os import getenv
|
|
2
|
-
from whatsapp import WhatsApp
|
|
3
|
-
from dotenv import load_dotenv
|
|
4
|
-
|
|
5
|
-
if __name__ == "__main__":
|
|
6
|
-
load_dotenv()
|
|
7
|
-
messenger = WhatsApp(token=getenv("TOKEN"),
|
|
8
|
-
phone_number_id=getenv("PHONE_NUMBER_ID"))
|
|
9
|
-
|
|
10
|
-
response = messenger.send_video(
|
|
11
|
-
video="https://www.youtube.com/watch?v=K4TOrB7at0Y",
|
|
12
|
-
recipient_id="255757xxxxxx",
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
print(response)
|
examples/standalone_hook.py
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import logging
|
|
3
|
-
from whatsapp import WhatsApp, Message
|
|
4
|
-
from dotenv import load_dotenv
|
|
5
|
-
from flask import Flask, request, Response
|
|
6
|
-
|
|
7
|
-
# Initialize Flask App
|
|
8
|
-
app = Flask(__name__)
|
|
9
|
-
|
|
10
|
-
# Load .env file
|
|
11
|
-
load_dotenv("../.env")
|
|
12
|
-
messenger = WhatsApp(os.getenv("TOKEN"),
|
|
13
|
-
phone_number_id=os.getenv("ID"))
|
|
14
|
-
VERIFY_TOKEN = "30cca545-3838-48b2-80a7-9e43b1ae8ce4"
|
|
15
|
-
|
|
16
|
-
# Logging
|
|
17
|
-
logging.basicConfig(
|
|
18
|
-
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
@app.get("/")
|
|
23
|
-
def verify_token():
|
|
24
|
-
if request.args.get("hub.verify_token") == VERIFY_TOKEN:
|
|
25
|
-
logging.info("Verified webhook")
|
|
26
|
-
challenge = request.args.get("hub.challenge")
|
|
27
|
-
return str(challenge)
|
|
28
|
-
logging.error("Webhook Verification failed")
|
|
29
|
-
return "Invalid verification token"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
@app.post("/")
|
|
33
|
-
def hook():
|
|
34
|
-
# Handle Webhook Subscriptions
|
|
35
|
-
data = request.get_json()
|
|
36
|
-
if data is None:
|
|
37
|
-
return Response(status=200)
|
|
38
|
-
logging.info("Received webhook data: %s", data)
|
|
39
|
-
changed_field = messenger.changed_field(data)
|
|
40
|
-
if changed_field == "messages":
|
|
41
|
-
new_message = messenger.is_message(data)
|
|
42
|
-
if new_message:
|
|
43
|
-
msg = Message(instance=messenger, data=data)
|
|
44
|
-
mobile = msg.sender
|
|
45
|
-
name = msg.name
|
|
46
|
-
message_type = msg.type
|
|
47
|
-
logging.info(
|
|
48
|
-
f"New Message; sender:{mobile} name:{name} type:{message_type}"
|
|
49
|
-
)
|
|
50
|
-
if message_type == "text":
|
|
51
|
-
message = msg.content
|
|
52
|
-
name = msg.name
|
|
53
|
-
logging.info("Message: %s", message)
|
|
54
|
-
m = Message(instance=messenger, to=mobile,
|
|
55
|
-
content="Hello World")
|
|
56
|
-
m.send()
|
|
57
|
-
|
|
58
|
-
elif message_type == "interactive":
|
|
59
|
-
message_response = msg.interactive
|
|
60
|
-
if message_response is None:
|
|
61
|
-
return Response(status=400)
|
|
62
|
-
interactive_type = message_response.get("type")
|
|
63
|
-
message_id = message_response[interactive_type]["id"]
|
|
64
|
-
message_text = message_response[interactive_type]["title"]
|
|
65
|
-
logging.info(
|
|
66
|
-
f"Interactive Message; {message_id}: {message_text}")
|
|
67
|
-
|
|
68
|
-
elif message_type == "location":
|
|
69
|
-
message_location = msg.location
|
|
70
|
-
if message_location is None:
|
|
71
|
-
return Response(status=400)
|
|
72
|
-
message_latitude = message_location["latitude"]
|
|
73
|
-
message_longitude = message_location["longitude"]
|
|
74
|
-
logging.info("Location: %s, %s",
|
|
75
|
-
message_latitude, message_longitude)
|
|
76
|
-
|
|
77
|
-
elif message_type == "image":
|
|
78
|
-
image = msg.image
|
|
79
|
-
if image is None:
|
|
80
|
-
return Response(status=400)
|
|
81
|
-
image_id, mime_type = image["id"], image["mime_type"]
|
|
82
|
-
image_url = messenger.query_media_url(image_id)
|
|
83
|
-
if image_url is None:
|
|
84
|
-
return Response(status=400)
|
|
85
|
-
image_filename = messenger.download_media(image_url, mime_type)
|
|
86
|
-
logging.info(f"{mobile} sent image {image_filename}")
|
|
87
|
-
|
|
88
|
-
elif message_type == "video":
|
|
89
|
-
video = msg.video
|
|
90
|
-
if video is None:
|
|
91
|
-
return Response(status=400)
|
|
92
|
-
video_id, mime_type = video["id"], video["mime_type"]
|
|
93
|
-
video_url = messenger.query_media_url(video_id)
|
|
94
|
-
if video_url is None:
|
|
95
|
-
return Response(status=400)
|
|
96
|
-
video_filename = messenger.download_media(video_url, mime_type)
|
|
97
|
-
logging.info(f"{mobile} sent video {video_filename}")
|
|
98
|
-
|
|
99
|
-
elif message_type == "audio":
|
|
100
|
-
audio = msg.audio
|
|
101
|
-
if audio is None:
|
|
102
|
-
return Response(status=400)
|
|
103
|
-
audio_id, mime_type = audio["id"], audio["mime_type"]
|
|
104
|
-
audio_url = messenger.query_media_url(audio_id)
|
|
105
|
-
if audio_url is None:
|
|
106
|
-
return Response(status=400)
|
|
107
|
-
audio_filename = messenger.download_media(audio_url, mime_type)
|
|
108
|
-
logging.info(f"{mobile} sent audio {audio_filename}")
|
|
109
|
-
|
|
110
|
-
elif message_type == "document":
|
|
111
|
-
file = msg.document
|
|
112
|
-
if file is None:
|
|
113
|
-
return Response(status=400)
|
|
114
|
-
file_id, mime_type = file["id"], file["mime_type"]
|
|
115
|
-
file_url = messenger.query_media_url(file_id)
|
|
116
|
-
if file_url is None:
|
|
117
|
-
return Response(status=400)
|
|
118
|
-
file_filename = messenger.download_media(file_url, mime_type)
|
|
119
|
-
logging.info(f"{mobile} sent file {file_filename}")
|
|
120
|
-
else:
|
|
121
|
-
logging.info(f"{mobile} sent {message_type} ")
|
|
122
|
-
logging.info(data)
|
|
123
|
-
else:
|
|
124
|
-
delivery = messenger.get_delivery(data)
|
|
125
|
-
if delivery:
|
|
126
|
-
logging.info(f"Message : {delivery}")
|
|
127
|
-
else:
|
|
128
|
-
logging.info("No new message")
|
|
129
|
-
return "OK", 200
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if __name__ == "__main__":
|
|
133
|
-
app.run(port=6869, debug=False)
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
examples/example_hook_obj.py,sha256=jlw6kF-BX_ZoYZnUs5yqDqzklQm-wjXO8bQecIRH3U8,3053
|
|
2
|
-
examples/reply_to_message_obj.py,sha256=CNseOMXEDA9y5V8o0y4cQhwf9_vN5drsVg5xu3kYp3M,346
|
|
3
|
-
examples/sending_audio.py,sha256=AAjIgNobQqqmVqz_IlawR1qeX9JpLUeVE3XbZANFFqw,441
|
|
4
|
-
examples/sending_button.py,sha256=CULZ9kpnIn17e6__ZrYy-VGxuY87AU8zSqd4UqHqvdA,1088
|
|
5
|
-
examples/sending_document.py,sha256=C5ofmLuWrLLFnn-JSw4qqDciTd6b1Cg4Kcuiht2qWa4,436
|
|
6
|
-
examples/sending_image.py,sha256=Kw4Wo-HjRsHhBXoGxElPak2zmvEwZqTJFOmtvcN14lY,412
|
|
7
|
-
examples/sending_location.py,sha256=qyP5vMkPx7x97AZD4q7ptPz7aEF0QELN84Sx_p0GRsA,462
|
|
8
|
-
examples/sending_message.py,sha256=QYPM1JigdB7nIcSdZqzcJ_y9wCx5VB0vKSwHPMpCNUE,415
|
|
9
|
-
examples/sending_template_message.py,sha256=tXO8LPXdLq21m8RaLS4m0GArMFKi61N0mvbicGiAJow,388
|
|
10
|
-
examples/sending_video.py,sha256=LtlKf-GlMU36L_3WBf6XIcjQlaSK0GcIECTt_iRXgCg,423
|
|
11
|
-
examples/standalone_hook.py,sha256=9MGmLB92IUg5lj1sTpWs-0k_85E8IfHOOpffUsr-Aq8,5330
|
|
12
|
-
whatsapp/__init__.py,sha256=Oyqhs51ILr5-01ek982FYF-7_fVt-KLKVbyNnpB45cc,9540
|
|
13
|
-
whatsapp/constants.py,sha256=2mMLccNiBw11OSNRzgPDjKfVc249U8yLpNqh2KNRzJs,40
|
|
14
|
-
whatsapp/ext/_buttons.py,sha256=GKgxDsansBf4dm4UtZWa-Y-P5ag0TCo36badqyS5fFU,2922
|
|
15
|
-
whatsapp/ext/_media.py,sha256=S8kLfFbZQ1zDCNjdFr5jQYBnuo7tp9FMGsZOGb-h23o,4511
|
|
16
|
-
whatsapp/ext/_message.py,sha256=_0E47iqKdP6YsFXSbSFHJ7TLzL5cSfUiHqbG17FN0Lg,3792
|
|
17
|
-
whatsapp/ext/_property.py,sha256=QS4FjWw21lyLuHnXGy7-2MCP-p0VoMw0gRpgu0OByO8,128
|
|
18
|
-
whatsapp/ext/_send_media.py,sha256=aLdq4a0CyYa_ZNy8KOXEdX2rwA79RbCPp-thMjVxvh0,10036
|
|
19
|
-
whatsapp/ext/_send_others.py,sha256=9Z2zV64Ygxu0LmN9Oy_oomwtgUbk3ZIFEF_3RWxkUDM,2934
|
|
20
|
-
whatsapp/ext/_static.py,sha256=6T9CmHD3XBAH3e2T-w9je1mOfC1HwdBIMaRQjBdR_cQ,9513
|
|
21
|
-
whatsapp_python-3.0.4.dist-info/METADATA,sha256=C0qVeKtRpxRmnQeYs_pw8YFT2u7w7CKjk4I5_6Fh-Mc,5202
|
|
22
|
-
whatsapp_python-3.0.4.dist-info/WHEEL,sha256=9QBuHhg6FNW7lppboF2vKVbCGTVzsFykgRQjjlajrhA,87
|
|
23
|
-
whatsapp_python-3.0.4.dist-info/licenses/LICENSE,sha256=HnVLQg1StPmnEJfysP2uUtgEGJ2NsZjAT_5y1WsV8RU,1092
|
|
24
|
-
whatsapp_python-3.0.4.dist-info/RECORD,,
|
|
File without changes
|