Skip to content

Commit

Permalink
feat: add a new slack tool to get thread messages using a link
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Hale <[email protected]>
  • Loading branch information
njhale committed Feb 14, 2025
1 parent c0dbcdb commit 8ea41b0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
4 changes: 4 additions & 0 deletions slack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getDMThreadHistory,
getMessageLink,
getThreadHistory,
getThreadHistoryFromLink,
listChannels,
listUsers,
search,
Expand Down Expand Up @@ -44,6 +45,9 @@ switch (command) {
case "getThreadHistory":
await getThreadHistory(webClient, process.env.CHANNELID, process.env.THREADID, process.env.LIMIT)
break
case "getThreadHistoryFromLink":
await getThreadHistoryFromLink(webClient, process.env.MESSAGELINK, process.env.LIMIT)
break
case "searchMessages":
await search(webClient, process.env.QUERY)
break
Expand Down
15 changes: 15 additions & 0 deletions slack/src/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ export async function getThreadHistory(webClient, channelId, threadId, limit) {
}
}

export async function getThreadHistoryFromLink(webClient, messageLink, limit) {
// Extract channel ID and message timestamp from the link
// Example link format: https://team.slack.com/archives/CHANNEL_ID/p1234567890123456
const matches = messageLink.match(/archives\/([A-Z0-9]+)\/p(\d+)/)
if (!matches) {
console.log('Invalid message link format')
process.exit(1)
}

const channelId = matches[1]
// Convert the timestamp to Slack's format (with decimal point)
const threadId = (matches[2].slice(0, -6) + '.' + matches[2].slice(-6))

await getThreadHistory(webClient, channelId, threadId, limit)
}

export async function search(webClient, query) {
const result = await webClient.search.all({
Expand Down
13 changes: 12 additions & 1 deletion slack/tool.gpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Name: Slack
Description: Tools for interacting with Slack
Metadata: bundle: true
Share Tools: List Channels, Search Channels, Get Channel History, Get Channel History by Time, Get Thread History, Search Messages, Send Message, Send Message in Thread, List Users, Search Users, Send DM, Send DM in Thread, Get Message Link, Get DM History, Get DM Thread History
Share Tools: List Channels, Search Channels, Get Channel History, Get Channel History by Time, Get Thread History From Link, Get Thread History, Search Messages, Send Message, Send Message in Thread, List Users, Search Users, Send DM, Send DM in Thread, Get Message Link, Get DM History, Get DM Thread History

---
Name: List Channels
Expand Down Expand Up @@ -49,6 +49,17 @@ Param: end: the end time in RFC 3339 format

#!/usr/bin/env node ${GPTSCRIPT_TOOL_DIR}/index.js getChannelHistoryByTime

---
Name: Get Thread History From Link
Description: Get the chat history for a particular thread from a Slack message link
Share Context: Slack Context
Tools: github.com/gptscript-ai/datasets/filter
Credential: ./credential
Param: messageLink: the link to the first Slack message in the thread (example "https://team.slack.com/archives/CHANNEL_ID/p1234567890123456")
Param: limit: the number of messages to return

#!/usr/bin/env node ${GPTSCRIPT_TOOL_DIR}/index.js getThreadHistoryFromLink

---
Name: Get Thread History
Description: Get the chat history for a particular thread
Expand Down

0 comments on commit 8ea41b0

Please sign in to comment.