Adam Millerchip
7915b6d4ed
I originally developed this as an employee under the assumption that this would be released as an official SDK maintained by the company. But this is not the case, so I'm resetting the history to develop this in a personal capacity. This commit represents the progress until now.
34 lines
681 B
Elixir
34 lines
681 B
Elixir
defmodule LineBotSample.Router do
|
|
use Plug.Router
|
|
use Plug.ErrorHandler
|
|
require Logger
|
|
|
|
plug Plug.Logger
|
|
|
|
plug :match
|
|
plug :dispatch
|
|
|
|
forward "/bot", to: LineBot.Webhook, callback: LineBotSample
|
|
|
|
get "/" do
|
|
send_resp(conn, :ok, "Server is alive.")
|
|
end
|
|
|
|
match "/" do
|
|
send_resp(conn, :method_not_allowed, "")
|
|
end
|
|
|
|
match _ do
|
|
send_resp(conn, :not_found, "")
|
|
end
|
|
|
|
def handle_errors(conn, %{kind: :error, reason: reason, stack: _stack}) do
|
|
message = Exception.message(reason)
|
|
Logger.error(message)
|
|
send_resp(conn, conn.status, message)
|
|
end
|
|
|
|
def handle_errors(conn, _) do
|
|
send_resp(conn, conn.status, "Server Error")
|
|
end
|
|
end
|