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

all()

@spec all() :: [%{channel_id: String.t(), supports: [atom()], capabilities: map()}]

Returns capability information for all registered channels.

Examples

CapabilityQuery.all()
# => [
#   %{channel_id: "telegram", supports: [:threads, :reactions, ...]},
#   %{channel_id: "discord", supports: [:threads, :edit, ...]}
# ]

common(channel_ids)

@spec common([String.t() | atom()]) :: [atom()]

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]

compare(channel_ids, capability_type)

@spec compare([String.t() | atom()], atom()) :: %{required(String.t()) => boolean()}

Compares a capability across multiple channels.

Examples

CapabilityQuery.compare(["telegram", "discord", "xmtp"], :attachments)
# => %{"telegram" => true, "discord" => true, "xmtp" => false}

fallback_for(channel_id, capability_type)

@spec fallback_for(String.t() | atom(), atom()) ::
  {:ok, term()} | {:error, :no_fallback}

Returns suggested fallback options for unsupported capabilities.

Examples

CapabilityQuery.fallback_for("xmtp", :rich_blocks)
# => {:ok, {:text, "[Rich content not supported]"}}

get(channel_id, capability_type)

Gets a capability's full configuration for a channel.

Examples

CapabilityQuery.get("telegram", :attachments)
# => %Capability{type: :attachments, enabled: true, config: %{max_size: 20000000}}

list(channel_id)

@spec list(String.t() | atom()) :: [atom()]

Lists all supported capabilities for a channel.

Examples

CapabilityQuery.list("telegram")
# => [:attachments, :rich_blocks, :threads, :reactions, :edit, :delete, :voice]

select_representation(channel_id, representations)

@spec select_representation(String.t() | atom(), [{atom(), term()}]) ::
  {atom(), term()} | nil

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"}

supports?(channel_id, capability_type)

@spec supports?(String.t() | atom(), atom()) :: boolean()

Checks if a channel supports a specific capability.

Examples

CapabilityQuery.supports?("telegram", :attachments)
# => true

CapabilityQuery.supports?("xmtp", :attachments)
# => false

supports_feature?(channel_id, capability_type, feature)

@spec supports_feature?(String.t() | atom(), atom(), atom()) :: boolean()

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

validate(channel_id, capability_type, params)

@spec validate(String.t() | atom(), atom(), map()) :: :ok | {:error, term()}

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}