All of this code doing all of this cool stuff in JavaScript doesn't mean much if we can't actually hook it up for broadcasting and storing messages! The good news is that there really isn't that much code we need to write! First, we'll want to update our chat channel code to be able to handle this new_message event and store the message in the database.
Back in lib/vocial_web/channels/chat_channel.ex, we'll need to add an alias to the Votes context:
alias Vocial.Votes
And then we'll add a new handle_in/3 function:
def handle_in("new_message", %{"author" => author, "message" => message}, socket) do with {:ok, _message} <- Votes.create_message(%{author: author, message: message}) do broadcast socket, ...