Skip to content

Commit f067cda

Browse files
Copilotalexec
andcommitted
Print thread-ts after sending messages for thread continuity
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
1 parent efc3a49 commit f067cda

3 files changed

Lines changed: 22 additions & 10 deletions

File tree

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,19 @@ Usage:
5656
```bash
5757
# Send a message
5858
slack send-message alex_collins@intuit.com "I love this tool! It makes Slack integration so easy."
59+
# Output includes:
60+
# Message sent to alex_collins@intuit.com (U12345678)
61+
# thread-ts: 1234567890.123456
5962

60-
# Reply to a message in a thread (thread-ts is the timestamp of the parent message)
63+
# Reply to a message in a thread (use the thread-ts from the previous message)
6164
slack send-message alex_collins@intuit.com "Thanks for the feedback!" "1234567890.123456"
65+
# Output includes:
66+
# Reply sent to alex_collins@intuit.com (U12345678) in thread 1234567890.123456
67+
# thread-ts: 1234567890.654321
6268
```
6369

70+
The `thread-ts` is printed after each message is sent, allowing you to use it to continue the conversation in a thread.
71+
6472
### MCP Server Mode
6573

6674
The MCP (Model Context Protocol) server allows AI assistants and other tools to interact with Slack through a standardized JSON-RPC protocol over stdio. This enables seamless integration with AI coding assistants and other automation tools.

main.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ func run(ctx context.Context, args []string) error {
7272
timestamp = args[3]
7373
}
7474

75-
return sendMessage(ctx, api, args[1], args[2], timestamp)
75+
_, err := sendMessage(ctx, api, args[1], args[2], timestamp)
76+
return err
7677
default:
7778
return fmt.Errorf("unknown sub-command: %s", args[0])
7879
}
@@ -92,12 +93,12 @@ func getToken() string {
9293
return ""
9394
}
9495

95-
func sendMessage(ctx context.Context, api *slack.Client, identifier, body, timestamp string) error {
96+
func sendMessage(ctx context.Context, api *slack.Client, identifier, body, timestamp string) (string, error) {
9697
var channel string
9798
if strings.Contains(identifier, "@") {
9899
user, err := api.GetUserByEmailContext(ctx, identifier)
99100
if err != nil {
100-
return fmt.Errorf("failed to lookup user: %w", err)
101+
return "", fmt.Errorf("failed to lookup user: %w", err)
101102
}
102103
channel = user.ID
103104
} else {
@@ -115,16 +116,19 @@ func sendMessage(ctx context.Context, api *slack.Client, identifier, body, times
115116
options = append(options, slack.MsgOptionTS(timestamp))
116117
}
117118

118-
if _, _, err := api.PostMessageContext(ctx, channel, options...); err != nil {
119-
return fmt.Errorf("failed to send message: %w", err)
119+
_, respTimestamp, err := api.PostMessageContext(ctx, channel, options...)
120+
if err != nil {
121+
return "", fmt.Errorf("failed to send message: %w", err)
120122
}
121123

122124
if timestamp != "" {
123125
fmt.Printf("Reply sent to %s (%s) in thread %s\n", identifier, channel, timestamp)
124126
} else {
125127
fmt.Printf("Message sent to %s (%s)\n", identifier, channel)
126128
}
127-
return nil
129+
fmt.Printf("thread-ts: %s\n", respTimestamp)
130+
131+
return respTimestamp, nil
128132
}
129133

130134
func configureToken(ctx context.Context) error {

mcp.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ func runMCPServer(ctx context.Context) error {
6060
timestamp := request.GetString("thread_ts", "")
6161

6262
// Send the message using the sendMessage function
63-
err = sendMessage(ctx, api, identifier, message, timestamp)
63+
respTimestamp, err := sendMessage(ctx, api, identifier, message, timestamp)
6464
if err != nil {
6565
return mcp.NewToolResultError(fmt.Sprintf("Error: %v", err)), nil
6666
}
6767

6868
if timestamp != "" {
69-
return mcp.NewToolResultText(fmt.Sprintf("Reply sent successfully to %s in thread %s", identifier, timestamp)), nil
69+
return mcp.NewToolResultText(fmt.Sprintf("Reply sent successfully to %s in thread %s\nthread-ts: %s", identifier, timestamp, respTimestamp)), nil
7070
}
71-
return mcp.NewToolResultText(fmt.Sprintf("Message sent successfully to %s", identifier)), nil
71+
return mcp.NewToolResultText(fmt.Sprintf("Message sent successfully to %s\nthread-ts: %s", identifier, respTimestamp)), nil
7272
})
7373

7474
// Start the stdio server

0 commit comments

Comments
 (0)