ClientUtils.Widget (client_utils v0.5.0)

View Source

Public interface to a user's support WidgetClient. Starts one Slipstream client per user on demand (under the app's DynamicSupervisor, keyed in the Registry) and exposes chat send / pagination / feedback / state to SupportWidgetLive. Shared by applications through client_utils.

Summary

Functions

Start the widget's registry, clients and local message bus under your supervision tree.

The host's shared CodeMySpec client, also usable independently of the widget.

Read host configuration without baking a generated application's name into the library.

Whether both the backend server URL and private credential path are configured.

Starts the user's client if not already running. Idempotent.

Ask CodeMySpec for a presigned S3 URL to upload a chat attachment to.

Ask CodeMySpec for a presigned S3 URL to upload a screenshot to.

Start the widget supervisor. Connection credentials are read from this OTP application's config.

Current accumulated messages for the user (for a freshly-mounted widget).

Report a problem (title/description/severity) — filed as a CodeMySpec issue.

PubSub topic SupportWidgetLive subscribes to for a user's message updates.

Sends body through the widget as its own check user and waits until CodeMySpec has stored it. Backs POST /_cms/verify/widget.

Registry :via tuple for a user's client process.

Functions

child_spec(opts)

Start the widget's registry, clients and local message bus under your supervision tree.

client()

The host's shared CodeMySpec client, also usable independently of the widget.

config(key)

Read host configuration without baking a generated application's name into the library.

configured?(app)

Whether both the backend server URL and private credential path are configured.

ensure_started(user_id, user_email, origin \\ nil)

Starts the user's client if not already running. Idempotent.

A client already running with a different origin is replaced rather than reused. origin is what tells CodeMySpec which site a message came from, and it is sent once, when the socket connects — so a client started earlier without one goes on reporting nothing forever, and {:already_started, pid} quietly discarded the origin the caller had just supplied.

That is how a widget that was installed, connected and delivering messages still could not be proven: the messages arrived with no origin, so nothing could attribute them to the site that sent them.

load_older(user_id, before)

request_chat_upload(user_id, content_type, filename)

Ask CodeMySpec for a presigned S3 URL to upload a chat attachment to.

request_screenshot_upload(user_id, content_type)

Ask CodeMySpec for a presigned S3 URL to upload a screenshot to.

send_message(user_id, body, attachments \\ [])

socket_url()

start_link(opts)

Start the widget supervisor. Connection credentials are read from this OTP application's config.

state(user_id)

Current accumulated messages for the user (for a freshly-mounted widget).

submit_feedback(user_id, payload)

Report a problem (title/description/severity) — filed as a CodeMySpec issue.

topic(user_id)

PubSub topic SupportWidgetLive subscribes to for a user's message updates.

verify(body, origin, timeout \\ 10000)

Sends body through the widget as its own check user and waits until CodeMySpec has stored it. Backs POST /_cms/verify/widget.

origin is where the caller reached this app; CodeMySpec only counts the message as coming from the deployed site when it matches.

via(user_id)

Registry :via tuple for a user's client process.