Loading

Get Channel ID and Thread ts in Agentforce Agent from Slack

Julkaisupäivä: Nov 13, 2026
Kuvaus

When a user mentions an Agentforce agent in a Slack channel or thread, Slack sends the channel ID and thread ts to the agent as session variables. Salesforce ignores the values sent from Slack unless the agent declares the variables. This article explains how to declare the variables in an Agentforce agent and use them in Flow or Apex actions.

Ratkaisu

This article explains how an Agentforce agent can read the ID of the Slack channel and the ts (timestamp) of the Slack thread where a user mentioned the agent while the agent is running. The agent can read the values that Slack sends after the variables are declared in the agent.

Session variables that Slack sends to Agentforce

When a user mentions the agent in a Slack channel, Slack starts the session with the following variables.

  • slack_channel: The channel ID, for example C0123ABCD.
  • slack_thread_ts: The ts of the thread where the agent replies. For a mention in a top-level message that does not belong to a thread, the value is the ts of that message. For a mention inside a thread, the value is the ts of the thread root message. In both cases, the value can be passed as thread_ts to chat.postMessage.

Slack sends the same variables with every later message in the same session. The values stay correct when the agent is mentioned again in the same thread.

Prerequisites

The following conditions apply when you declare the variables in the Agentforce agent.

  • Use the exact names slack_channel and slack_thread_ts.
  • Set visibility: "External" on each variable.

Steps

Follow these steps to declare the variables in the agent and pass the values to actions.

  1. Add slack_channel and slack_thread_ts to the variable definitions of the agent. The following code is an example that declares both variables as External.
    `variables:
        slack_channel: mutable string
            label: "Slack Channel ID"
            description: "The Slack channel the user is talking to the agent in."
            visibility: "External"
        slack_thread_ts: mutable string
            label: "Slack Thread TS"
            description: "The ts of the Slack thread the agent is replying in."
            visibility: "External"`
    Because the variable names match exactly and the visibility is External, the agent can receive the values that Slack sends.
  2. Bind the variables directly to the inputs of the Flow or Apex actions that need the values. For example, specify with slack_channel = @variables.slack_channel.
  3. Do not specify "..." for these inputs. With "...", the planner infers and fills in the value, so an incorrect value might be passed.
Knowledge-artikkelin numero

005466770

 
Ladataan
Salesforce Help | Article