Skip to content

Instantly share code, notes, and snippets.

@denielchiang
Created July 14, 2023 04:11
Show Gist options
  • Save denielchiang/e2718a3f24b1e4c6ca7ee0ce9d385d96 to your computer and use it in GitHub Desktop.
Save denielchiang/e2718a3f24b1e4c6ca7ee0ce9d385d96 to your computer and use it in GitHub Desktop.
helpers/line.ex - first version
@spec send_to_group(String.t()) :: {:ok, String.t()} | {:error, String.t()}
def send_to_group(msg) do
Req.new(url: "https://notify-api.line.me/api/notify",)
|> Req.Request.put_header("Content-Type", "application/x-www-form-urlencoded")
|> Req.post(
auth: {:bearer, Application.fetch_env!(:line_reminder, :line_token)},
form: [message: msg]
)
|> case do
{:ok, %Req.Response{status: 200}} ->
{:ok, "Topic already be sent"}
{:ok, _others} ->
{:error, "connected but something going wrong"}
{:error, _others} ->
{:error, "connection failure happen"}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment