mix cms_gen.support_widget (CodeMySpecGenerators v0.6.1)

Copy Markdown View Source

Generates an always-on support widget for a host app's users — signed in or not. One widget, two clear intents:

  • Chat — a live conversation with a CodeMySpec operator.

  • Report a problem — file an issue (title / description / severity) that lands in the project's CodeMySpec issue queue.

    $ mix cms_gen.support_widget

Both intents ride ONE connection: per logged-in user, the host app's server opens a Slipstream connection to CodeMySpec authenticated by the project deploy key (the key never reaches the browser). Chat relays send_message/new_message; "Report a problem" pushes a submit_feedback event on the same conversation:<user_id> topic, which CodeMySpec files as an issue. No OAuth, no second transport.

This supersedes cms_gen.feedback_widget (feedback-only, OAuth/REST) — the support widget does everything that did, plus chat, over the deploy-key socket.

Generated files

  • lib/<app>/code_my_spec/widget_client.ex — per-user Slipstream client
  • lib/<app>/code_my_spec/widget.ex — registry/supervisor interface
  • lib/<app>_web/live/support_widget_live.ex — the sticky nested LiveView

It also edits the four things the widget needs to work: the slipstream dependency, the registry and supervisor in the supervision tree, the live_render in the root layout, and the socket URL and deploy key in runtime config. Each is skipped if already present and reported either way.

Assumptions

The app runs <Base>.PubSub. The deploy key is read from Application.get_env(:<app>, :deploy_key) — the same key content sync uses.

phx.gen.auth is optional. When <Base>Web.UserAuth exists, the widget wires its on_mount {_, :mount_current_scope} so signed-in users keep one thread across devices; when it doesn't, every visitor gets a session-derived identity instead (see SupportWidgetLive's identity/2). Either way the widget renders and "Report a problem" works.