Cyclium. Conversations. LiveHelpers
(Cyclium v0.1.5)
Copy Markdown
Reusable helpers for conversation LiveViews.
Provides bus event handling, message loading from episodes, and conversation
lifecycle management. Consuming apps use this module to get module attributes
and import the helper functions.
Usage
defmodule MyAppWeb.ConversationLive.Show do
use MyAppWeb, :live_view
use Cyclium.Conversations.LiveHelpers, actor_id: "my_actor"
# @__actor_id and @__dispatch are set for you.
# All helper functions are imported.
endOptions
:actor_id— required, the actor identifier for filtering bus events:dispatch— dispatch module (default:Cyclium.Conversations.Dispatch)
Summary
Functions
Dispatch a user message. Appends the user message to the message list and creates the episode.
Reconstruct chat messages from completed episodes in a conversation.
Load or create a conversation based on params and live_action.
Returns {conversation, messages}.
Handle a conversation status change event. Returns updated conversation or :ignore.
Handle an episode.completed bus event for a conversation LiveView.
Handle an episode.failed bus event for a conversation LiveView.
Functions
Dispatch a user message. Appends the user message to the message list and creates the episode.
Returns {:ok, updated_messages} or {:error, updated_messages, reason}.
Reconstruct chat messages from completed episodes in a conversation.
Load or create a conversation based on params and live_action.
Returns {conversation, messages}.
Handle a conversation status change event. Returns updated conversation or :ignore.
Handle an episode.completed bus event for a conversation LiveView.
Checks that the episode belongs to the current conversation. If it does,
returns {:ok, assigns_map} with the updated assigns. Otherwise returns :ignore.
Example
def handle_info({:bus, "episode.completed", %{episode_id: eid, actor_id: @__actor_id}}, socket) do
case on_episode_completed(eid, socket.assigns.conversation.id, socket.assigns.messages) do
{:ok, new_assigns} -> {:noreply, assign(socket, new_assigns)}
:ignore -> {:noreply, socket}
end
end
Handle an episode.failed bus event for a conversation LiveView.
Returns {:ok, assigns_map} or :ignore.