Skip to content

Commit 15dcc51

Browse files
committed
Add correct Slack formatting
1 parent 716eb76 commit 15dcc51

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,6 @@ http-body-util = "0.1"
7070

7171
# TLS (needed for slack-morphism)
7272
rustls = { version = "0.23", features = ["aws-lc-rs"] }
73+
74+
# Lightweight regex for Slack markdown conversion
75+
regex-lite = "0.1"

src/channels/slack.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,34 @@ use super::{
1414
use crate::config::SlackConfig;
1515
use crate::pairing::PairingStore;
1616

17+
// ============================================================================
18+
// Markdown to Slack mrkdwn conversion
19+
// ============================================================================
20+
21+
/// Convert standard Markdown to Slack's mrkdwn format
22+
fn markdown_to_mrkdwn(text: &str) -> String {
23+
let mut result = text.to_string();
24+
25+
// Convert bold: **text** -> *text*
26+
// Be careful not to convert already-correct single asterisks
27+
// Use a simple approach: replace ** with a placeholder, then convert
28+
result = result.replace("**", "\x00BOLD\x00");
29+
result = result.replace("\x00BOLD\x00", "*");
30+
31+
// Convert italic: *text* -> _text_ (but only single asterisks not part of bold)
32+
// This is tricky because * is used for bold in mrkdwn
33+
// Skip this for now as it can conflict with bullet points
34+
35+
// Convert links: [text](url) -> <url|text>
36+
let link_re = regex_lite::Regex::new(r"\[([^\]]+)\]\(([^)]+)\)").unwrap();
37+
result = link_re.replace_all(&result, "<$2|$1>").to_string();
38+
39+
// Convert inline code: `code` stays the same in Slack
40+
// Convert code blocks: ```code``` stays the same in Slack
41+
42+
result
43+
}
44+
1745
// ============================================================================
1846
// Channel Implementation
1947
// ============================================================================
@@ -61,10 +89,13 @@ impl Channel for SlackChannel {
6189
);
6290
let session = self.client.open_session(&self.token);
6391

92+
// Convert markdown to Slack's mrkdwn format
93+
let mrkdwn_message = markdown_to_mrkdwn(message);
94+
6495
// Build request with thread_ts if available (required for AI Assistant apps)
6596
let mut request = SlackApiChatPostMessageRequest::new(
6697
self.channel_id.clone(),
67-
SlackMessageContent::new().with_text(message.to_string()),
98+
SlackMessageContent::new().with_text(mrkdwn_message),
6899
);
69100

70101
// Reply in the thread if we have a thread_ts

0 commit comments

Comments
 (0)