From 8ea41b0296077bed5e7bc492462b10f3bb0e8614 Mon Sep 17 00:00:00 2001 From: Nick Hale <4175918+njhale@users.noreply.github.com> Date: Thu, 13 Feb 2025 21:04:56 -0500 Subject: [PATCH] feat: add a new slack tool to get thread messages using a link Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com> --- slack/index.js | 4 ++++ slack/src/tools.js | 15 +++++++++++++++ slack/tool.gpt | 13 ++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/slack/index.js b/slack/index.js index b9085be3..8652952d 100644 --- a/slack/index.js +++ b/slack/index.js @@ -6,6 +6,7 @@ import { getDMThreadHistory, getMessageLink, getThreadHistory, + getThreadHistoryFromLink, listChannels, listUsers, search, @@ -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 diff --git a/slack/src/tools.js b/slack/src/tools.js index c04dc34d..65b1c811 100644 --- a/slack/src/tools.js +++ b/slack/src/tools.js @@ -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({ diff --git a/slack/tool.gpt b/slack/tool.gpt index 722fd1c8..f4084d75 100644 --- a/slack/tool.gpt +++ b/slack/tool.gpt @@ -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 @@ -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