microsoft / microsoft/Agents

Slack channel: SDK replying as a new message instead of replying in Thread

Open
#335 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeSpec
Stars
1.1k
Forks
340
Avg merge
3d 13h
Merged PRs (30d)
12

Description

Is your feature request related to a problem? Please describe.
I'm using below method reply to conversation.
await context.send_activity("Hello!")

Teams Channel: When I send a message tagging the bot, it is replying in thread. (which I want)
Slack Channel: When I send a message tagging the bot, it is replying as a new message. (which I do not want)

Describe the solution you'd like
For Slack, I would like to send message in Thread instead of sending a new message.

Describe alternatives you've considered
Manually making an API call to Slack to reply in thread.

`async def send_reply_in_thread(context: TurnContext, message: str) -> None:
"""
Send a reply in a Slack thread instead of as a new message.
Falls back to normal send_activity for non-Slack channels (with retry).

Args:
    context: The turn context
    message: The message to send
"""
channel_data = context.activity.channel_data or {}
slack_message = (
    channel_data.get("SlackMessage")
    if channel_data and isinstance(channel_data, dict)
    else None
)

if slack_message and isinstance(slack_message, dict):
    event = slack_message.get("event")
    api_token = (
        channel_data.get("ApiToken") if isinstance(channel_data, dict) else None
    )
    if event and api_token:
        thread_ts = event.get("thread_ts") or event.get("ts")
        channel_id = event.get("channel")
        if thread_ts and channel_id:
            try:
                async with aiohttp.ClientSession() as session:
                    async with session.post(
                        "https://slack.com/api/chat.postMessage",
                        headers={
                            "Authorization": f"Bearer {api_token}",
                            "Content-Type": "application/json",
                        },
                        json={
                            "channel": channel_id,
                            "thread_ts": thread_ts,
                            "text": message,
                        },
                    ) as resp:
                        result = await resp.json()
                        logger.info(f"Slack API response: {result}")
                        if not result.get("ok"):
                            logger.error(f"Slack API error: {result.get('error')}")
                            await context.send_activity("Hello!")
                return
            except Exception as e:
                logger.error(f"Error using Slack Web API: {e}", exc_info=True)
                await context.send_activity("Hello!")
else:
    logger.info("Sending message normally, not in Slack thread")
    await context.send_activity("Hello!")`

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing context.send_activity through the SDK's Slack channel handling and compare how the incoming Slack event exposes thread information. Done means a Slack message tagging the bot is sent in its existing thread rather than as a new message, while non-Slack channels retain their current behavior; verify this with a Slack channel scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.