Skip to content

Commit

Permalink
fix: typo in urls
Browse files Browse the repository at this point in the history
This caused the library to be broken and was caused by a typo while replacing strings in the files.
  • Loading branch information
filipporomani committed Oct 14, 2024
1 parent 09fcf30 commit 6416268
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 18 deletions.
4 changes: 2 additions & 2 deletions whatsapp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def makeversion(table):
"Phone number ID not provided but required")
self.token = token
self.phone_number_id = phone_number_id
self.base_url = "https://graph.facebook.com/v{self.LATEST}"
self.base_url = f"https://graph.facebook.com/{self.LATEST}"
self.url = f"{self.base_url}/{phone_number_id}/messages"
self.verify_token = verify_token

Expand Down Expand Up @@ -362,7 +362,7 @@ def send(self, sender=None, preview_url: bool = True) -> dict:
if sender == None:
sender = self.instance.phone_number_id

url = f"https://graph.facebook.com/v{self.instance.LATEST}/{sender}/messages"
url = f"https://graph.facebook.com/{self.instance.LATEST}/{sender}/messages"
data = {
"messaging_product": "whatsapp",
"recipient_type": self.rec,
Expand Down
16 changes: 13 additions & 3 deletions whatsapp/ext/_buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def send_button(self, button: Dict[Any, Any], recipient_id: str, sender=None) ->
if sender == None:
sender = self.phone_number_id

url = f"https://graph.facebook.com/v{self.LATEST}/{sender}/messages"
url = f"https://graph.facebook.com/{self.instance.LATEST}/{sender}/messages"
data = {
"messaging_product": "whatsapp",
"to": recipient_id,
Expand All @@ -60,7 +60,7 @@ def send_button(self, button: Dict[Any, Any], recipient_id: str, sender=None) ->


def send_reply_button(
self, button: Dict[Any, Any], recipient_id: str
self, button: Dict[Any, Any], recipient_id: str, sender=None
) -> Dict[Any, Any]:
"""
Sends an interactive reply buttons[menu] message to a WhatsApp user
Expand All @@ -72,6 +72,16 @@ def send_reply_button(
Note:
The maximum number of buttons is 3, more than 3 buttons will rise an error.
"""
try:
sender = dict(self.l)[sender]

except:
sender = self.phone_number_id

if sender == None:
sender = self.phone_number_id

url = f"https://graph.facebook.com/{self.instance.LATEST}/{sender}/messages"
if len(button["action"]["buttons"]) > 3:
raise ValueError("The maximum number of buttons is 3.")

Expand All @@ -82,7 +92,7 @@ def send_reply_button(
"type": "interactive",
"interactive": button,
}
r = requests.post(self.url, headers=self.headers, json=data)
r = requests.post(url, headers=self.headers, json=data)
if r.status_code == 200:
logging.info(f"Reply buttons sent to {recipient_id}")
return r.json()
Expand Down
2 changes: 1 addition & 1 deletion whatsapp/ext/_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def upload_media(self, media: str, sender=None) -> Union[Dict[Any, Any], None]:
if sender == None:
sender = self.phone_number_id

url = f"https://graph.facebook.com/v{self.LATEST}/{sender}/media"
url = f"https://graph.facebook.com/{self.instance.LATEST}/{sender}/media"
form_data = {
"file": (
media,
Expand Down
8 changes: 4 additions & 4 deletions whatsapp/ext/_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def send_template(self, template: str, recipient_id: str, components: str = None
if sender == None:
sender = self.phone_number_id

url = f"https://graph.facebook.com/v{self.LATEST}/{sender}/messages"
url = f"https://graph.facebook.com/{self.instance.LATEST}/{sender}/messages"
data = {
"messaging_product": "whatsapp",
"to": recipient_id,
Expand Down Expand Up @@ -114,7 +114,7 @@ def mark_as_read(self) -> dict:


def send(self, preview_url: bool = True) -> dict:
url = f"https://graph.facebook.com/v{self.LATEST}/{self.sender}/messages"
url = f"https://graph.facebook.com/{self.LATEST}/{self.sender}/messages"
data = {
"messaging_product": "whatsapp",
"recipient_type": self.rec,
Expand All @@ -123,11 +123,11 @@ def send(self, preview_url: bool = True) -> dict:
"text": {"preview_url": preview_url, "body": self.content},
}
logging.info(f"Sending message to {self.to}")
r = requests.post(f"{url}", headers=self.headers, json=data)
r = requests.post(url, headers=self.headers, json=data)
if r.status_code == 200:
logging.info(f"Message sent to {self.to}")
return r.json()
logging.info(f"Message not sent to {self.to}")
logging.info(f"Status code: {r.status_code}")
logging.error(f"Response: {r.json()}")
logging.error(f"Response fddfscsad: {r.json()}")
return r.json()
12 changes: 6 additions & 6 deletions whatsapp/ext/_send_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def send_location(self, lat: str, long: str, name: str, address: str, recipient_
if sender == None:
sender = self.phone_number_id

url = f"https://graph.facebook.com/v{self.LATEST}/{sender}/messages"
url = f"https://graph.facebook.com/{self.instance.LATEST}/{sender}/messages"
data = {
"messaging_product": "whatsapp",
"to": recipient_id,
Expand Down Expand Up @@ -91,7 +91,7 @@ def send_image(
if sender == None:
sender = self.phone_number_id

url = f"https://graph.facebook.com/v{self.LATEST}/{sender}/messages"
url = f"https://graph.facebook.com/{self.instance.LATEST}/{sender}/messages"
if link:
data = {
"messaging_product": "whatsapp",
Expand Down Expand Up @@ -149,7 +149,7 @@ def send_sticker(self, sticker: str, recipient_id: str, recipient_type: str = "i
if sender == None:
sender = self.phone_number_id

url = f"https://graph.facebook.com/v{self.LATEST}/{sender}/messages"
url = f"https://graph.facebook.com/{self.instance.LATEST}/{sender}/messages"
if link:
data = {
"messaging_product": "whatsapp",
Expand Down Expand Up @@ -203,7 +203,7 @@ def send_audio(self, audio: str, recipient_id: str, link: bool = True, sender =
if sender == None:
sender = self.phone_number_id

url = f"https://graph.facebook.com/v{self.LATEST}/{sender}/messages"
url = f"https://graph.facebook.com/{self.instance.LATEST}/{sender}/messages"
if link:
data = {
"messaging_product": "whatsapp",
Expand Down Expand Up @@ -258,7 +258,7 @@ def send_video(
if sender == None:
sender = self.phone_number_id

url = f"https://graph.facebook.com/v{self.LATEST}/{sender}/messages"
url = f"https://graph.facebook.com/{self.instance.LATEST}/{sender}/messages"
if link:
data = {
"messaging_product": "whatsapp",
Expand Down Expand Up @@ -312,7 +312,7 @@ def send_document(
if sender == None:
sender = self.phone_number_id

url = f"https://graph.facebook.com/v{self.LATEST}/{sender}/messages"
url = f"https://graph.facebook.com/{self.instance.LATEST}/{sender}/messages"
if link:
data = {
"messaging_product": "whatsapp",
Expand Down
4 changes: 2 additions & 2 deletions whatsapp/ext/_send_others.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def send_custom_json(self, data: dict, recipient_id: str = "", sender=None):
if sender == None:
sender = self.phone_number_id

url = f"https://graph.facebook.com/v{self.LATEST}/{sender}/messages"
url = f"https://graph.facebook.com/{self.instance.LATEST}/{sender}/messages"

if recipient_id:
if "to" in data.keys():
Expand Down Expand Up @@ -88,7 +88,7 @@ def send_contacts(
if sender == None:
sender = self.phone_number_id

url = f"https://graph.facebook.com/v{self.LATEST}/{sender}/messages"
url = f"https://graph.facebook.com/{self.instance.LATEST}/{sender}/messages"

data = {
"messaging_product": "whatsapp",
Expand Down

0 comments on commit 6416268

Please sign in to comment.