Skip to content

Commit

Permalink
feat: add reaction to message
Browse files Browse the repository at this point in the history
fixes #38
Added the reaction feature.
  • Loading branch information
filipporomani committed Aug 13, 2024
1 parent f3eee22 commit a8906a4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ I fixed some bugs and added many features, however the library still needs a lot
- Listening to events (messages, media, etc.)
- Sending messages
- Marking messages as read
- Reacting to messages
- Sending Media (images, audio, video and documents)
- Sending location
- Sending interactive buttons
Expand Down
2 changes: 1 addition & 1 deletion whatsapp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,4 @@ def __init__(self, id: int = None, data: dict = {}, instance: WhatsApp = None, c
except:
pass

from .ext._message import send, reply, mark_as_read
from .ext._message import send, reply, mark_as_read, react
19 changes: 19 additions & 0 deletions whatsapp/ext/_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@
import requests


def react(self, emoji: str) -> dict:
data = {
"messaging_product": "whatsapp",
"recipient_type":"individual",
"to": self.sender,
"type": "reaction",
"reaction": {"message_id": self.id, "emoji": emoji},
}
logging.info(f"Reacting to {self.id}")
r = requests.post(self.url, headers=self.headers, json=data)
if r.status_code == 200:
logging.info(f"Reaction sent to {self.to}")
return r.json()
logging.info(f"Reaction not sent to {self.to}")
logging.info(f"Status code: {r.status_code}")
logging.debug(f"Response: {r.json()}")
return r.json()


def send_template(self, template: str, recipient_id: str, components: str, lang: str = "en_US") -> dict:
"""
Sends a template message to a WhatsApp user, Template messages can either be;
Expand Down

0 comments on commit a8906a4

Please sign in to comment.