Skip to content

Commit 2e8d3bd

Browse files
authored
feat: add slack integration (#73)
- add new controller to test slack integration - create schemas and table for slack integration - add slack handler module and some changes in schema and migrations - add controller test cases - add slack_event schema for validation and use it, improve the test cases - create slack archives ui, add new ts_utc field, add is_broadcasted field - add basic text formatting in slack ui, other stylings on the page - add non-navigable links in the user-settings page - add module documentation for slack_controller and slack modules, remove comments - add index for ts_utc column of messages, minor changes in slack ui
1 parent 6f111b5 commit 2e8d3bd

23 files changed

Lines changed: 4289 additions & 1 deletion

config/test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ config :dau, :aws_client, AWSS3.Sandbox
4242
config :dau, AWSS3, file_prefix: "temp"
4343

4444
config :dau, :gupshup_client, DAU.UserMessage.MessageDelivery.Sandbox
45+
46+
config :dau, :slack_process_async, false

lib/dau/markdown.ex

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
defmodule DAU.Markdown do
2+
@moduledoc """
3+
This module is used to format the raw text that we receive from slack (during slack integration).
4+
"""
5+
def render(raw) when is_binary(raw) do
6+
raw
7+
|> preprocess_slack_syntax()
8+
|> Earmark.as_html!()
9+
|> HtmlSanitizeEx.basic_html()
10+
|> add_link_styling()
11+
|> Phoenix.HTML.raw()
12+
end
13+
14+
def render(raw) do
15+
raw
16+
end
17+
18+
# Add styling to links, preserving existing attributes
19+
defp add_link_styling(html) do
20+
html
21+
|> String.replace(~r/<a(\s+[^>]*)>/, fn match ->
22+
# Check if class attribute already exists
23+
if String.contains?(match, "class=\"") do
24+
# Add to existing class
25+
String.replace(match, ~r/class=\"([^\"]*)\"/, "class=\\1 text-blue-600 hover:underline hover:text-blue-800 transition-colors\"")
26+
else
27+
# Add new class attribute
28+
String.replace(match, "<a", "<a class=\"text-blue-600 hover:underline hover:text-blue-800 transition-colors\"")
29+
end
30+
end)
31+
end
32+
33+
# --- Preprocessing helpers ---
34+
defp preprocess_slack_syntax(text) do
35+
text
36+
|> replace_slack_links()
37+
|> replace_single_star_bold()
38+
end
39+
40+
# <url|label> -> [label](url)
41+
defp replace_slack_links(text) do
42+
Regex.replace(~r/<([^>|]+)\|([^>]+)>/, text, "[\\2](\\1)")
43+
end
44+
45+
# Convert Slack-style *bold* (single stars) -> **bold**
46+
# Avoid touching **already bold** and skip newlines inside
47+
defp replace_single_star_bold(text) do
48+
Regex.replace(~r/(?<!\*)\*([^*\n]+)\*(?!\*)/, text, "**\\1**")
49+
end
50+
end

0 commit comments

Comments
 (0)