Skip to content

Instantly share code, notes, and snippets.

@jdjkelly
Created April 8, 2024 17:29
Show Gist options
  • Save jdjkelly/7ca63ccdb6d43fcc51736b940c7e0ef1 to your computer and use it in GitHub Desktop.
Save jdjkelly/7ca63ccdb6d43fcc51736b940c7e0ef1 to your computer and use it in GitHub Desktop.
LLM Channel summary Slackbot
import { App, } from '@slack/bolt';
import { Anthropic } from '@anthropic-ai/sdk';
const app = new App({
signingSecret: process.env.SLACK_SIGNING_SECRET,
token: process.env.SLACK_BOT_TOKEN,
});
const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
(async () => {
app.command('/summary', async ({ ack, respond, command, client }) => {
await ack();
const messages = await client.conversations.history({
channel: command.channel_id,
limit: 999,
latest: Math.floor(Date.now() / 1000) - 24 * 60 * 60;
}).map((message) => `${message.username}: ${message.text}`).join('\n\n');
const llmResponse = await anthropic.messages.create({
model: 'claude-3-sonnet-20240229',
max_tokens: 4096,
system: `
You are a personal assistant whose job it is to summarize activity Slack channels.
You will read a transcript provided and then identify the most important conversations that occurred.`,
messages: [{ role: 'user', content: 'Here is the transcript for your task:\n\n' + messages }],
});
await respond({
blocks: [{
type: 'section',
text: {
type: 'mrkdwn',
text: 'Channel Summary for the Last Day',
},
}, {
type: 'section',
text: {
type: 'mrkdwn',
text: llmResponse.messages[0].content,
},
}],
});
});
await app.start(3000);
console.log('⚡️ Slackbot is running!');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment