Class: Nanobot::Bus::InboundMessage

Inherits:
Struct
  • Object
show all
Defined in:
lib/nanobot/bus/events.rb

Overview

InboundMessage represents a message coming into the system from a channel

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel:, sender_id:, chat_id:, content:, **opts) ⇒ InboundMessage

Returns a new instance of InboundMessage.

Parameters:

  • channel (String) —

    source channel name (e.g. 'telegram', 'slack')

  • sender_id (String) —

    unique identifier for the message sender

  • chat_id (String) —

    unique identifier for the chat/conversation

  • content (String) —

    message text content

  • opts (Hash) —

    optional fields: :timestamp, :media, :metadata



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/nanobot/bus/events.rb', line 23

def initialize(channel:, sender_id:, chat_id:, content:, **opts)
  super(
    channel: channel,
    sender_id: sender_id,
    chat_id: chat_id,
    content: content,
    timestamp: opts[:timestamp] || Time.now,
    media: opts[:media] || [],
    metadata: opts[:metadata] || {}
  )
end

Instance Attribute Details

#channel ⇒ Object

Returns the value of attribute channel

Returns:

  • (Object) —

    the current value of channel



8
9
10
# File 'lib/nanobot/bus/events.rb', line 8

def channel
  @channel
end

#chat_id ⇒ Object

Returns the value of attribute chat_id

Returns:

  • (Object) —

    the current value of chat_id



8
9
10
# File 'lib/nanobot/bus/events.rb', line 8

def chat_id
  @chat_id
end

#content ⇒ Object

Returns the value of attribute content

Returns:

  • (Object) —

    the current value of content



8
9
10
# File 'lib/nanobot/bus/events.rb', line 8

def content
  @content
end

#media ⇒ Object

Returns the value of attribute media

Returns:

  • (Object) —

    the current value of media



8
9
10
# File 'lib/nanobot/bus/events.rb', line 8

def media
  @media
end

#metadata ⇒ Object

Returns the value of attribute metadata

Returns:

  • (Object) —

    the current value of metadata



8
9
10
# File 'lib/nanobot/bus/events.rb', line 8

def 
  @metadata
end

#sender_id ⇒ Object

Returns the value of attribute sender_id

Returns:

  • (Object) —

    the current value of sender_id



8
9
10
# File 'lib/nanobot/bus/events.rb', line 8

def sender_id
  @sender_id
end

#timestamp ⇒ Object

Returns the value of attribute timestamp

Returns:

  • (Object) —

    the current value of timestamp



8
9
10
# File 'lib/nanobot/bus/events.rb', line 8

def timestamp
  @timestamp
end

Instance Method Details

#session_key ⇒ String

Generates a unique session key combining channel and chat_id

Returns:

  • (String) —

    key in the format "channel:chat_id"



37
38
39
# File 'lib/nanobot/bus/events.rb', line 37

def session_key
  "#{channel}:#{chat_id}"
end