/bot_channel.ex Secret
Last active
August 19, 2017 04:53
Revisions
-
shankardevy revised this gist
Aug 19, 2017 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ defmodule MangoWeb.BotChannel do use MangoWeb, :channel alias Mango.Sales def join("pos", payload, socket) do -
shankardevy created this gist
Jul 9, 2017 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ defmodule Mango.Web.BotChannel do use Mango.Web, :channel alias Mango.Sales def join("pos", payload, socket) do welcome_text = "Hello! Welcome to Mango Point of Sale" {:ok, %{message: welcome_text}, socket} end def handle_in("status", payload, socket) do reply = case Sales.get_order(payload["message"]) do nil -> %{ message: "Order not found." } order -> %{ message: "Status: #{order.status}"} end {:reply, {:ok, reply}, socket} end def handle_in("new", _, socket) do order = Sales.create_cart() new_socket = socket |> assign(:order, order) reply = %{ message: "New Order in Progress: ##{order.id}" } {:reply, {:ok, reply}, new_socket} end def handle_in(_, payload, socket) do reply = %{ message: "I don't understand your question." } {:reply, {:error, reply}, socket} end end