OfficialMessaging

Slack

Let agents catch you up on Slack: summarize a busy channel, find the thread where a decision was made, list the messages that mention you, or pull an attachment someone shared. They see the channels, private channels and direct messages you can see, and search the same way you do in Slack.

With write access, agents can also act as you: post or reply in a thread, send a direct message, edit or delete your messages, react with an emoji, or share a file. Everything they post appears under your name.

Choose the access for each part of Slack: public channels, private channels, direct messages, search, users and files can be read, and messages, reactions, direct messages and files can be written. By default agents read and search, but never post. Each connection covers one Slack workspace; add another connection for each additional workspace.

Connect with Slack in one click: pick your workspace and allow access. Your authorization stays on Houston's server. See Connect your Slack account.

Setup instructions

Connect Slack

  1. In Houston, choose the access for each row: Read or None for Public channels, Private channels, Search and Users; Read, Write or None for Direct messages and Files; and Write or None for Reactions and Messages.
  2. Select Add to Slack, sign in and check the workspace shown.
  3. Select Allow. If approval is required, ask a workspace admin and reconnect after approval.

Agents see what you can see in the rows you allow, including private channels and direct messages. With Messages or Files at Write, they post and share files under your name. Direct messages at Write lets them open new direct and group conversations.

Row Read Write
Public channels channels:read, channels:history
Private channels groups:read, groups:history
Direct messages im:read, im:history, mpim:read, mpim:history adds im:write, mpim:write
Search search:read
Users users:read
Files files:read adds files:write
Reactions reactions:write
Messages chat:write
Advanced

Add one connection per workspace; Enterprise Grid-wide installations are unsupported. Raising any row asks you to authorize again. Long channel histories may be slow because of Slack's app limits; search is often faster.

Deleting the Houston connection removes its saved authorization. Also revoke Houston on Slack's app management page to end provider access.

