david-lev / pywa

🤖 Build WhatsApp Bots in Python
https://pywa.readthedocs.io
MIT License
221 stars 33 forks source link

Adding tracker to messages #51

Closed yehuda-lev closed 4 months ago

yehuda-lev commented 4 months ago

WhatsApp Cloud API has the option to add to any message an optional param called biz_opaque_callback_data, this param value is returned with the message status (sent read etc) and can be used to track messages from specific type for stats or graphs etc.

In PyWa this param name will be called tracker to simplify the reason of using this param.

from pywa import WhatsApp

wa = WhatsApp(...)
wa.send_message(to=...., text="Hi from pywa!", tracker="start_msg")
from pywa import WhatsApp, types, filters

wa = WhatsApp(...)

@wa.on_message_status(filters.message_status.read, filters.message_status.with_tracker)
def on_message_read_with_tracker(_: WhatsApp, status: types.MessageStatus):
    if status.tracker == "start_msg":
        print("The message has just been read")