Created
July 17, 2023 01:38
-
-
Save denielchiang/9e9fef149235bef698642b8316bd8ee0 to your computer and use it in GitHub Desktop.
Tomasz's advice
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 LineReminder.Line do | |
@moduledoc """ | |
Line http client wrapper | |
""" | |
@doc """ | |
Send passing message to particular line group | |
## Examples | |
iex> send_to_group("abc") | |
{:ok, message} | |
""" | |
@spec send_to_group(String.t()) :: {:ok, String.t()} | {:error, String.t()} | |
def send_to_group(msg) do | |
[ | |
url: "https://notify-api.line.me/api/notify", | |
headers: [{"Content-Type", "application/x-www-form-urlencoded"}], | |
auth: {:bearer, Application.fetch_env!(:line_reminder, :line_token)} | |
] | |
|> Req.new() | |
|> then(&Req.post!(&1, form: [message: msg]).body["message"]) | |
|> handle_resp() | |
end | |
defp handle_resp("ok"), do: {:ok, "Topic already be sent"} | |
defp handle_resp(message), do: {:error, message} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment