green-api / whatsapp-chatbot-python

This library helps you easily create a Python chatbot with WhatsApp API.
https://green-api.com/en
Other
44 stars 12 forks source link

Any way to handle incoming WA calls via bot.router webhooks? #36

Open dimitrii9000 opened 4 months ago

lent0s commented 4 months ago

@dimitrii9000 Good afternoon! To process incoming call notifications, you must enable the "incomingCallWebhook": "yes" option in the instance settings You can get acquainted with the type of webhook notifications about calls here

lent0s commented 4 months ago

@dimitrii9000 At the moment, the bot does not have an incoming call handler. Clients can add it themselves. We will take your wishes into account and add this feature in future releases

dimitrii9000 commented 4 months ago

Thanks! For any other interested parties, it's quite easy to add custom handler to handle calls

from whatsapp_chatbot_python.manager.observer import Observer

class WhatsappMessageHandler:
    def __init__(self, bot: GreenAPIBot):
        self.bot = bot
        self.bot.router.incoming_call = Observer(self.bot.router)
        self.bot.router.observers["incomingCall"] = self.bot.router.incoming_call

        @self.bot.router.incoming_call()
        def message_handler(notification: Notification) -> None:
            logging.info(notification.event)