Skip to content

Slack

Read Slack channels, people and messages, and post messages, from DuckDB SQL

Connector software
Free and open source
Service credentials
Not needed
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/slack/index.md to help me query Slack with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Find your largest Slack channels

SELECT name, num_members
FROM slack.main.channels()
WHERE is_member
ORDER BY num_members DESC
LIMIT 10

Quick start

Choose where to run Slack, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach the release directly

Downloads the latest release for your platform and caches it locally.

ATTACH 'slack' AS slack (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/vgi-slack'
);

3. Run a query

query.sql
SELECT name, num_members
FROM slack.main.channels()
WHERE is_member
ORDER BY num_members DESC
LIMIT 10
More example queries β†’
Technical details
Verified connector release
v0.2.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach the release directly

Uses the verified release each time you attach the connector.

ATTACH 'slack' AS slack (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/[email protected]'
);

Overview

Slack workspace data as SQL tables: channels, people, channel history and threads, read through the Slack Web API with a bot token, plus posting messages from a query.

ATTACH options

token
Slack bot token (xoxb-...). Pass it as an expression to keep it out of the SQL text: token getenv('SLACK_BOT_TOKEN').VARCHAR
api_url
Slack Web API root URL. Change it only for a proxy or a test server.VARCHAR

Catalog

Everything slack exposes once attached β€” read straight from the worker's released build.

slack 1 schema
main 7 functions

Slack readers for channels, people and conversations, and writers that post messages.

Schema examples (14)
Examples (14)

Check which workspace and bot the token is for

SELECT team, user, bot_id FROM slack.main.auth_info();

The ten largest channels the bot is in

SELECT name, num_members
FROM slack.main.channels()
WHERE is_member
ORDER BY num_members DESC
LIMIT 10;

Count public and private channels, including archived ones

SELECT is_private, count(*) AS channels
FROM slack.main.channels(exclude_archived := false)
GROUP BY is_private;

Who created each channel the bot can see, oldest channel first (include_deleted keeps creators who have left)

SELECT c.name, u.real_name AS created_by, c.created_at
FROM slack.main.channels() c
LEFT JOIN slack.main.users(include_deleted := true) u ON u.id = c.creator
ORDER BY c.created_at;
10 more examples

Where the workspace's people are, by time zone

SELECT tz, count(*) AS people
FROM slack.main.users()
WHERE NOT is_bot
GROUP BY tz
ORDER BY people DESC;

Most active people in #general since the start of 2026

SELECT u.real_name, count(*) AS messages
FROM slack.main.messages('#general', oldest := TIMESTAMPTZ '2026-01-01') m
JOIN slack.main.users() u ON u.id = m.user_id
GROUP BY u.real_name
ORDER BY messages DESC
LIMIT 10;

The twenty latest messages in a channel, by ID

SELECT posted_at, text
FROM slack.main.messages('C0123ABCD')
ORDER BY posted_at DESC
LIMIT 20;

Read one thread in order

SELECT posted_at, user_id, text
FROM slack.main.replies('#general', '1700000000.000100')
ORDER BY posted_at;

Read a thread (parent message first, then replies) with each author's real name instead of a user ID

SELECT r.posted_at, coalesce(u.real_name, r.user_id) AS author, r.text
FROM slack.main.replies('#general', '1767225900.000100') r
LEFT JOIN slack.main.users(include_deleted := true) u ON u.id = r.user_id
ORDER BY r.posted_at;

Announce a deploy and keep the message ts

SELECT channel_id, ts
FROM slack.main.post_message('#deploys', 'Deployed *v1.2* :rocket:');

Reply in an existing thread

SELECT ts
FROM slack.main.post_message('#deploys', 'Rollback finished', thread_ts := '1700000000.000100');

Dry run: an empty input posts nothing (no token or network needed)

SELECT count(*) AS posted
FROM slack.main.post_messages((SELECT '#alerts' AS channel, 'never sent' AS text WHERE false));

Post an alert per down host and count them

