LemonChannels. CapabilityQuery
(lemon_channels v0.1.0)
View Source
Query API for channel capabilities.
Provides a clean interface for tools to query channel capabilities and determine how to render content for different channels.
Usage
# Check if a channel supports a capability
CapabilityQuery.supports?("telegram", :attachments)
# => true
# Check for specific features
CapabilityQuery.supports_feature?("discord", :rich_blocks, :markdown)
# => true
# Validate before sending
CapabilityQuery.validate("telegram", :attachments, %{size: 5_000_000})
# => :ok
# Get fallback strategy
CapabilityQuery.fallback_for("xmtp", :rich_blocks)
# => {:ok, {:text, "[Rich content not supported]"}}
# Compare capabilities across channels
CapabilityQuery.compare(["telegram", "discord", "xmtp"], :attachments)
# => %{"telegram" => true, "discord" => true, "xmtp" => false}
Summary
Functions
Returns capability information for all registered channels.
Gets the intersection of capabilities across multiple channels.
Compares a capability across multiple channels.
Returns suggested fallback options for unsupported capabilities.
Gets a capability's full configuration for a channel.
Lists all supported capabilities for a channel.
Selects the best representation for content based on channel capabilities.
Checks if a channel supports a specific capability.
Checks if a channel supports a specific feature within a capability.
Validates a capability request against a channel's capabilities.
Functions
Returns capability information for all registered channels.
Examples
CapabilityQuery.all()
# => [
# %{channel_id: "telegram", supports: [:threads, :reactions, ...]},
# %{channel_id: "discord", supports: [:threads, :edit, ...]}
# ]
Gets the intersection of capabilities across multiple channels.
Returns the set of capabilities that ALL channels support.
Examples
CapabilityQuery.common(["telegram", "discord"])
# => [:threads, :edit, :delete, :attachments]
Compares a capability across multiple channels.
Examples
CapabilityQuery.compare(["telegram", "discord", "xmtp"], :attachments)
# => %{"telegram" => true, "discord" => true, "xmtp" => false}
Returns suggested fallback options for unsupported capabilities.
Examples
CapabilityQuery.fallback_for("xmtp", :rich_blocks)
# => {:ok, {:text, "[Rich content not supported]"}}
@spec get(String.t() | atom(), atom()) :: LemonChannels.Capabilities.Capability.t() | nil
Gets a capability's full configuration for a channel.
Examples
CapabilityQuery.get("telegram", :attachments)
# => %Capability{type: :attachments, enabled: true, config: %{max_size: 20000000}}
Lists all supported capabilities for a channel.
Examples
CapabilityQuery.list("telegram")
# => [:attachments, :rich_blocks, :threads, :reactions, :edit, :delete, :voice]
Selects the best representation for content based on channel capabilities.
Examples
CapabilityQuery.select_representation("telegram", [
{:rich_blocks, [%{type: :section, text: "Hello"}]},
{:text, "Hello"}
])
# => {:rich_blocks, [%{type: :section, text: "Hello"}]}
CapabilityQuery.select_representation("xmtp", [
{:rich_blocks, [%{type: :section, text: "Hello"}]},
{:text, "Hello"}
])
# => {:text, "Hello"}
Checks if a channel supports a specific capability.
Examples
CapabilityQuery.supports?("telegram", :attachments)
# => true
CapabilityQuery.supports?("xmtp", :attachments)
# => false
Checks if a channel supports a specific feature within a capability.
Examples
CapabilityQuery.supports_feature?("telegram", :rich_blocks, :markdown)
# => true
CapabilityQuery.supports_feature?("discord", :rich_blocks, :buttons)
# => false
Validates a capability request against a channel's capabilities.
Examples
CapabilityQuery.validate("telegram", :attachments, %{size: 5_000_000})
# => :ok
CapabilityQuery.validate("telegram", :attachments, %{size: 50_000_000})
# => {:error, :file_too_large}