# List Messages — Bot for Slack

> Read the message history of a channel, direct message (DM), or group DM using the bot token, newest first. Returns messages with text, timestamps (ts), user IDs, and reactions, plus has_more to tell whether older messages remain. To read…

- Key: `slack_bot-list-messages`
- Type: Action (Read-only)
- Version: 0.0.1
- App: Bot for Slack (`slack_bot`) — https://pipedream.com/apps/slack-bot.md
- This page (HTML): https://pipedream.com/apps/slack-bot/actions/list-messages
- Hints: read-only · open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/slack_bot/actions/list-messages/list-messages.mjs

## Description

Read the message history of a channel, direct message (DM), or group DM using the bot token, newest first. Returns messages with text, timestamps (`ts`), user IDs, and reactions, plus `has_more` to tell whether older messages remain. To read further back, call again with `latest` set to the `ts` of the last message returned and `inclusive` left `false`, so that message is not returned again. Use **List Replies** with a message's `ts` to read its thread. [See the documentation](https://api.slack.com/methods/conversations.history)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `conversation` | `string` | Yes | The ID of the conversation to read, e.g. C1234567890 for a channel or D1234567890 for a DM. Use List Channels to find a channel ID (the id field). A DM ID is the channel field of a message the bot received or of a Send Message response. In order to list a Slack channel, your bot must be a member of that channel, and in order to list private channels, your bot must have the groups:read scope in the OAuth & Permissions settings in Slack for this bot. Options are loaded from the connected account. |
| `limit` | `integer` | No | Maximum number of messages to return, e.g. 50. Default: 15. Slack apps distributed commercially outside the Slack Marketplace are capped at 15 messages and 1 request per minute; keep the default for those. Internal and Marketplace apps can request more, and results are paged automatically. |
| `oldest` | `string` | No | Only return messages posted after this Slack timestamp, e.g. 1610000000.000000 (Unix epoch seconds, optionally with fractional microseconds). A message with exactly this timestamp is excluded unless Inclusive is true. |
| `latest` | `string` | No | Only return messages posted before this Slack timestamp, e.g. 1610000000.000000. Defaults to now. A message with exactly this timestamp is excluded unless Inclusive is true. |
| `inclusive` | `boolean` | No | Set to true to include messages whose timestamp equals Oldest or Latest, e.g. to fetch one known message. Ignored unless one of them is set. Default: false. |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "slack_bot",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "slack_bot-list-messages",
  arguments: {
    conversation: "Channel",
    limit: 10,
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "slack_bot-list-messages",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    slack_bot: { authProvisionId: "apn_xxxxxxx" },
    conversation: "Channel",
    limit: 10,
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "slack_bot-list-messages",
    "configured_props": {
      "slack_bot": { "authProvisionId": "apn_xxxxxxx" },
      "conversation": "Channel",
      "limit": 10
    }
  }'
```

---

- App: https://pipedream.com/apps/slack-bot.md · All apps: https://pipedream.com/apps
