Files
self 1fb848b8cb feat: namespace plugin identity
Adopt canonical plugin id/slug manifest fields, vendor-prefixed OTP app naming, and fully-qualified capability ids for Sender.
2026-05-27 19:05:39 +02:00

47 lines
1.1 KiB
Elixir

defmodule TribeOne.TribesPlugin.Sender.ChatIntegration do
@moduledoc false
@chat_capability "org.tribe-one.caps.chat@1"
def embedded_panel(slug, opts \\ []) when is_binary(slug) do
with {:ok, provider} <- provider_module(),
true <- function_exported?(provider, :embedded_panel, 2),
{:ok, surface} <- provider.embedded_panel(slug, opts) do
{:ok, surface}
else
_other -> :unavailable
end
rescue
_error -> :unavailable
end
def channel_slug(stream_id \\ "default") when is_binary(stream_id) do
"sender-stream-" <> slugify(stream_id)
end
def chat_available? do
match?({:ok, _provider}, provider_module())
rescue
_error -> false
end
defp provider_module do
if Code.ensure_loaded?(Tribes.Plugin.Registry) do
Tribes.Plugin.Registry.provider_module(@chat_capability)
else
:error
end
end
defp slugify(value) do
value
|> String.downcase()
|> String.replace(~r/[^a-z0-9]+/u, "-")
|> String.trim("-")
|> case do
"" -> "default"
slug -> slug
end
end
end