Module: Ask::Content
- Defined in:
- lib/ask/content.rb
Overview
Content types for multi-modal messages.
These are frozen value objects representing different kinds of content that can appear in an Message. A message's content_blocks may contain multiple content objects of different types, allowing text, images, audio, video, and files to be interleaved naturally.
All content types are frozen value objects with structural equality. They carry the minimum fields needed for provider-agnostic use; each provider serializes them to its own wire format.
Defined Under Namespace
Modules: Block Classes: Audio, File, Image, Media, Text, Video
Class Method Summary collapse
-
.from_h(hash) ⇒ Block
Rebuild a content block from a
to_hhash (persistence round-trips).
Class Method Details
.from_h(hash) ⇒ Block
Rebuild a content block from a to_h hash (persistence round-trips).
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/ask/content.rb', line 223 def self.from_h(hash) hash = hash.transform_keys(&:to_s) case hash["type"] when "text" Text.new(hash["text"].to_s) when "image" Image.new(**media_args(hash)) when "audio" Audio.new(**media_args(hash)) when "video" Video.new(**media_args(hash)) when "file" File.new( data: hash["data"], mime_type: hash["mime_type"], filename: hash["filename"], url: hash["url"], file_id: hash["file_id"] ) else raise ArgumentError, "Unknown content block type: #{hash["type"].inspect}" end end |