SELECT count(*) AS posted
FROM slack.main.post_messages((SELECT '#alerts' AS channel, 'Host ' || h || ' is down' AS text FROM (VALUES ('web-1'), ('web-2')) t(h)));

Reply in the thread of every unanswered message people posted in #general in the last day, and count the nudges

SELECT count(*) AS nudged
FROM slack.main.post_messages((SELECT channel_id AS channel, 'Bumping this: is anyone looking at it?' AS text, ts AS thread_ts FROM slack.main.messages('#general', oldest := now()::TIMESTAMP - INTERVAL 1 DAY) WHERE reply_count IS NULL AND subtype IS NULL AND bot_id IS NULL));
Table functions
auth_info () 1 example

Show which Slack workspace, user and bot the attached token belongs to

No arguments
Returns columns
team_id VARCHAR
Workspace ID, e.g. 'T0123ABCD'.
team VARCHAR
Workspace name.
url VARCHAR
Workspace URL, e.g. 'https://acme.slack.com/'.
user_id VARCHAR
User ID the token acts as (the bot user for a bot token).
user VARCHAR
User name the token acts as.
bot_id VARCHAR
Bot ID when the token is a bot token, otherwise NULL.
Example

Check which workspace and bot the token is for

SELECT team, user, bot_id FROM slack.main.auth_info();
Link
channels (exclude_archived := BOOLEAN, types := VARCHAR) 3 examples

List the Slack channels the bot can see

