Flow Completion

Flow Completion#

The FlowCompletion class represents an update that arrives when user completes a flow.

class pywa.types.FlowCompletion#

A flow completion message. This update arrives when a user completes a flow.

Variables:
  • id – The message ID (If you want to reply to the message, use message_id_to_reply instead).

  • metadata – The metadata of the message (to which phone number it was sent).

  • type (MessageType) – The message type (Always MessageType.INTERACTIVE).

  • from_user – The user who sent the message.

  • timestamp – The timestamp when the message was sent (in UTC).

  • reply_to_message (ReplyToMessage | None) – The message to which this message is a reply to.

  • body (str) – The body of the message.

  • token (str | None) – The token of the flow. can be None in some cases :|

  • response (dict[str, Any]) – The response from the flow.

  • shared_data – Shared data between handlers.

get_media(media_cls, key, index=0)#

Get the media object from the response.

Example

>>> from pywa import WhatsApp, types
>>> wa = WhatsApp(...)
>>> @wa.on_flow_completion
... def on_flow_completion(_: WhatsApp, flow: types.FlowCompletion):
...     img = flow.get_media(types.Image,key="image")
...     img.download()
Parameters:
  • media_cls (Type[_FlowResMediaType]) – The media class to create the media object (e.g. types.Image).

  • key (str) – The key of the media in the response.

  • index (int) – The index of the media in the response (default to 0).

Returns:

The media object.

Raises:
  • KeyError – If the key is not found in the response.

  • ValueError – If the response has no data.

  • IndexError – If the index is out of range.

Return type:

_FlowResMediaType