class Event
Represents a Matrix event received via the Application Service API.
Provides typed accessors for all envelope fields plus schema-driven validation using the official Matrix spec YAML schemas.
event = Event.new(raw_hash) event.type # => "m.room.message" event.sender # => "@alice:example.org" event.content.body # => "hello" event.valid? # => true event.valid! # => true (or raises Schema::ValidationError)
Definitions
def schema
The JSONSchemer::Schema for this event's type, or nil if unknown.
Implementation
def schema
Schema[@type]
end
def valid?
Validate this event against its schema. Returns true if valid or if no schema exists (lenient).
Implementation
def valid?
Schema.valid?(@raw)
end
def valid!
Validate this event against its schema. Raises Schema::ValidationError with detailed errors on failure. Returns true if valid or if no schema exists.
Implementation
def valid!
errors = Schema.validate(@raw)
unless errors.empty?
raise Schema::ValidationError.new(
errors,
event_type: @type,
event_id: @event_id
)
end
true
end
def content_properties
Content property names defined by the schema for this event type.
Implementation
def content_properties
Schema.content_properties(@type)
end
def state_event?
Is this a state event? (has a state_key)
Implementation
def state_event?
!@state_key.nil?
end