Named arguments
exclude_archived := BOOLEAN
Leave out archived channels. Default true. Β· default true
types := VARCHAR
Comma-separated conversation types: any of public_channel, private_channel, mpim, im. Default 'public_channel,private_channel'. Β· default "public_channel,private_channel"
Returns columns
id VARCHAR
Conversation ID, e.g. 'C0123ABCD'. Pass it to messages() or post_message().
name VARCHAR
Channel name without the leading '#'.
is_private BOOLEAN
True for a private channel.
is_archived BOOLEAN
True when the channel is archived.
is_member BOOLEAN
True when the bot is a member (it can read the channel's history).
num_members BIGINT
Number of members, when Slack reports it.
topic VARCHAR
Channel topic text.
purpose VARCHAR
Channel purpose text.
creator VARCHAR
User ID of the channel's creator.
created_at TIMESTAMP WITH TIME ZONE
When the channel was created.
Examples (3)

The ten largest channels the bot is in

SELECT name, num_members
FROM slack.main.channels()
WHERE is_member
ORDER BY num_members DESC
LIMIT 10;

Count public and private channels, including archived ones

SELECT is_private, count(*) AS channels
FROM slack.main.channels(exclude_archived := false)
GROUP BY is_private;

Who created each channel the bot can see, oldest channel first (include_deleted keeps creators who have left)

SELECT c.name, u.real_name AS created_by, c.created_at
FROM slack.main.channels() c
LEFT JOIN slack.main.users(include_deleted := true) u ON u.id = c.creator
ORDER BY c.created_at;
Link
messages (channel VARCHAR, latest := TIMESTAMP WITH TIME ZONE, oldest := TIMESTAMP WITH TIME ZONE) 2 examples

Read a Slack channel's message history, newest first

Positional arguments
channel VARCHAR
Channel ID ('C0123ABCD') or name ('#general' or 'general'). The bot must be a member.
Named arguments
latest := TIMESTAMP WITH TIME ZONE
Only messages posted at or before this time. Default NULL: up to now. Β· default null
oldest := TIMESTAMP WITH TIME ZONE
Only messages posted at or after this time. Default NULL: no lower bound. Β· default null
Returns columns
channel_id VARCHAR
Conversation ID the message is in.
ts VARCHAR
Slack message timestamp, the message's ID within the channel (e.g. '1700000000.123456').
posted_at TIMESTAMP WITH TIME ZONE
When the message was posted (ts as a timestamp).
user_id VARCHAR
User ID of the author; NULL for some bot and system messages.
bot_id VARCHAR
Bot ID when a bot or app posted the message.
type VARCHAR
Event type, normally 'message'.
subtype VARCHAR
Message subtype such as 'bot_message' or 'channel_join'; NULL for ordinary messages.
text VARCHAR
Message text in Slack's mrkdwn format.
thread_ts VARCHAR
ts of the thread's parent message; equals ts on a parent, NULL outside threads.
reply_count BIGINT
Number of replies, on a thread's parent message.
edited_at TIMESTAMP WITH TIME ZONE
When the message was last edited, or NULL.
Examples (2)

Most active people in #general since the start of 2026

SELECT u.real_name, count(*) AS messages
FROM slack.main.messages('#general', oldest := TIMESTAMPTZ '2026-01-01') m
JOIN slack.main.users() u ON u.id = m.user_id
GROUP BY u.real_name
ORDER BY messages DESC
LIMIT 10;

The twenty latest messages in a channel, by ID

SELECT posted_at, text
FROM slack.main.messages('C0123ABCD')
ORDER BY posted_at DESC
LIMIT 20;
Link
post_message (channel VARCHAR, text VARCHAR, thread_ts := VARCHAR) 2 examples

Post one message to a Slack channel and return its ts

Positional arguments
channel VARCHAR
Channel ID ('C0123ABCD') or name ('#general'). The bot must be allowed to post there.
text VARCHAR
Message text, in Slack mrkdwn (*bold*, _italic_, <https://example.com|links>, <@U0123ABCD> mentions).
Named arguments
thread_ts := VARCHAR
ts of a parent message to reply in its thread. Default NULL: a new top-level message. Β· default null
Returns columns
channel_id VARCHAR
Conversation ID the message was posted to.
ts VARCHAR
ts of the new message: its ID, and the thread_ts to reply to it.
posted_at TIMESTAMP WITH TIME ZONE
When Slack recorded the message.
thread_ts VARCHAR
Parent message ts when the message was posted as a thread reply.
text VARCHAR
The text that was posted.
Examples (2)

Announce a deploy and keep the message ts

SELECT channel_id, ts
FROM slack.main.post_message('#deploys', 'Deployed *v1.2* :rocket:');

Reply in an existing thread

SELECT ts
FROM slack.main.post_message('#deploys', 'Rollback finished', thread_ts := '1700000000.000100');
Link
replies (channel VARCHAR, thread_ts VARCHAR) 2 examples

Read a Slack thread: the parent message and its replies, oldest first

Arguments
channel VARCHAR
Channel ID ('C0123ABCD') or name ('#general') the thread is in.
thread_ts VARCHAR
ts of the thread's parent message, e.g. from messages().ts where reply_count > 0.
Returns columns
channel_id VARCHAR
Conversation ID the message is in.
ts VARCHAR
Slack message timestamp, the message's ID within the channel (e.g. '1700000000.123456').
posted_at TIMESTAMP WITH TIME ZONE
When the message was posted (ts as a timestamp).
user_id VARCHAR
User ID of the author; NULL for some bot and system messages.
bot_id VARCHAR
Bot ID when a bot or app posted the message.
type VARCHAR
Event type, normally 'message'.
subtype VARCHAR
Message subtype such as 'bot_message' or 'channel_join'; NULL for ordinary messages.
text VARCHAR
Message text in Slack's mrkdwn format.
thread_ts VARCHAR
ts of the thread's parent message; equals ts on a parent, NULL outside threads.
reply_count BIGINT
Number of replies, on a thread's parent message.
edited_at TIMESTAMP WITH TIME ZONE
When the message was last edited, or NULL.
Examples (2)

Read one thread in order

SELECT posted_at, user_id, text
FROM slack.main.replies('#general', '1700000000.000100')
ORDER BY posted_at;

Read a thread (parent message first, then replies) with each author's real name instead of a user ID

SELECT r.posted_at, coalesce(u.real_name, r.user_id) AS author, r.text
FROM slack.main.replies('#general', '1767225900.000100') r
LEFT JOIN slack.main.users(include_deleted := true) u ON u.id = r.user_id
ORDER BY r.posted_at;
Link
users (include_deleted := BOOLEAN) 1 example

List the members of the Slack workspace

Named arguments
include_deleted := BOOLEAN
Include deactivated users. Default false. Β· default false
Returns columns
id VARCHAR
User ID, e.g. 'U0123ABCD'. Matches messages.user_id.
name VARCHAR
Username (handle).
real_name VARCHAR
Full name from the user's profile.
display_name VARCHAR
Display name from the user's profile.
email VARCHAR
Email address; NULL unless the token has the users:read.email scope.
title VARCHAR
Job title from the user's profile.
tz VARCHAR
IANA time zone, e.g. 'America/New_York'.
is_bot BOOLEAN
True for bot users.
is_admin BOOLEAN
True for workspace admins.
deleted BOOLEAN
True for deactivated users.
Example

Where the workspace's people are, by time zone

SELECT tz, count(*) AS people
FROM slack.main.users()
WHERE NOT is_bot
GROUP BY tz
ORDER BY people DESC;
Link
Table in-out functions
post_messages (data TABLE) 3 examples

Post one Slack message per input row (columns channel, text, optional thread_ts)

Arguments
data TABLE
Subquery of messages to post, one per row, with columns `channel` (ID or '#name') and `text`, and optionally `thread_ts` (NULL for a top-level message).
Returns columns
channel_id VARCHAR
Conversation ID the message was posted to.
ts VARCHAR
ts of the new message: its ID, and the thread_ts to reply to it.
posted_at TIMESTAMP WITH TIME ZONE
When Slack recorded the message.
thread_ts VARCHAR
Parent message ts when the message was posted as a thread reply.
text VARCHAR
The text that was posted.
Examples (3)

Dry run: an empty input posts nothing (no token or network needed)

SELECT count(*) AS posted
FROM slack.main.post_messages((SELECT '#alerts' AS channel, 'never sent' AS text WHERE false));

Post an alert per down host and count them

SELECT count(*) AS posted
FROM slack.main.post_messages((SELECT '#alerts' AS channel, 'Host ' || h || ' is down' AS text FROM (VALUES ('web-1'), ('web-2')) t(h)));

Reply in the thread of every unanswered message people posted in #general in the last day, and count the nudges

SELECT count(*) AS nudged
FROM slack.main.post_messages((SELECT channel_id AS channel, 'Bumping this: is anyone looking at it?' AS text, ts AS thread_ts FROM slack.main.messages('#general', oldest := now()::TIMESTAMP - INTERVAL 1 DAY) WHERE reply_count IS NULL AND subtype IS NULL AND bot_id IS NULL));
Link

Try these queries

Check which workspace and bot the token is for

SELECT team, user, bot_id FROM slack.main.auth_info()

Uses auth_info

Count public and private channels, including archived ones

SELECT is_private, count(*) AS channels
FROM slack.main.channels(exclude_archived := false)
GROUP BY is_private

Uses channels

Where the workspace's people are, by time zone

SELECT tz, count(*) AS people
FROM slack.main.users()
WHERE NOT is_bot
GROUP BY tz
ORDER BY people DESC

Uses users

Most active people in #general since the start of 2026

SELECT u.real_name, count(*) AS messages
FROM slack.main.messages('#general', oldest := TIMESTAMPTZ '2026-01-01') m
JOIN slack.main.users() u ON u.id = m.user_id
GROUP BY u.real_name
ORDER BY messages DESC
LIMIT 10

Uses messagesusers

Read one thread in order

SELECT posted_at, user_id, text
FROM slack.main.replies('#general', '1700000000.000100')
ORDER BY posted_at

Uses replies

Announce a deploy and keep the message ts

SELECT channel_id, ts
FROM slack.main.post_message('#deploys', 'Deployed *v1.2* :rocket:')

Uses post_message

7 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • Using the slack worker, which Slack workspace (team name) is the bot connected to?
  • Using the slack worker, list the names of the channels the bot is a member of.
  • Using the slack worker, how many top-level messages are in the #general channel?
  • Using the slack worker, which user (by real name) posted the most messages in #general?

Slack is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.