Files
copilotkit__copilotkit/examples/slack/app/tools/read-thread.ts
Alem Tuzlak fc3cc1b395 feat(examples): drive Slack and Telegram from one app
examples/slack now starts a Slack bot and/or a Telegram bot from one platform-neutral app layer, env-conditional on which credentials are set. Neutralized Slack-specific rendering so the shared components work on both platforms: unicode glyphs instead of mrkdwn shortcodes, no Block Kit raw fallbacks, neutral context/tool wording. Migrated the Telegram e2e smoke harness and BotFather setup docs; removed the separate examples/telegram app.
2026-06-17 19:20:00 +02:00

36 lines
1.3 KiB
TypeScript

/**
* `read_thread` — an app-side `BotTool` that hands the agent the full
* conversation thread it's replying in. This is what makes "write this
* incident thread up as a postmortem" possible: the agent calls
* `read_thread`, gets the actual messages, and summarizes those instead
* of inventing content.
*
* It's a worked example of a `BotTool` that reads conversation history
* via the platform-agnostic `ctx.thread.getMessages()` capability —
* the adapter targets the current thread, so no channel/ts plumbing is
* needed.
*/
import { z } from "zod";
import { defineBotTool } from "@copilotkit/bot";
export const readThreadTool = defineBotTool({
name: "read_thread",
description:
"Fetch the messages in the current conversation thread so you can " +
"summarize or act on them. Call this before turning a conversation into a " +
"Linear issue or a Notion postmortem — never guess what was said. Returns " +
"the messages in chronological order with author and timestamp.",
parameters: z.object({}),
async handler(_args, { thread }) {
const messages = await thread.getMessages();
return {
count: messages.length,
messages: messages.map((m) => ({
user: m.user?.name ?? m.user?.handle ?? (m.isBot ? "bot" : "unknown"),
text: m.text,
ts: m.ts,
})),
};
},
});