Skip to content

Telegram thread/topic replies lose thread context #1699

@Davidsod

Description

@Davidsod

Problem

When a message arrives in a Telegram thread (forum topic), the thread_id is captured by the Telegram channel (src/channels/telegram.ts:158,226) and TelegramChannel.sendMessage() supports a threadId parameter (line 368). However, the reply is sent without thread context because:

  1. thread_id is not persisted in the messages tablesrc/db.ts has no thread_id column
  2. Callers never pass threadIdsrc/index.ts:297, :712, :719 all call channel.sendMessage(jid, text) without it
  3. The Channel interface in src/types.ts defines sendMessage(jid: string, text: string) without a threadId parameter (even though TelegramChannel accepts one as an optional third arg)

Result

Bot replies land in the main chat instead of the thread/topic where the user sent the message.

Suggested Fix

  1. Add thread_id TEXT column to the messages table in src/db.ts
  2. Store thread_id when inserting messages (it's already on the NewMessage type at src/types.ts:54)
  3. When sending a reply, look up the most recent thread_id for the chat JID and pass it through
  4. Update Channel.sendMessage signature to accept an optional threadId
  5. Update all sendMessage call sites in src/index.ts to pass the thread context

This affects the core message flow, so it should be fixed upstream rather than patched locally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions