Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update __init__.py #21

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions heyoo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ def __init__(self, token=None, phone_number_id=None):
phone_number_id[str]: Phone number id for the WhatsApp cloud API obtained from the developer portal
"""
self.token = token
self.url = f"https://graph.facebook.com/v13.0/{phone_number_id}/messages"
self.base_url = 'https://graph.facebook.com/v13.0'
self.url = f"{self.base_url}/{phone_number_id}/messages"

self.headers = {
"Content-Type": "application/json",
"Authorization": "Bearer {}".format(self.token),
Expand Down Expand Up @@ -223,7 +225,7 @@ def send_video(self, video, recipient_id, caption=None, link=True):
video[str]: Video id or link of the video
recipient_id[str]: Phone number of the user with country code wihout +
caption[str]: Caption of the video
link[bool]: Whether to send an video id or an video link, True means that the video is an id, False means that the video is a link
link[bool]: Whether to send a video id or a video link, True means that the video is an id, False means that the video is a link

example:
>>> from whatsapp import WhatsApp
Expand Down Expand Up @@ -256,7 +258,7 @@ def send_document(self, document, recipient_id, caption=None, link=True):
document[str]: Document id or link of the document
recipient_id[str]: Phone number of the user with country code wihout +
caption[str]: Caption of the document
link[bool]: Whether to send an document id or an document link, True means that the document is an id, False means that the document is a link
link[bool]: Whether to send a document id or a document link, True means that the document is an id, False means that the document is a link

Example:
>>> from whatsapp import WhatsApp
Expand Down Expand Up @@ -352,7 +354,7 @@ def query_media_url(self, media_id):
>>> whatsapp = WhatsApp(token, phone_number_id)
>>> whatsapp.query_media_url("media_id")
"""
r = requests.get(f"{self.BASE_URL}{media_id}", headers=self.headers)
r = requests.get(f"{self.base_url}{media_id}", headers=self.headers)
if r.status_code == 200:
return r.json()["url"]
return None
Expand Down