Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a new slack tool to get thread messages using a link #441

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading