Last active
June 12, 2020 11:52
-
-
Save ihorkatkov/af07260d32aa9b97f785b8ab64304f21 to your computer and use it in GitHub Desktop.
How to not pattern match
This file contains hidden or 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 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