Class: Whatsapp::MessageHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/whatsapp/message_handler.rb

Overview

Base class for incoming message handlers.

Subclass this and implement +#call+ to process incoming WhatsApp messages. Configure the handler in your initializer:

Whatsapp.configure do |config| config.message_handler = WhatsappMessageHandler end

Examples:

class WhatsappMessageHandler < Whatsapp::MessageHandler
  def call(message, session:)
    case message.text
    when /^book/i
      BookingService.create_from_whatsapp(message)
    when /^help/i
      # Reply logic...
    end
  end
end

Instance Method Summary collapse

Instance Method Details

#call(message, session:) ⇒ void

This method returns an undefined value.

Process an incoming message.

Parameters:

  • message (Message)

    the incoming WhatsApp message

  • session (String)

    the session name that received the message

Raises:

  • (NotImplementedError)

    if not overridden in subclass



30
31
32
# File 'lib/whatsapp/message_handler.rb', line 30

def call(message, session:)
  raise NotImplementedError, "#{self.class}#call must be implemented"
end