Skip to content

Bug: KeyError in from_contact on message status webhook event #227

Description

@riklaunim

Short summary

Message status update contains only wa_id for a contact

Steps to reproduce

pywa 4.4.0, I got a message status update on webhook and it throws user_id KeyError in from_contact as the data dict there only has wa_id.

{'object': 'whatsapp_business_account', 'entry': [{'id': '1....', 'changes': [{'value': {'messaging_product': 'whatsapp', 'metadata': {'display_phone_number': '1....', 'phone_number_id': '1....'}, 'contacts': [{'wa_id': '4....'}], 'statuses': [{'id': 'wamid.H....', 'status': 'failed', 'timestamp': '1....', 'recipient_id': '4...', 'errors': [{'code': 131026, 'title': 'Message undeliverable', 'message': 'Message undeliverable', 'error_data': {'details': 'Message Undeliverable.'}}]}]}, 'field': 'messages'}]}]}

Expected behavior

No response

Logs / Traceback

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/pywa/server.py", line 405, in _call_handlers
    ].from_update(client=self, update=raw_update)
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pywa/types/message_status.py", line 170, in from_update
    from_user=client._usr_cls.from_contact(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pywa/types/user.py", line 95, in from_contact
    bsuid=data["user_id"],
          ~~~~^^^^^^^^^^^
KeyError: 'user_id'

pywa version

4.4.0

Python version

No response

OS

No response

Minimal reproduction

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions