Example on how to implement "forms" within channels

I would like to have a way of an admin to get real time notifications every time a user submits a form and be able to chat with him if desired.
I couldn’t find any suitable example for this use case as:

  1. I think forms because:
    a) the user could be an unregistered user;
    b) the admin could be away and as such it should look/work like a form, not a chat;
    c) I want to save everything in the database and have different views on data;
  2. I think channels because:
    a) I would like to get instant alert that a form was submitted;
    b) I could want to reply immediately and start a chat;

I would like to have some feedback about the best approach, so I would greatly appreciate if someone could give some guiding lines or recommend any blog post/article on this.
Thanks,

Paulo Janeiro

Did you try to save from the channel, or publish to the channel from the controller?

def contact(conn, _params) do
   changeset = ...
   case Repo.insert(changeset) do
   ...
   AppName.Endpoint.broadcast("contact_forms:#{id}", "action_name", payload)
   ...
end
1 Like