This is part of building a chat app with Phoenix Channels workshop. In this part we will use Elixir to build a chat bot.
Remember in part 1 we generated root for the umbrella application? Generate new application for chat bot:
$ cd chatter/apps
$ mix new bot
Using umbrella applications provided by Elixir we can desing for deletability
, one of the great ideas Greg Young
was talking about. Let's stop here for a second and think about boundaries, microservices and how to get it right.
Now we are ready to move on to a bot implementation. Let's write a "code I wish I had" in our ChatterWeb application to identify our interface and then TDD the implementation.
In chatter/apps/chatter_web/lib/chatter_web/channels/room_channel.ex
def handle_in("new_message", payload, socket) do
IO.inspect payload # IO.inspect will print out to a console payload, which we receive
# Bot.answer(payload) # The code I wish I had
broadcast! socket, "new_message", payload
{:noreply, socket}
end