Skip to content

Instantly share code, notes, and snippets.

@shankardevy
Last active August 19, 2017 04:53

Revisions

  1. shankardevy revised this gist Aug 19, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions bot_channel.ex
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    defmodule Mango.Web.BotChannel do
    use Mango.Web, :channel
    defmodule MangoWeb.BotChannel do
    use MangoWeb, :channel
    alias Mango.Sales

    def join("pos", payload, socket) do
  2. shankardevy created this gist Jul 9, 2017.
    30 changes: 30 additions & 0 deletions bot_channel.ex
    Original 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