Files

  • connector.luau
    -- Slack Web API for one connected user in one workspace, with a Slack user token.
    -- Arguments and results keep Slack's native field names. Credentials are injected only by Houston's proxy.
    type Options = {[string]: any}
    
    local API = "https://slack.com/api/"
    local LIMIT = 15
    
    local function allow(names: {string}): {[string]: boolean}
    	local set = {}
    	for _, name in names do set[name] = true end
    	return table.freeze(set)
    end
    
    local PAGE = allow({"cursor", "limit"})
    local CHANNELS = allow({"cursor", "limit", "types", "exclude_archived"})
    local HISTORY = allow({"cursor", "limit", "oldest", "latest", "inclusive", "include_all_metadata"})
    local SEARCH = allow({"count", "page", "sort", "sort_dir", "highlight"})
    local MENTIONS = allow({"count", "page", "sort", "sort_dir", "highlight", "query"})
    local USERS = allow({"cursor", "limit", "include_locale"})
    local MESSAGE = {"blocks", "attachments", "unfurl_links", "unfurl_media", "reply_broadcast", "mrkdwn", "parse", "link_names", "metadata", "client_msg_id"}
    local REPLY = allow(MESSAGE)
    local POST = allow({"thread_ts", table.unpack(MESSAGE)})
    local UPDATE = allow({"blocks", "attachments", "parse", "link_names", "metadata", "file_ids", "reply_broadcast"})
    local UPLOAD = allow({"filename", "title", "alt_text", "channel", "thread_ts", "text"})
    -- Slack timestamps and cursors are opaque strings; a number would lose trailing zeros.
    local STRINGS = allow({"cursor", "oldest", "latest", "thread_ts"})
    
    -- Slack reports most failures as HTTP 200 with {ok = false, error = code}. Authentication
    -- codes carry 401 and missing permissions 403, so Houston can ask for reconnection.
    local AUTH_ERRORS = allow({"not_authed", "invalid_auth", "account_inactive", "token_revoked", "token_expired"})
    local RETRYABLE = allow({"ratelimited", "internal_error", "fatal_error", "service_unavailable", "request_timeout"})
    
    local function text(value: any, field: string): string
    	assert(type(value) == "string" and value ~= "", "slack: " .. field .. " must be a nonempty string")
    	return value
    end
    
    local function optional(value: any, field: string): string?
    	if value == nil then return nil end
    	return text(value, field)
    end
    
    local function options(value: any, allowed: {[string]: boolean}): Options
    	local copy: Options = {}
    	if value == nil then return copy end
    	assert(type(value) == "table", "slack: options must be a table")
    	for key, item in value do
    		assert(allowed[key], "slack: unknown option " .. tostring(key))
    		copy[key] = if STRINGS[key] then text(item, key) else item
    	end
    	return copy
    end
    
    local function form(params: Options): string
    	local parts: {string} = {}
    	for key, value in params do
    		assert(type(value) == "string" or type(value) == "number" or type(value) == "boolean",
    			"slack: " .. key .. " must be a string, number or boolean")
    		table.insert(parts, url.encode(key) .. "=" .. url.encode(value))
    	end
    	table.sort(parts)
    	return table.concat(parts, "&")
    end
    
    local function fail(operation: string, status: number, body: any, headers: HttpHeaders, write: boolean?): never
    	local code = if type(body) == "table" and type(body.error) == "string" then string.sub(body.error, 1, 100) else nil
    	local message = "slack: " .. (code or ("HTTP " .. status))
    	if type(body) == "table" and type(body.needed) == "string" then
    		message ..= " (needs " .. string.sub(body.needed, 1, 200) .. ")"
    	end
    	if code and AUTH_ERRORS[code] then
    		status = 401
    		message ..= "; reconnect Slack"
    	elseif code == "missing_scope" then
    		status = 403
    		message ..= "; reconnect Slack with the access this call needs"
    	end
    	local wait = headers["retry-after"]
    	if wait and wait[1] then message ..= "; retry after " .. string.sub(wait[1], 1, 10) .. "s" end
    	-- A failed write may still have taken effect, unless Slack rate-limited it.
    	local limited = status == 429 or code == "ratelimited"
    	local transient = status >= 500 or (code ~= nil and RETRYABLE[code] == true)
    	return houston.fail({operation = operation, layer = "upstream", upstream_status = status,
    		retryable = limited or (transient and not write), message = message})
    end
    
    local function check(operation: string, response: HttpResponse, write: boolean?)
    	if response.statusCode >= 200 and response.statusCode < 300 then return end
    	local ok, body = pcall(json.decode, await(response.body:readPrefix(4096)))
    	fail(operation, response.statusCode, if ok then body else nil, response.headers, write)
    end
    
    -- Reads use GET query strings and writes JSON bodies. files.getUploadURLExternal takes a form
    -- body; it only reserves an upload URL, so like reads its transient failures stay retryable.
    local function call(operation: string, method: string, params: Options, encoding: ("json" | "form")?): Options
    	local request: HttpRequest = {method = "GET", url = API .. method}
    	if encoding == "json" then
    		request.method, request.body = "POST", json.encode(params)
    		request.headers = {["Content-Type"] = {"application/json; charset=utf-8"}}
    	elseif encoding == "form" then
    		request.method, request.body = "POST", form(params)
    		request.headers = {["Content-Type"] = {"application/x-www-form-urlencoded"}}
    	else
    		local query = form(params)
    		if query ~= "" then request.url ..= "?" .. query end
    	end
    	local response = await(http.request(request))
    	check(operation, response, encoding == "json")
    	local ok, body = pcall(json.decode, await(response.body:readAll()))
    	if not ok or type(body) ~= "table" or type(body.ok) ~= "boolean" then
    		return houston.fail({operation = operation, layer = "upstream", upstream_status = response.statusCode,
    			retryable = false, message = "slack: invalid JSON response"})
    	end
    	if body.ok ~= true then fail(operation, response.statusCode, body, response.headers, encoding == "json") end
    	local metadata = body.response_metadata
    	if type(metadata) == "table" and type(metadata.next_cursor) == "string" and metadata.next_cursor ~= "" then
    		body.nextCursor = metadata.next_cursor
    	end
    	return body
    end
    
    local function field(operation: string, body: Options, name: string): any
    	local value = body[name]
    	if value == nil then
    		return houston.fail({operation = operation, layer = "upstream", retryable = false,
    			message = "slack: response has no " .. name})
    	end
    	return value
    end
    
    local function getProfile(): Options
    	return call("getProfile", "auth.test", {})
    end
    
    local function listChannels(opts: Options?): Options
    	local params = options(opts, CHANNELS)
    	params.types = params.types or "public_channel,private_channel,im,mpim"
    	if params.exclude_archived == nil then params.exclude_archived = true end
    	return call("listChannels", "users.conversations", params)
    end
    
    local function getChannel(channel: string): Options
    	return field("getChannel", call("getChannel", "conversations.info", {channel = text(channel, "channel ID")}), "channel")
    end
    
    local function listMessages(channel: string, opts: Options?): Options
    	local params = options(opts, HISTORY)
    	params.channel = text(channel, "channel ID")
    	params.limit = params.limit or LIMIT
    	return call("listMessages", "conversations.history", params)
    end
    
    local function getThread(channel: string, ts: string, opts: Options?): Options
    	local params = options(opts, HISTORY)
    	params.channel, params.ts = text(channel, "channel ID"), text(ts, "thread timestamp")
    	params.limit = params.limit or LIMIT
    	return call("getThread", "conversations.replies", params)
    end
    
    local function search(operation: string, query: string, params: Options): Options
    	params.query = text(query, "search query")
    	params.sort = params.sort or "timestamp"
    	params.sort_dir = params.sort_dir or "desc"
    	local messages = call(operation, "search.messages", params).messages
    	if type(messages) ~= "table" then
    		return houston.fail({operation = operation, layer = "upstream", retryable = false, message = "slack: response has no messages"})
    	end
    	local paging = messages.paging
    	if type(paging) == "table" and type(paging.page) == "number" and type(paging.pages) == "number" and paging.page < paging.pages then
    		messages.nextPage = paging.page + 1
    	end
    	return messages
    end
    
    local function searchMessages(query: string, opts: Options?): Options
    	return search("searchMessages", query, options(opts, SEARCH))
    end
    
    local function listMentions(opts: Options?): Options
    	local params = options(opts, MENTIONS)
    	local narrow = if params.query == "" then nil else optional(params.query, "query")
    	params.query = nil
    	local query = "<@" .. text(call("listMentions", "auth.test", {}).user_id, "authenticated user ID") .. ">"
    	return search("listMentions", if narrow then query .. " " .. narrow else query, params)
    end
    
    local function listMembers(channel: string, opts: Options?): Options
    	local params = options(opts, PAGE)
    	params.channel = text(channel, "channel ID")
    	return call("listMembers", "conversations.members", params)
    end
    
    local function getUser(user: string): Options
    	return field("getUser", call("getUser", "users.info", {user = text(user, "user ID")}), "user")
    end
    
    local function listUsers(opts: Options?): Options
    	local params = options(opts, USERS)
    	params.limit = params.limit or 200
    	return call("listUsers", "users.list", params)
    end
    
    local function getPermalink(channel: string, ts: string): string
    	return field("getPermalink", call("getPermalink", "chat.getPermalink",
    		{channel = text(channel, "channel ID"), message_ts = text(ts, "message timestamp")}), "permalink")
    end
    
    local function getFile(id: string): Options
    	return field("getFile", call("getFile", "files.info", {file = text(id, "file ID")}), "file")
    end
    
    local function downloadFile(id: string, path: string): Options
    	text(path, "session path")
    	local file = getFile(id)
    	if file.is_external == true then
    		return houston.fail({operation = "downloadFile", layer = "upstream", retryable = false,
    			message = "slack: this file is stored outside Slack; open its url_private link instead"})
    	end
    	local source = text(file.url_private_download or file.url_private, "file download URL")
    	local response = await(http.request({method = "GET", url = source}))
    	-- Slack redirects an unauthorized file request to its sign-in page, or serves that page.
    	local status, kind = response.statusCode, response.headers["content-type"]
    	local html = type(file.mimetype) == "string" and string.find(file.mimetype, "html", 1, true) ~= nil
    	local page = status >= 200 and status < 300 and kind ~= nil and kind[1] ~= nil
    		and string.find(kind[1], "text/html", 1, true) ~= nil and not html
    	if page or (status >= 300 and status < 400) then
    		response.body:close()
    		return houston.fail({operation = "downloadFile", layer = "upstream", upstream_status = 401,
    			retryable = false, message = "slack: file download returned a sign-in page; reconnect Slack"})
    	end
    	check("downloadFile", response)
    	local output = fs.open(path, "w")
    	output:write(response.body)
    	await(output:close())
    	return {path = path, url = await(fs.signedGetUrl(path)), bytes = await(fs.stat(path)).size}
    end
    
    local function post(operation: string, channel: string, message: string, params: Options): Options
    	params.channel, params.text = text(channel, "channel ID"), text(message, "message text")
    	return call(operation, "chat.postMessage", params, "json")
    end
    
    local function postMessage(channel: string, message: string, opts: Options?): Options
    	return post("postMessage", channel, message, options(opts, POST))
    end
    
    local function reply(channel: string, ts: string, message: string, opts: Options?): Options
    	local params = options(opts, REPLY)
    	params.thread_ts = text(ts, "thread timestamp")
    	return post("reply", channel, message, params)
    end
    
    local function updateMessage(channel: string, ts: string, message: string, opts: Options?): Options
    	local params = options(opts, UPDATE)
    	params.channel, params.ts, params.text = text(channel, "channel ID"), text(ts, "message timestamp"), text(message, "message text")
    	return call("updateMessage", "chat.update", params, "json")
    end
    
    local function deleteMessage(channel: string, ts: string): Options
    	return call("deleteMessage", "chat.delete", {channel = text(channel, "channel ID"), ts = text(ts, "message timestamp")}, "json")
    end
    
    local function openConversation(users: string | {string}): Options
    	local list = users
    	if type(list) == "table" then
    		for index, user in list do text(user, "user ID " .. tostring(index)) end
    		list = table.concat(list, ",")
    	end
    	return field("openConversation", call("openConversation", "conversations.open", {users = text(list, "user IDs")}, "json"), "channel")
    end
    
    local function reaction(operation: string, method: string, channel: string, ts: string, name: string): Options
    	return call(operation, method, {channel = text(channel, "channel ID"), timestamp = text(ts, "message timestamp"),
    		name = text(name, "emoji name")}, "json")
    end
    
    local function uploadFile(path: string, opts: Options?): Options
    	local params = options(opts, UPLOAD)
    	local name = text(params.filename or string.match(text(path, "session path"), "([^/]+)$"), "filename")
    	local complete = {
    		files = {{id = "", title = optional(params.title, "title") or name}},
    		channel_id = optional(params.channel, "channel"), thread_ts = optional(params.thread_ts, "thread_ts"),
    		initial_comment = optional(params.text, "text"),
    	}
    	local altText = optional(params.alt_text, "alt_text")
    	assert(complete.channel_id or (complete.thread_ts == nil and complete.initial_comment == nil),
    		"slack: thread_ts and text need channel; omit all three to keep the file private")
    	local stat = await(fs.stat(path))
    	assert(stat.isFile and stat.size > 0, "slack: upload path must be a nonempty session file")
    	local upload = call("uploadFile", "files.getUploadURLExternal", {filename = name, length = stat.size, alt_txt = altText}, "form")
    	complete.files[1].id = text(upload.file_id, "uploaded file ID")
    	local response = await(http.request({method = "POST", url = text(upload.upload_url, "upload URL"),
    		headers = {["Content-Type"] = {"application/octet-stream"}}, body = fs.open(path, "r")}))
    	-- Slack discards an upload that is never completed, so this step is safe to retry.
    	check("uploadFile", response)
    	response.body:close()
    	return call("uploadFile", "files.completeUploadExternal", complete, "json")
    end
    
    local exports: {[string]: any} = {getProfile = getProfile}
    -- Conversation reads share routes; Slack's scopes limit them to the conversation types the rows allow.
    if houston.allows("channels:read") or houston.allows("private_channels:read") or houston.allows("direct_messages:read") then
    	exports.listChannels = listChannels
    	exports.getChannel = getChannel
    	exports.listMessages = listMessages
    	exports.getThread = getThread
    	exports.listMembers = listMembers
    	exports.getPermalink = getPermalink
    end
    if houston.allows("search:read") then
    	exports.searchMessages = searchMessages
    	exports.listMentions = listMentions
    end
    if houston.allows("users:read") then
    	exports.getUser = getUser
    	exports.listUsers = listUsers
    end
    if houston.allows("files:read") then
    	exports.getFile = getFile
    	exports.downloadFile = downloadFile
    end
    if houston.allows("messages:write") then
    	exports.postMessage = postMessage
    	exports.reply = reply
    	exports.updateMessage = updateMessage
    	exports.deleteMessage = deleteMessage
    end
    if houston.allows("direct_messages:write") then
    	exports.openConversation = openConversation
    end
    if houston.allows("reactions:write") then
    	exports.addReaction = function(channel: string, ts: string, name: string): Options
    		return reaction("addReaction", "reactions.add", channel, ts, name)
    	end
    	exports.removeReaction = function(channel: string, ts: string, name: string): Options
    		return reaction("removeReaction", "reactions.remove", channel, ts, name)
    	end
    end
    if houston.allows("files:write") then
    	exports.uploadFile = uploadFile
    end
    
    local operationHelp: {[string]: string} = {
    	getProfile = [[getProfile() -> {user_id, user, team_id, team, url}
    The connected Slack user and workspace.]],
    	listChannels = [[listChannels(opts?) -> {channels, nextCursor?}
    Your channels and DMs (users.conversations). opts: types (comma-separated public_channel,private_channel,im,mpim; default all), exclude_archived (default true), limit, cursor.]],
    	getChannel = [[getChannel(channel) -> channel
    Channel details (conversations.info).]],
    	listMessages = [[listMessages(channel, opts?) -> {messages, has_more, nextCursor?}
    Newest first (conversations.history). opts: limit (default 15), cursor, oldest, latest, inclusive, include_all_metadata. Message files arrays carry file IDs for getFile and downloadFile.]],
    	getThread = [[getThread(channel, ts, opts?) -> {messages, has_more, nextCursor?}
    The parent message and its replies (conversations.replies). Same opts as listMessages.]],
    	searchMessages = [[searchMessages(query, opts?) -> {matches, total, paging, nextPage?}
    Slack search syntax, such as "in:#general from:@ana after:2026-01-01". opts: count, page, sort ("timestamp" default or "score"), sort_dir ("desc" default), highlight. Pass page = result.nextPage for the next page.]],
    	listMentions = [[listMentions(opts?) -> {matches, total, paging, nextPage?}
    Search results mentioning you, including thread replies. Same opts as searchMessages, plus query to narrow it, such as "in:#general".]],
    	listMembers = [[listMembers(channel, opts?) -> {members, nextCursor?}
    User IDs in a channel. opts: limit, cursor.]],
    	getUser = [[getUser(user) -> user
    A user's profile (users.info).]],
    	listUsers = [[listUsers(opts?) -> {members, nextCursor?}
    Workspace users. opts: limit (default 200), cursor, include_locale.]],
    	getPermalink = [[getPermalink(channel, ts) -> string
    A message's Slack URL.]],
    	getFile = [[getFile(id) -> file
    File metadata (files.info): name, mimetype, size, url_private...]],
    	downloadFile = [[downloadFile(id, path) -> {path, url, bytes}
    Streams a Slack file into a session path; url is a Houston signed download URL. Never inline file contents. A download that fails while streaming leaves path as it was. External files (is_external) are not stored in Slack and cannot be downloaded.]],
    	postMessage = [[postMessage(channel, text, opts?) -> {channel, ts, message}
    Posts as you; channel is a channel or DM ID. opts: thread_ts, blocks, attachments, unfurl_links, unfurl_media, reply_broadcast, mrkdwn, parse, link_names, metadata, client_msg_id. Never retry automatically: after an error the message may already be posted, so check with listMessages first.]],
    	reply = [[reply(channel, ts, text, opts?) -> {channel, ts, message}
    Replies in the thread of message ts. Same opts as postMessage, without thread_ts.]],
    	updateMessage = [[updateMessage(channel, ts, text, opts?) -> {channel, ts, text}
    Edits one of your messages. opts: blocks, attachments, parse, link_names, metadata, file_ids, reply_broadcast.]],
    	deleteMessage = [[deleteMessage(channel, ts) -> {channel, ts}
    Deletes one of your messages.]],
    	openConversation = [[openConversation(users) -> channel
    Opens a DM (one user ID) or group DM (a comma-separated string or array of IDs); pass channel.id to postMessage.]],
    	addReaction = [[addReaction(channel, ts, name) -> {ok}
    Adds an emoji reaction; name has no colons, such as "thumbsup".]],
    	removeReaction = [[removeReaction(channel, ts, name) -> {ok}
    Removes your emoji reaction.]],
    	uploadFile = [[uploadFile(path, opts?) -> {files}
    Streams a session file to Slack. opts: filename (default the path's last segment), title, alt_text, channel (share there; omit to keep the file private), thread_ts, text (a comment posted with the file).]],
    }
    
    exports.help = function(): string
    	local names: {string} = {}
    	for name in exports do
    		if name ~= "help" then table.insert(names, name) end
    	end
    	table.sort(names)
    	local sections = {[[Slack: one connected user in one workspace. Credentials stay on Houston. Calls return completed values; do not wrap them in await(). Pass channel IDs, user IDs and message timestamps (ts) as strings, never numbers. Unknown options are rejected. Writes act as the connected user. Only calls the connection's access allows are listed.
    Each call returns one page. Pass cursor = result.nextCursor (or page = result.nextPage for searches) for the next one. Slack limits conversations.history and conversations.replies to 1 request per minute and 15 messages for apps outside the Slack Marketplace, so listMessages and getThread can fail with ratelimited: wait as the error says, and prefer searchMessages to scan many channels. Slack errors name the Slack error code, such as not_in_channel or missing_scope.]]}
    	for _, name in names do
    		local section = operationHelp[name]
    		assert(section, "missing help for configured function " .. name)
    		table.insert(sections, "## " .. section)
    	end
    	return table.concat(sections, "\n\n")
    end
    
    return exports
    
  • houston.json
    {
      "schema_version": 2,
      "name": "Slack",
      "files": [
        "connector.luau"
      ],
      "icon": "icon.svg",
      "access": [
        {
          "name": "channels",
          "label": "Public channels",
          "description": "Public channels you are in: their messages, threads and members.",
          "levels": [
            {"value": "none", "label": "None"},
            {"value": "read", "label": "Read"}
          ],
          "default": "read"
        },
        {
          "name": "private_channels",
          "label": "Private channels",
          "description": "Private channels you are in: their messages, threads and members.",
          "levels": [
            {"value": "none", "label": "None"},
            {"value": "read", "label": "Read"}
          ],
          "default": "read"
        },
        {
          "name": "direct_messages",
          "label": "Direct messages",
          "description": "Direct and group direct messages; Write opens new ones.",
          "levels": [
            {"value": "none", "label": "None"},
            {"value": "read", "label": "Read"},
            {"value": "write", "label": "Write"}
          ],
          "default": "read"
        },
        {
          "name": "search",
          "label": "Search",
          "description": "Message search and your mentions.",
          "levels": [
            {"value": "none", "label": "None"},
            {"value": "read", "label": "Read"}
          ],
          "default": "read"
        },
        {
          "name": "users",
          "label": "Users",
          "description": "Workspace members and their profiles.",
          "levels": [
            {"value": "none", "label": "None"},
            {"value": "read", "label": "Read"}
          ],
          "default": "read"
        },
        {
          "name": "files",
          "label": "Files",
          "description": "Download shared files; Write uploads and shares files.",
          "levels": [
            {"value": "none", "label": "None"},
            {"value": "read", "label": "Read"},
            {"value": "write", "label": "Write"}
          ],
          "default": "read"
        },
        {
          "name": "reactions",
          "label": "Reactions",
          "description": "Add and remove your emoji reactions.",
          "levels": [
            {"value": "none", "label": "None"},
            {"value": "write", "label": "Write"}
          ],
          "default": "none"
        },
        {
          "name": "messages",
          "label": "Messages",
          "description": "Post, reply, edit and delete messages as you.",
          "levels": [
            {"value": "none", "label": "None"},
            {"value": "write", "label": "Write"}
          ],
          "default": "none"
        }
      ],
      "auth": {
        "oauth": {
          "type": "oauth2",
          "label": "Connect with Slack",
          "brand": "slack",
          "authorize_url": "https://slack.com/oauth/v2/authorize",
          "token_url": "https://slack.com/api/oauth.v2.access",
          "client_id": "{{publisher.client_id}}",
          "client_secret": "{{publisher.client_secret}}",
          "client_auth": "body",
          "pkce": "none",
          "scope_parameter": "user_scope",
          "scope_separator": ",",
          "scopes": [
            {
              "if": "{{ allows access.channels \"read\" }}",
              "values": [
                "channels:read",
                "channels:history"
              ]
            },
            {
              "if": "{{ allows access.private_channels \"read\" }}",
              "values": [
                "groups:read",
                "groups:history"
              ]
            },
            {
              "if": "{{ allows access.direct_messages \"read\" }}",
              "values": [
                "im:read",
                "im:history",
                "mpim:read",
                "mpim:history"
              ]
            },
            {
              "if": "{{ allows access.users \"read\" }}",
              "values": [
                "users:read"
              ]
            },
            {
              "if": "{{ allows access.search \"read\" }}",
              "values": [
                "search:read"
              ]
            },
            {
              "if": "{{ allows access.files \"read\" }}",
              "values": [
                "files:read"
              ]
            },
            {
              "if": "{{ allows access.messages \"write\" }}",
              "values": [
                "chat:write"
              ]
            },
            {
              "if": "{{ allows access.files \"write\" }}",
              "values": [
                "files:write"
              ]
            },
            {
              "if": "{{ allows access.direct_messages \"write\" }}",
              "values": [
                "im:write",
                "mpim:write"
              ]
            },
            {
              "if": "{{ allows access.reactions \"write\" }}",
              "values": [
                "reactions:write"
              ]
            }
          ],
          "token_response": {
            "access_token": "/authed_user/access_token",
            "refresh_token": "/authed_user/refresh_token",
            "expires_in": "/authed_user/expires_in",
            "scopes": "/authed_user/scope",
            "checks": [
              {
                "op": "equals",
                "path": "/ok",
                "value": true
              },
              {
                "op": "equals",
                "path": "/authed_user/token_type",
                "value": "user"
              },
              {
                "op": "exists",
                "path": "/team/id"
              },
              {
                "op": "exists",
                "path": "/authed_user/id"
              }
            ]
          },
          "refresh_response": {
            "checks": [
              {
                "op": "equals",
                "path": "/ok",
                "value": true
              }
            ]
          },
          "account": {
            "url": "https://slack.com/api/auth.test",
            "headers": {
              "Authorization": {
                "value": "Bearer {{auth.oauth.access_token}}"
              }
            },
            "label": "/team",
            "checks": [
              {
                "op": "equals",
                "path": "/ok",
                "value": true
              }
            ]
          }
        }
      },
      "publisher": {
        "client_id": {
          "label": "Slack client ID",
          "order": 1,
          "required": true,
          "type": "string"
        },
        "client_secret": {
          "label": "Slack client secret",
          "order": 2,
          "required": true,
          "type": "secret"
        }
      },
      "proxy": [
        {
          "match": {
            "protocol": "http",
            "host": [
              "slack.com"
            ],
            "method": [
              "GET"
            ],
            "path": [
              "/api/auth.test",
              "/api/users.conversations",
              "/api/conversations.info",
              "/api/conversations.history",
              "/api/conversations.replies",
              "/api/conversations.members",
              "/api/chat.getPermalink"
            ]
          },
          "action": {
            "headers": {
              "set": {
                "Authorization": "Bearer {{auth.oauth.access_token}}"
              }
            }
          }
        },
        {
          "if": "{{ allows access.search \"read\" }}",
          "match": {
            "protocol": "http",
            "host": [
              "slack.com"
            ],
            "method": [
              "GET"
            ],
            "path": [
              "/api/search.messages"
            ]
          },
          "action": {
            "headers": {
              "set": {
                "Authorization": "Bearer {{auth.oauth.access_token}}"
              }
            }
          }
        },
        {
          "if": "{{ allows access.users \"read\" }}",
          "match": {
            "protocol": "http",
            "host": [
              "slack.com"
            ],
            "method": [
              "GET"
            ],
            "path": [
              "/api/users.info",
              "/api/users.list"
            ]
          },
          "action": {
            "headers": {
              "set": {
                "Authorization": "Bearer {{auth.oauth.access_token}}"
              }
            }
          }
        },
        {
          "if": "{{ allows access.files \"read\" }}",
          "match": {
            "protocol": "http",
            "host": [
              "slack.com"
            ],
            "method": [
              "GET"
            ],
            "path": [
              "/api/files.info"
            ]
          },
          "action": {
            "headers": {
              "set": {
                "Authorization": "Bearer {{auth.oauth.access_token}}"
              }
            }
          }
        },
        {
          "if": "{{ allows access.files \"read\" }}",
          "match": {
            "protocol": "http",
            "host": [
              "files.slack.com"
            ],
            "method": [
              "GET"
            ],
            "path": [
              "/files-pri/*"
            ],
            "opaque_path_parameters": [
              "*"
            ]
          },
          "action": {
            "headers": {
              "set": {
                "Authorization": "Bearer {{auth.oauth.access_token}}"
              }
            }
          }
        },
        {
          "if": "{{ allows access.messages \"write\" }}",
          "match": {
            "protocol": "http",
            "host": [
              "slack.com"
            ],
            "method": [
              "POST"
            ],
            "path": [
              "/api/chat.postMessage",
              "/api/chat.update",
              "/api/chat.delete"
            ]
          },
          "action": {
            "headers": {
              "set": {
                "Authorization": "Bearer {{auth.oauth.access_token}}"
              }
            }
          }
        },
        {
          "if": "{{ allows access.direct_messages \"write\" }}",
          "match": {
            "protocol": "http",
            "host": [
              "slack.com"
            ],
            "method": [
              "POST"
            ],
            "path": [
              "/api/conversations.open"
            ]
          },
          "action": {
            "headers": {
              "set": {
                "Authorization": "Bearer {{auth.oauth.access_token}}"
              }
            }
          }
        },
        {
          "if": "{{ allows access.reactions \"write\" }}",
          "match": {
            "protocol": "http",
            "host": [
              "slack.com"
            ],
            "method": [
              "POST"
            ],
            "path": [
              "/api/reactions.add",
              "/api/reactions.remove"
            ]
          },
          "action": {
            "headers": {
              "set": {
                "Authorization": "Bearer {{auth.oauth.access_token}}"
              }
            }
          }
        },
        {
          "if": "{{ allows access.files \"write\" }}",
          "match": {
            "protocol": "http",
            "host": [
              "slack.com"
            ],
            "method": [
              "POST"
            ],
            "path": [
              "/api/files.getUploadURLExternal",
              "/api/files.completeUploadExternal"
            ]
          },
          "action": {
            "headers": {
              "set": {
                "Authorization": "Bearer {{auth.oauth.access_token}}"
              }
            }
          }
        },
        {
          "if": "{{ allows access.files \"write\" }}",
          "match": {
            "protocol": "http",
            "host": [
              "files.slack.com"
            ],
            "method": [
              "POST"
            ],
            "path": [
              "/upload/v1/*"
            ],
            "opaque_path_parameters": [
              "*"
            ]
          },
          "action": {
            "headers": {
              "remove": [
                "Authorization"
              ]
            }
          }
        }
      ]
    }
    
  • icon.svgicon.svg
  • README.md
    ---
    description: Let agents read your Slack channels, threads and mentions, and post or reply as you.
    ---
    
    # Slack
    
    Let agents catch you up on Slack: summarize a busy channel, find the thread where
    a decision was made, list the messages that mention you, or pull an attachment
    someone shared. They see the channels, private channels and direct messages you
    can see, and search the same way you do in Slack.
    
    With write access, agents can also act as you: post or reply in a thread, send a
    direct message, edit or delete your messages, react with an emoji, or share a
    file. Everything they post appears under your name.
    
    Choose the access for each part of Slack: public channels, private channels,
    direct messages, search, users and files can be read, and messages, reactions,
    direct messages and files can be written. By default agents read and search, but
    never post. Each connection covers one Slack workspace; add another connection
    for each additional workspace.
    
    Connect with Slack in one click: pick your workspace and allow access. Your
    authorization stays on Houston's server. See [Connect your Slack account](SETUP.md).
    
  • SETUP.md
    # Connect Slack
    
    1. In Houston, choose the access for each row: **Read** or **None** for
       **Public channels**, **Private channels**, **Search** and **Users**; **Read**,
       **Write** or **None** for **Direct messages** and **Files**; and **Write** or
       **None** for **Reactions** and **Messages**.
    2. Select **Add to Slack**, sign in and check the workspace shown.
    3. Select **Allow**. If approval is required, ask a workspace admin and reconnect
       after approval.
    
    > Agents see what you can see in the rows you allow, including private channels
    > and direct messages. With **Messages** or **Files** at **Write**, they post and
    > share files under your name. **Direct messages** at **Write** lets them open
    > new direct and group conversations.
    
    | Row | Read | Write |
    | --- | --- | --- |
    | Public channels | `channels:read`, `channels:history` | |
    | Private channels | `groups:read`, `groups:history` | |
    | Direct messages | `im:read`, `im:history`, `mpim:read`, `mpim:history` | adds `im:write`, `mpim:write` |
    | Search | `search:read` | |
    | Users | `users:read` | |
    | Files | `files:read` | adds `files:write` |
    | Reactions | | `reactions:write` |
    | Messages | | `chat:write` |
    
    ## Advanced
    
    Add one connection per workspace; Enterprise Grid-wide installations are unsupported.
    Raising any row asks you to authorize again. Long channel histories may be slow
    because of Slack's app limits; search is often faster.
    
    Deleting the Houston connection removes its saved authorization. Also revoke
    Houston on Slack's [app management](https://slack.com/apps/manage) page to end
    provider access.
    
  • tests
    • authentication.luau
      return {
      	contract = function(m)
      		m.authentication({
      			{
      				auth = {},
      				config = {},
      				endpoint = { "GET", "https://slack.com/api/auth.test" },
      				expected = "Bearer synthetic-oauth-token",
      				header = "Authorization",
      				method = "oauth",
      				oauth = true,
      				publisher = {
      					client_id = "synthetic-public-client",
      					client_secret = "synthetic-client-secret",
      				},
      				scopes = true,
      			},
      		})
      	end,
      }
      
    • errors.luau
      return {
      	scenario = {publisher = {client_id = "fixture-client", client_secret = "fixture-private-secret"}, config = {}, auth_method = "oauth", auth_config = {}},
      	access = {messages = "write", files = "write", reactions = "write"},
      	configure = function()
      		calls = 0
      		http = {request = function()
      			calls += 1
      			return fixture.operation({statusCode = status, headers = responseHeaders, body = fixture.reader(payload)})
      		end}
      	end,
      	run = function(slack)
      		local function upstream(code, body, headers, expected, call)
      			status, payload, responseHeaders = code, body, headers
      			local before = calls
      			local ok, err = pcall(call or function() slack.listMessages("C1") end)
      			for _, text in expected do
      				assert(not ok and string.find(tostring(err), text, 1, true), "missing " .. text .. " in " .. tostring(err))
      			end
      			assert(calls == before + 1, "failed call was retried")
      		end
      		upstream(200, '{"ok":false,"error":"not_in_channel"}', {}, {"slack: not_in_channel", '"upstream_status":200', '"retryable":false'})
      		upstream(200, '{"ok":false,"error":"missing_scope","needed":"chat:write","provided":"channels:read"}', {},
      			{"slack: missing_scope (needs chat:write)", "reconnect Slack", '"upstream_status":403', '"retryable":false'},
      			function() slack.postMessage("C1", "Hi") end)
      		upstream(200, '{"ok":false,"error":"token_revoked"}', {}, {"slack: token_revoked; reconnect Slack", '"upstream_status":401'})
      		upstream(200, '{"ok":false,"error":"invalid_auth"}', {}, {"slack: invalid_auth", '"upstream_status":401'})
      		upstream(429, '{"ok":false,"error":"ratelimited"}', {["retry-after"] = {"60"}},
      			{"slack: ratelimited; retry after 60s", '"upstream_status":429', '"retryable":true'})
      		upstream(200, '{"ok":false,"error":"internal_error"}', {}, {"slack: internal_error", '"retryable":true'})
      		upstream(200, '{"ok":false,"error":"fatal_error"}', {}, {"slack: fatal_error", '"retryable":false'},
      			function() slack.postMessage("C1", "Hi") end)
      		upstream(503, "unavailable", {}, {"slack: HTTP 503", '"retryable":false'}, function() slack.deleteMessage("C1", "1.0") end)
      		fs = fixture.files()
      		local file = fs.open("report.txt", "w")
      		file:write("report")
      		await(file:close())
      		upstream(503, "unavailable", {}, {"slack: HTTP 503", '"retryable":true'}, function() slack.uploadFile("report.txt") end)
      		local reserved = calls
      		local ok, err = pcall(function()
      			status, payload, responseHeaders = 200, '{"ok":true,"upload_url":"https://files.slack.com/upload/v1/signed","file_id":"F1"}', {}
      			local request = http.request
      			http.request = function(req)
      				if string.find(req.url, "files.slack.com", 1, true) then status, payload = 503, "unavailable" end
      				return request(req)
      			end
      			slack.uploadFile("report.txt")
      		end)
      		assert(not ok and string.find(tostring(err), '"retryable":true', 1, true) and calls == reserved + 2, "an uncompleted upload is safe to retry")
      		upstream(429, '{"ok":false,"error":"ratelimited"}', {["retry-after"] = {"30"}}, {"retry after 30s", '"retryable":true'},
      			function() slack.addReaction("C1", "1.0", "eyes") end)
      		upstream(503, "<html>Service unavailable</html>", {}, {"slack: HTTP 503", '"retryable":true'})
      		upstream(200, "<html>Maintenance</html>", {}, {"slack: invalid JSON response"})
      		upstream(200, "[]", {}, {"slack: invalid JSON response"})
      		upstream(200, '{"ok":true}', {}, {"slack: response has no channel"}, function() slack.getChannel("C1") end)
      		upstream(200, '{"ok":false,"error":"' .. string.rep("x", 5000) .. '"}', {}, {"slack: xxxx"})
      		local ok, err = pcall(slack.listMessages, "C1")
      		assert(not ok and #tostring(err) < 1000, "error messages stay bounded")
      	end,
      }
      
    • manifest.luau
      return {
      	contract = function(m)
      		-- TestSlackPublisherOwnedClient
      		do
      			if not (m.publisherClient(m.raw.auth["oauth"])) then
      				m.fail("Slack OAuth client must belong to the publication")
      			end
      		end
      		-- TestSlackScopesAndAccessRoutes
      		do
      			local base = {
      				"GET https://slack.com/api/auth.test",
      				"GET https://slack.com/api/users.conversations?types=im",
      				"GET https://slack.com/api/conversations.history?channel=C1",
      				"GET https://slack.com/api/conversations.replies?channel=C1&ts=1.2",
      				"GET https://slack.com/api/conversations.info?channel=C1",
      				"GET https://slack.com/api/conversations.members?channel=C1",
      				"GET https://slack.com/api/chat.getPermalink?channel=C1&message_ts=1.2",
      			}
      			local conversations = { "getChannel", "getPermalink", "getThread", "listChannels", "listMembers", "listMessages" }
      			-- In scope group order; each entry is active when its row allows its level.
      			local gates = {
      				{ row = "channels", level = "read", scopes = { "channels:read", "channels:history" }, exports = conversations },
      				{ row = "private_channels", level = "read", scopes = { "groups:read", "groups:history" }, exports = conversations },
      				{
      					row = "direct_messages",
      					level = "read",
      					scopes = { "im:read", "im:history", "mpim:read", "mpim:history" },
      					exports = conversations,
      				},
      				{
      					row = "users",
      					level = "read",
      					scopes = { "users:read" },
      					routes = { "GET https://slack.com/api/users.info?user=U1", "GET https://slack.com/api/users.list?limit=200" },
      					exports = { "getUser", "listUsers" },
      				},
      				{
      					row = "search",
      					level = "read",
      					scopes = { "search:read" },
      					routes = { "GET https://slack.com/api/search.messages?query=hi" },
      					exports = { "listMentions", "searchMessages" },
      				},
      				{
      					row = "files",
      					level = "read",
      					scopes = { "files:read" },
      					routes = {
      						"GET https://slack.com/api/files.info?file=F1",
      						"GET https://files.slack.com/files-pri/T1-F1/download/report.pdf",
      						"GET https://files.slack.com/files-pri/T1-F1/download/100%25%20done.pdf",
      					},
      					exports = { "downloadFile", "getFile" },
      				},
      				{
      					row = "messages",
      					level = "write",
      					scopes = { "chat:write" },
      					routes = {
      						"POST https://slack.com/api/chat.postMessage",
      						"POST https://slack.com/api/chat.update",
      						"POST https://slack.com/api/chat.delete",
      					},
      					exports = { "deleteMessage", "postMessage", "reply", "updateMessage" },
      				},
      				{
      					row = "files",
      					level = "write",
      					scopes = { "files:write" },
      					routes = {
      						"POST https://slack.com/api/files.getUploadURLExternal",
      						"POST https://slack.com/api/files.completeUploadExternal",
      					},
      					unauthenticated = { "POST https://files.slack.com/upload/v1/CwABAAAAXQoAAQ%2FBz%3D" },
      					exports = { "uploadFile" },
      				},
      				{
      					row = "direct_messages",
      					level = "write",
      					scopes = { "im:write", "mpim:write" },
      					routes = { "POST https://slack.com/api/conversations.open" },
      					exports = { "openConversation" },
      				},
      				{
      					row = "reactions",
      					level = "write",
      					scopes = { "reactions:write" },
      					routes = { "POST https://slack.com/api/reactions.add", "POST https://slack.com/api/reactions.remove" },
      					exports = { "addReaction", "removeReaction" },
      				},
      			}
      			local denied = {
      				"GET https://slack.com/api/chat.postMessage?channel=C1&text=hi",
      				"GET https://slack.com/api/files.getUploadURLExternal?filename=a&length=1",
      				"POST https://slack.com/api/oauth.v2.access",
      				"GET https://slack.com/api/oauth.v2.access",
      				"POST https://slack.com/api/auth.revoke",
      				"POST https://slack.com/api/conversations.history",
      				"GET https://slack.com/api/users.profile.set",
      				"GET https://files.slack.com/upload/v1/signed",
      				"POST https://files.slack.com/files-pri/T1-F1/download/report.pdf",
      				"GET https://files.slack.com/files-pri/../upload/v1/signed",
      				"GET https://slack.com.evil.test/api/auth.test",
      				"GET https://evil.slack.com/api/auth.test",
      			}
      			local rank = { none = 0, read = 1, write = 2 }
      			-- Each row's levels above none.
      			local rows = {
      				channels = { "read" },
      				private_channels = { "read" },
      				direct_messages = { "read", "write" },
      				search = { "read" },
      				users = { "read" },
      				files = { "read", "write" },
      				reactions = { "write" },
      				messages = { "write" },
      			}
      			local readOnly = {
      				"channels:read",
      				"channels:history",
      				"groups:read",
      				"groups:history",
      				"im:read",
      				"im:history",
      				"mpim:read",
      				"mpim:history",
      				"users:read",
      				"search:read",
      				"files:read",
      			}
      			local readWrite = m.concat(readOnly, { "chat:write", "files:write", "im:write", "mpim:write", "reactions:write" })
      			local defaults, top = { reactions = "none", messages = "none" }, {}
      			for row, levels in rows do
      				defaults[row] = defaults[row] or "read"
      				top[row] = levels[#levels]
      			end
      			local cases = { { levels = defaults, scopes = readOnly }, { access = top, levels = top, scopes = readWrite } }
      			for row, levels in rows do
      				for _, level in levels do
      					local only = {}
      					for name in rows do
      						only[name] = "none"
      					end
      					only[row] = level
      					table.insert(cases, { access = only, levels = only })
      				end
      			end
      			local publisher = { client_id = "fixture-client", client_secret = "fixture-secret" }
      			for _, case in cases do
      				local parts = {}
      				for row, level in case.levels do
      					table.insert(parts, row .. "=" .. level)
      				end
      				table.sort(parts)
      				local label = table.concat(parts, " ")
      				local scopes, allowed, blocked, open, closed, names, seen = {}, {}, {}, {}, {}, { "getProfile" }, {}
      				for _, gate in gates do
      					local on = rank[case.levels[gate.row]] >= rank[gate.level]
      					if on then
      						scopes = m.concat(scopes, gate.scopes)
      						for _, name in gate.exports do
      							if not seen[name] then
      								seen[name] = true
      								table.insert(names, name)
      							end
      						end
      					end
      					for _, route in gate.routes or {} do
      						table.insert(if on then allowed else blocked, route)
      					end
      					for _, route in gate.unauthenticated or {} do
      						table.insert(if on then open else closed, route)
      					end
      				end
      				table.sort(names)
      				if case.scopes and not m.equal(scopes, case.scopes) then
      					m.fail("%s expected scopes do not reproduce the v1 set", label)
      				end
      				local r, err = m.resolve(publisher, {}, nil, "oauth", case.access)
      				assert(not err, tostring(err))
      				if not m.equal(r.Scopes, scopes) then
      					m.fail("access=%s scopes %s", label, r.Scopes)
      				end
      				r.Context.Auth["oauth"].access_token = "xoxp-fixture"
      				m.routes(r, "Bearer xoxp-fixture", true, m.concat(base, allowed))
      				m.routes(r, "Bearer xoxp-fixture", false, m.concat(blocked, denied))
      				m.routes(r, "", true, open)
      				m.routes(r, "", false, closed)
      				local result, exportErr = m.exports({}, "oauth", scopes, nil, case.access)
      				assert(result and not exportErr, tostring(exportErr))
      				if not (result.type == "result" and m.equal(result.exports, names)) then
      					m.fail("access=%s exports %s", label, result.exports)
      				end
      			end
      		end
      	end,
      }
      
    • read_only.luau
      return {
      	scenario = {publisher = {client_id = "fixture-client", client_secret = "fixture-private-secret"}, config = {}, auth_method = "oauth", auth_config = {}},
      	configure = function()
      		requests, responses = {}, {}
      		http = {request = function(req)
      			table.insert(requests, req)
      			assert(#responses > 0, "unexpected request: " .. req.url)
      			return fixture.operation({statusCode = 200, headers = {}, body = fixture.reader(table.remove(responses, 1))})
      		end}
      	end,
      	run = function(slack)
      		local names = {}
      		for name, fn in slack do
      			assert(type(fn) == "function")
      			table.insert(names, name)
      		end
      		table.sort(names)
      		assert(table.concat(names, ",") == "downloadFile,getChannel,getFile,getPermalink,getProfile,getThread,getUser,"
      			.. "listChannels,listMembers,listMentions,listMessages,listUsers,searchMessages",
      			"default access exposes only reads: " .. table.concat(names, ","))
      
      		responses = {'{"ok":true,"channels":[],"response_metadata":{"next_cursor":""}}'}
      		local page = slack.listChannels()
      		assert(json.encode(page.channels) == "[]" and page.nextCursor == nil)
      		assert(requests[1].method == "GET" and requests[1].body == nil and requests[1].headers == nil, "credentials stay in the proxy")
      		assert(requests[1].url == "https://slack.com/api/users.conversations?exclude_archived=true&types=public_channel%2Cprivate_channel%2Cim%2Cmpim")
      
      		responses = {'{"ok":true,"channels":[{"id":"C1"},{"id":"D1"}],"response_metadata":{"next_cursor":"dGVhbTpDMDYx+/=="}}'}
      		page = slack.listChannels({types = "im", exclude_archived = false, limit = 200})
      		assert(#page.channels == 2 and page.nextCursor == "dGVhbTpDMDYx+/==")
      		assert(requests[2].url == "https://slack.com/api/users.conversations?exclude_archived=false&limit=200&types=im")
      
      		local ok, err = pcall(slack.listChannels, {user = "U_OTHER"})
      		assert(not ok and string.find(tostring(err), "unknown option user", 1, true))
      		assert(#requests == 2, "invalid input reached Slack")
      	end,
      }
      
    • reads.luau
      return {
      	scenario = {publisher = {client_id = "fixture-client", client_secret = "fixture-private-secret"}, config = {}, auth_method = "oauth", auth_config = {}},
      	configure = function()
      		requests, responses = {}, {}
      		fs = fixture.files()
      		http = {request = function(req)
      			table.insert(requests, req)
      			assert(#responses > 0, "unexpected request: " .. req.url)
      			local response = table.remove(responses, 1)
      			if type(response) == "string" then response = {body = response} end
      			return fixture.operation({statusCode = response.status or 200, headers = response.headers or {}, body = fixture.reader(response.body)})
      		end}
      		function last() return requests[#requests].url end
      		function rejected(fn, ...)
      			local before = #requests
      			local ok, err = pcall(fn, ...)
      			assert(not ok and #requests == before, "invalid input reached Slack")
      			return tostring(err)
      		end
      	end,
      	run = function(slack)
      		responses = {'{"ok":true,"messages":[{"ts":"1790000000.000001","text":"hi"}],"has_more":true,"response_metadata":{"next_cursor":"bmV4dA=="}}'}
      		local history = slack.listMessages("C1", {oldest = "1780000000.000000"})
      		assert(history.messages[1].ts == "1790000000.000001" and history.has_more and history.nextCursor == "bmV4dA==")
      		assert(last() == "https://slack.com/api/conversations.history?channel=C1&limit=15&oldest=1780000000.000000")
      
      		local opts = {cursor = "next+one", limit = 5}
      		responses = {'{"ok":true,"messages":[],"has_more":false}'}
      		local thread = slack.getThread("C1", "1790000000.000001", opts)
      		assert(json.encode(thread.messages) == "[]" and thread.nextCursor == nil)
      		assert(last() == "https://slack.com/api/conversations.replies?channel=C1&cursor=next%2Bone&limit=5&ts=1790000000.000001")
      		assert(opts.channel == nil and opts.ts == nil, "options are not mutated")
      
      		responses = {'{"ok":true,"messages":{"matches":[{"text":"hi"}],"total":3,"paging":{"page":1,"pages":3}}}'}
      		local found = slack.searchMessages("in:#general hello", {count = 1})
      		assert(found.total == 3 and found.nextPage == 2)
      		assert(last() == "https://slack.com/api/search.messages?count=1&query=in%3A%23general%20hello&sort=timestamp&sort_dir=desc")
      
      		responses = {'{"ok":true,"user_id":"U1"}', '{"ok":true,"messages":{"matches":[],"total":0,"paging":{"page":1,"pages":1}}}'}
      		local mentions = slack.listMentions({query = "in:#general", page = 1})
      		assert(json.encode(mentions.matches) == "[]" and mentions.nextPage == nil)
      		assert(requests[#requests - 1].url == "https://slack.com/api/auth.test")
      		assert(last() == "https://slack.com/api/search.messages?page=1&query=%3C%40U1%3E%20in%3A%23general&sort=timestamp&sort_dir=desc")
      
      		responses = {'{"ok":true,"channel":{"id":"C1","name":"general"}}', '{"ok":true,"user":{"id":"U1"}}',
      			'{"ok":true,"permalink":"https://acme.slack.com/archives/C1/p1"}', '{"ok":true,"members":["U1","U2"]}',
      			'{"ok":true,"members":[{"id":"U1"}],"response_metadata":{"next_cursor":"dXNlcjpVMg=="}}', '{"ok":true,"members":[]}'}
      		assert(slack.getChannel("C1").name == "general" and last() == "https://slack.com/api/conversations.info?channel=C1")
      		assert(slack.getUser("U1").id == "U1" and last() == "https://slack.com/api/users.info?user=U1")
      		assert(slack.getPermalink("C1", "1.2") == "https://acme.slack.com/archives/C1/p1")
      		assert(last() == "https://slack.com/api/chat.getPermalink?channel=C1&message_ts=1.2")
      		assert(#slack.listMembers("C1", {limit = 2}).members == 2 and last() == "https://slack.com/api/conversations.members?channel=C1&limit=2")
      		local users = slack.listUsers()
      		assert(users.members[1].id == "U1" and users.nextCursor == "dXNlcjpVMg==" and last() == "https://slack.com/api/users.list?limit=200")
      		assert(json.encode(slack.listMembers("C2").members) == "[]" and last() == "https://slack.com/api/conversations.members?channel=C2")
      
      		local file = '{"ok":true,"file":{"id":"F1","mimetype":"application/pdf","url_private_download":"https://files.slack.com/files-pri/T1-F1/download/report.pdf"}}'
      		responses = {file, {body = "%PDF bytes", headers = {["content-type"] = {"application/pdf"}}}}
      		local saved = slack.downloadFile("F1", "report.pdf")
      		assert(requests[#requests - 1].url == "https://slack.com/api/files.info?file=F1")
      		assert(last() == "https://files.slack.com/files-pri/T1-F1/download/report.pdf" and requests[#requests].headers == nil)
      		assert(saved.path == "report.pdf" and saved.url == "https://houston.test/report.pdf" and saved.bytes == 10)
      		local saved_file = fs.open("report.pdf", "r")
      		assert(await(saved_file:readAll()) == "%PDF bytes")
      		await(saved_file:close())
      
      		-- A failed download leaves an existing session file untouched.
      		responses = {file, {body = "<html>Sign in</html>", headers = {["content-type"] = {"text/html; charset=utf-8"}}}}
      		local ok, err = pcall(slack.downloadFile, "F1", "report.pdf")
      		assert(not ok and string.find(tostring(err), "sign-in page", 1, true) and string.find(tostring(err), '"upstream_status":401', 1, true))
      		responses = {file, {status = 403, body = "Forbidden"}}
      		ok, err = pcall(slack.downloadFile, "F1", "report.pdf")
      		assert(not ok and string.find(tostring(err), "slack: HTTP 403", 1, true) and string.find(tostring(err), '"upstream_status":403', 1, true))
      		responses = {file, {status = 302, body = ""}}
      		ok, err = pcall(slack.downloadFile, "F1", "report.pdf")
      		assert(not ok and string.find(tostring(err), "reconnect Slack", 1, true) and string.find(tostring(err), '"upstream_status":401', 1, true))
      		responses = {'{"ok":true,"file":{"id":"F9","is_external":true,"url_private":"https://docs.example.com/d/1"}}'}
      		ok, err = pcall(slack.downloadFile, "F9", "report.pdf")
      		assert(not ok and string.find(tostring(err), "stored outside Slack", 1, true) and last() == "https://slack.com/api/files.info?file=F9")
      		local kept = fs.open("report.pdf", "r")
      		assert(await(kept:readAll()) == "%PDF bytes", "a failed download replaced the file")
      		await(kept:close())
      
      		local page = '{"ok":true,"file":{"id":"F2","mimetype":"text/html","url_private_download":"https://files.slack.com/files-pri/T1-F2/download/page.html"}}'
      		responses = {page, {body = "<html>Page</html>", headers = {["content-type"] = {"text/html"}}}}
      		assert(slack.downloadFile("F2", "page.html").bytes == 17, "an HTML file downloads")
      
      		responses = {'{"ok":true,"user_id":"U1"}', '{"ok":true,"messages":{"matches":[],"total":0,"paging":{"page":1,"pages":1}}}'}
      		slack.listMentions({query = ""})
      		assert(last() == "https://slack.com/api/search.messages?query=%3C%40U1%3E&sort=timestamp&sort_dir=desc", "an empty filter is ignored")
      
      		assert(string.find(rejected(slack.getThread, "C1", 1790000000.000001), "thread timestamp must be", 1, true))
      		assert(string.find(rejected(slack.listMessages, "", nil), "channel ID must be", 1, true))
      		assert(string.find(rejected(slack.listMessages, "C1", {limit = {1}}), "limit must be", 1, true))
      		assert(string.find(rejected(slack.listMessages, "C1", {latest = 1790000000.00001}), "latest must be", 1, true))
      		assert(string.find(rejected(slack.listChannels, {cursor = ""}), "cursor must be", 1, true))
      		assert(string.find(rejected(slack.searchMessages, "x", {query = "y"}), "unknown option query", 1, true))
      		assert(string.find(rejected(slack.listMentions, {query = 7}), "query must be", 1, true))
      		assert(string.find(rejected(slack.downloadFile, "F1", ""), "session path must be", 1, true))
      		assert(#responses == 0)
      	end,
      }
      
    • writes.luau
      return {
      	scenario = {publisher = {client_id = "fixture-client", client_secret = "fixture-private-secret"}, config = {}, auth_method = "oauth", auth_config = {}},
      	access = {direct_messages = "write", files = "write", reactions = "write", messages = "write"},
      	configure = function()
      		requests, responses = {}, {}
      		fs = fixture.files()
      		local upload = fs.open("reports/q3.txt", "w")
      		upload:write("hello slack")
      		await(upload:close())
      		await(fs.open("reports/empty.txt", "w"):close())
      		http = {request = function(req)
      			if req.body ~= nil and type(req.body) ~= "string" then req.wire = await(req.body:readAll()) end
      			table.insert(requests, req)
      			assert(#responses > 0, "unexpected request: " .. req.url)
      			local response = table.remove(responses, 1)
      			if type(response) == "string" then response = {body = response} end
      			return fixture.operation({statusCode = response.status or 200, headers = {}, body = fixture.reader(response.body)})
      		end}
      		function sent(index)
      			local req = requests[index]
      			assert(req.method == "POST" and req.headers["Content-Type"][1] == "application/json; charset=utf-8")
      			assert(req.headers.Authorization == nil, "credentials stay in the proxy")
      			return json.decode(req.body)
      		end
      	end,
      	run = function(slack)
      		for _, name in {"postMessage", "reply", "updateMessage", "deleteMessage", "openConversation", "addReaction", "removeReaction", "uploadFile"} do
      			assert(type(slack[name]) == "function", name .. " is exported at write access")
      		end
      
      		local opts = {blocks = {{type = "section", text = {type = "mrkdwn", text = "*Hi*"}}}, unfurl_links = false}
      		responses = {'{"ok":true,"channel":"C1","ts":"1.000002","message":{"text":"Hello"}}'}
      		assert(slack.reply("C1", "1.000001", "Hello", opts).ts == "1.000002")
      		local body = sent(1)
      		assert(requests[1].url == "https://slack.com/api/chat.postMessage")
      		assert(body.channel == "C1" and body.thread_ts == "1.000001" and body.text == "Hello" and body.unfurl_links == false)
      		assert(body.blocks[1].text.text == "*Hi*" and opts.channel == nil and opts.text == nil, "options are not mutated")
      
      		responses = {'{"ok":true,"channel":"C1","ts":"1.000003"}', '{"ok":true,"channel":"C1","ts":"1.000003","text":"Edited"}',
      			'{"ok":true,"channel":"C1","ts":"1.000003"}', '{"ok":true,"channel":{"id":"G1"}}', '{"ok":true}', '{"ok":true}'}
      		slack.postMessage("C1", "Hi")
      		body = sent(2)
      		assert(requests[2].url == "https://slack.com/api/chat.postMessage" and body.channel == "C1" and body.text == "Hi" and body.thread_ts == nil)
      		slack.updateMessage("C1", "1.000003", "Edited")
      		body = sent(3)
      		assert(requests[3].url == "https://slack.com/api/chat.update" and body.ts == "1.000003" and body.text == "Edited")
      		slack.deleteMessage("C1", "1.000003")
      		assert(requests[4].url == "https://slack.com/api/chat.delete" and sent(4).ts == "1.000003")
      		assert(slack.openConversation({"U1", "U2"}).id == "G1")
      		assert(requests[5].url == "https://slack.com/api/conversations.open" and sent(5).users == "U1,U2")
      		slack.addReaction("C1", "1.000003", "thumbsup")
      		body = sent(6)
      		assert(requests[6].url == "https://slack.com/api/reactions.add" and body.timestamp == "1.000003" and body.name == "thumbsup")
      		slack.removeReaction("C1", "1.000003", "thumbsup")
      		assert(requests[7].url == "https://slack.com/api/reactions.remove" and sent(7).name == "thumbsup")
      
      		responses = {'{"ok":true,"upload_url":"https://files.slack.com/upload/v1/signed","file_id":"F1"}', "OK - 11",
      			'{"ok":true,"files":[{"id":"F1","title":"Q3"}]}'}
      		local uploaded = slack.uploadFile("reports/q3.txt", {channel = "C1", thread_ts = "1.000001", text = "Q3 numbers", title = "Q3", alt_text = "Report"})
      		assert(uploaded.files[1].id == "F1")
      		assert(requests[8].method == "POST" and requests[8].url == "https://slack.com/api/files.getUploadURLExternal")
      		assert(requests[8].headers["Content-Type"][1] == "application/x-www-form-urlencoded")
      		assert(requests[8].body == "alt_txt=Report&filename=q3.txt&length=11")
      		assert(requests[9].url == "https://files.slack.com/upload/v1/signed" and requests[9].wire == "hello slack")
      		assert(requests[9].headers["Content-Type"][1] == "application/octet-stream" and requests[9].headers.Authorization == nil)
      		body = sent(10)
      		assert(requests[10].url == "https://slack.com/api/files.completeUploadExternal")
      		assert(body.files[1].id == "F1" and body.files[1].title == "Q3" and body.channel_id == "C1"
      			and body.thread_ts == "1.000001" and body.initial_comment == "Q3 numbers")
      
      		responses = {'{"ok":true,"upload_url":"https://files.slack.com/upload/v1/private","file_id":"F2"}', "OK", '{"ok":true,"files":[{"id":"F2"}]}'}
      		slack.uploadFile("reports/q3.txt")
      		assert(requests[11].body == "filename=q3.txt&length=11")
      		body = sent(13)
      		assert(body.files[1].title == "q3.txt" and body.channel_id == nil, "an unshared upload stays private")
      
      		responses = {'{"ok":true,"upload_url":"https://files.slack.com/upload/v1/expired","file_id":"F3"}', {status = 404, body = "Not Found"}}
      		local ok, err = pcall(slack.uploadFile, "reports/q3.txt", {channel = "C1"})
      		assert(not ok and string.find(tostring(err), "slack: HTTP 404", 1, true) and #requests == 15, "a failed upload is not completed")
      		responses = {'{"ok":true,"upload_url":"https://files.slack.com/upload/v1/signed","file_id":"F4"}', "OK", '{"ok":false,"error":"channel_not_found"}'}
      		ok, err = pcall(slack.uploadFile, "reports/q3.txt", {channel = "C404"})
      		assert(not ok and string.find(tostring(err), "slack: channel_not_found", 1, true) and #requests == 18)
      
      		local before = #requests
      		for _, case in {
      			{function() slack.postMessage("C1", "Hi", {username = "someone-else"}) end, "unknown option username"},
      			{function() slack.postMessage("C1", "Hi", {icon_url = "https://example.com/a.png"}) end, "unknown option icon_url"},
      			{function() slack.reply("C1", "1.0", "Hi", {thread_ts = "2.0"}) end, "unknown option thread_ts"},
      			{function() slack.postMessage("C1", "") end, "message text must be"},
      			{function() slack.openConversation({"U1", ""}) end, "user ID 2 must be"},
      			{function() slack.uploadFile("reports/q3.txt", {channel = 5}) end, "channel must be"},
      			{function() slack.uploadFile("missing.txt") end, "not_found"},
      			{function() slack.uploadFile("reports/empty.txt") end, "nonempty session file"},
      			{function() slack.uploadFile("reports/q3.txt", {thread_ts = "1.0"}) end, "need channel"},
      			{function() slack.uploadFile("reports/q3.txt", {text = "hi"}) end, "need channel"},
      			{function() slack.postMessage("C1", "Hi", {thread_ts = 1790000000.00001}) end, "thread_ts must be"},
      		} do
      			local ok, err = pcall(case[1])
      			local message = if type(err) == "table" then json.encode(err) else tostring(err)
      			assert(not ok and string.find(message, case[2], 1, true), message)
      		end
      		assert(#requests == before and #responses == 0, "invalid input reached Slack")
      	end,
      }