Current section
Files
Jump to
Current section
Files
lib/cointrade.ex
defmodule Cointrade do
@moduledoc """
Slack API 모듈
"""
@slack_token System.get_env("SLACK_TOKEN")
@doc """
슬랙 메시지 전송
"""
def send_message(channel, text) do
url = "https://slack.com/api/chat.postMessage"
headers = [
{"Content-Type", "application/json"},
{"Authorization", "Bearer #{@slack_token}"}
]
payload = %{
channel: channel,
text: text
}
case HTTPoison.post(url, Jason.encode!(payload), headers) do
{:ok, %{body: body}} ->
body
{:error, %{body: body}} ->
IO.puts(body)
end
end
end