Skip to content

Instantly share code, notes, and snippets.

@shankardevy
Last active August 19, 2017 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shankardevy/92720049d6d42f160dbd47ae677f91a8 to your computer and use it in GitHub Desktop.
Save shankardevy/92720049d6d42f160dbd47ae677f91a8 to your computer and use it in GitHub Desktop.
defmodule MangoWeb.BotChannel do
use MangoWeb, :channel
def join("pos", payload, socket) do
if authorized?(payload) do
{:ok, socket}
else
{:error, %{reason: "unauthorized"}}
end
end
# Channels can be used in a request/response fashion
# by sending replies to requests from the client
def handle_in("ping", payload, socket) do
{:reply, {:ok, payload}, socket}
end
# It is also common to receive messages from the client and
# broadcast to everyone in the current topic (bot:lobby).
def handle_in("shout", payload, socket) do
broadcast socket, "shout", payload
{:noreply, socket}
end
# Add authorization logic here as required.
defp authorized?(_payload) do
true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment