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:
thread_id is not persisted in the messages table — src/db.ts has no thread_id column
- Callers never pass
threadId — src/index.ts:297, :712, :719 all call channel.sendMessage(jid, text) without it
- 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
- Add
thread_id TEXT column to the messages table in src/db.ts
- Store
thread_id when inserting messages (it's already on the NewMessage type at src/types.ts:54)
- When sending a reply, look up the most recent
thread_id for the chat JID and pass it through
- Update
Channel.sendMessage signature to accept an optional threadId
- 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.
Problem
When a message arrives in a Telegram thread (forum topic), the
thread_idis captured by the Telegram channel (src/channels/telegram.ts:158,226) andTelegramChannel.sendMessage()supports athreadIdparameter (line 368). However, the reply is sent without thread context because:thread_idis not persisted in themessagestable —src/db.tshas nothread_idcolumnthreadId—src/index.ts:297,:712,:719all callchannel.sendMessage(jid, text)without itChannelinterface insrc/types.tsdefinessendMessage(jid: string, text: string)without athreadIdparameter (even thoughTelegramChannelaccepts 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
thread_id TEXTcolumn to themessagestable insrc/db.tsthread_idwhen inserting messages (it's already on theNewMessagetype atsrc/types.ts:54)thread_idfor the chat JID and pass it throughChannel.sendMessagesignature to accept an optionalthreadIdsendMessagecall sites insrc/index.tsto pass the thread contextThis affects the core message flow, so it should be fixed upstream rather than patched locally.