Skip to content

Instantly share code, notes, and snippets.

@ihorkatkov
Last active June 12, 2020 11:52
Show Gist options
  • Save ihorkatkov/af07260d32aa9b97f785b8ab64304f21 to your computer and use it in GitHub Desktop.
Save ihorkatkov/af07260d32aa9b97f785b8ab64304f21 to your computer and use it in GitHub Desktop.
How to not pattern match
defmodule BucklerBot.Handlers.Private do
use Agala.Provider.Telegram, :handler
import BucklerBot.Gettext
require Logger
def init(opts), do: opts
def call(conn = %Agala.Conn{
request: %{"message" => %{"chat" => %{"id" => chat_id, "type" => "private"}, "text" => "/ping"}}
}, _) do
conn
|> send_message(chat_id, "BucklerBot is now working")
conn
end
def call(conn = %Agala.Conn{
request: %{"message" => %{"chat" => %{"id" => chat_id, "first_name" => first_name, "type" => "private"}, "text" => "/start"}}
}, _) do
# Some logic here
end
def call(conn = %Agala.Conn{
request: %{"message" => %{"chat" => %{"id" => chat_id, "first_name" => first_name, "type" => "public"}, "text" => "/start"}}
}, _) do
# Another logic here
end
def call(conn = %Agala.Conn{
request: %{"message" => %{"chat" => %{"id" => chat_id, "first_name" => first_name, "type" => "private"}, "text" => "/stop"}}
}, _) do
# Another logic here
end
#################################################
def call(conn = %Agala.Conn{
request: request
}, _) do
Logger.error("Unexpected message:\n#{inspect request}")
conn
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment