-
-
Save shankardevy/04fdf946d6a79372f05a1adb1d54a223 to your computer and use it in GitHub Desktop.
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 characters
defmodule MangoWeb.BotChannel do | |
use MangoWeb, :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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment