Skip to content

Message Handling#

The bot automatically handles different types of WhatsApp messages and converts them into a format that OpenAI models can understand.

Supported Message Types#

  • Text: Plain text messages
  • Images: Photos with optional captions (supported on models with image processing capabilities)
  • Audio: Voice messages with automatic transcription
  • Video: Video messages with captions
  • Documents: File attachments
  • Polls: Messages with polls and poll updates
  • Location: Location sharing
  • Contacts: Contact sharing

Message Handler Registry#

The bot uses a registry of message handlers to handle different message types:

# Accessing the registry
registry = bot.message_handlers

# Creating a custom message handler
class CustomMessageHandler(MessageHandler):
def can_handle(self, notification):
return notification.get_message_type() == "custom-type"

async def process_message(self, notification, openai_client=None, model=None):
# Process the message
return "Processed content"

# Register a custom handler
bot.register_message_handler(CustomMessageHandler())

# Replace an existing handler
bot.replace_handler(TextMessageHandler, CustomTextHandler())