Skip to content

Commit

Permalink
Merge pull request #4436 from santiment/split-insights-discord
Browse files Browse the repository at this point in the history
Split insights notifications in discord
  • Loading branch information
tspenov authored Oct 21, 2024
2 parents f7721f5 + b691413 commit 348a7a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/notifications_config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Config
config :sanbase, Sanbase.Messaging.Insight,
enabled: {:system, "INSIGHTS_DISCORD_NOTIFICATION_ENABLED", "true"},
webhook_url: {:system, "INSIGHTS_DISCORD_WEBHOOK_URL"},
pulse_webhook_url: {:system, "PULSE_INSIGHTS_DISCORD_WEBHOOK_URL"},
insights_discord_publish_user: {:system, "INSIGHTS_DISCORD_PUBLISH_USER", "New Insight"}

config :sanbase, Sanbase.Telegram,
Expand Down
15 changes: 13 additions & 2 deletions lib/sanbase/messaging/insight.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule Sanbase.Messaging.Insight do
def do_publish_in_discord(post) do
post
|> create_discord_payload()
|> publish()
|> publish(%{is_pulse: post.is_pulse})
|> case do
{:ok, %HTTPoison.Response{status_code: 204}} ->
:ok
Expand Down Expand Up @@ -46,14 +46,25 @@ defmodule Sanbase.Messaging.Insight do
Jason.encode!(%{content: content, username: insights_discord_publish_user()})
end

defp publish(payload) do
defp publish(payload, %{is_pulse: true}) do
http_client().post(pulse_discord_webhook_url(), payload, [
{"Content-Type", "application/json"}
])
end

defp publish(payload, %{is_pulse: false}) do
http_client().post(discord_webhook_url(), payload, [{"Content-Type", "application/json"}])
end

defp discord_webhook_url do
Config.module_get(__MODULE__, :webhook_url)
end

# default to the regular discord webhook url if the pulse webhook url is not set
def pulse_discord_webhook_url do
Config.module_get(__MODULE__, :pulse_webhook_url) || discord_webhook_url()
end

defp insights_discord_publish_user do
Config.module_get(__MODULE__, :insights_discord_publish_user)
end
Expand Down

0 comments on commit 348a7a8

Please sign in to comment.