Skip to content

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

@rajashekarNampelli

Description

@rajashekarNampelli

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!")`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions