summaryrefslogtreecommitdiff
path: root/Omni/Agent/Telegram/Types.hs
diff options
context:
space:
mode:
authorBen Sima <ben@bensima.com>2025-12-13 15:03:11 -0500
committerBen Sima <ben@bensima.com>2025-12-13 15:03:11 -0500
commitc35ba7d248642386544a776f86815e01630eb50d (patch)
tree4624289fd86f0250179322d1581e16d0defd9d90 /Omni/Agent/Telegram/Types.hs
parent38c4ea7fcb86ea78448e7097fcd8689d37d78399 (diff)
feat: add Telegram topic (message_thread_id) support
- Parse message_thread_id from incoming messages - Include thread_id in sendMessage API calls - Pass thread_id through message queue system - Replies now go to the correct topic in supergroups
Diffstat (limited to 'Omni/Agent/Telegram/Types.hs')
-rw-r--r--Omni/Agent/Telegram/Types.hs10
1 files changed, 9 insertions, 1 deletions
diff --git a/Omni/Agent/Telegram/Types.hs b/Omni/Agent/Telegram/Types.hs
index aaea65b..7a91df3 100644
--- a/Omni/Agent/Telegram/Types.hs
+++ b/Omni/Agent/Telegram/Types.hs
@@ -94,7 +94,8 @@ test =
tmDocument = Nothing,
tmPhoto = Nothing,
tmVoice = Nothing,
- tmReplyTo = Nothing
+ tmReplyTo = Nothing,
+ tmThreadId = Nothing
}
case Aeson.decode (Aeson.encode msg) of
Nothing -> Test.assertFailure "Failed to decode TelegramMessage"
@@ -355,6 +356,7 @@ data TelegramMessage = TelegramMessage
{ tmUpdateId :: Int,
tmChatId :: Int,
tmChatType :: ChatType,
+ tmThreadId :: Maybe Int,
tmUserId :: Int,
tmUserFirstName :: Text,
tmUserLastName :: Maybe Text,
@@ -372,6 +374,7 @@ instance Aeson.ToJSON TelegramMessage where
[ "update_id" .= tmUpdateId m,
"chat_id" .= tmChatId m,
"chat_type" .= tmChatType m,
+ "thread_id" .= tmThreadId m,
"user_id" .= tmUserId m,
"user_first_name" .= tmUserFirstName m,
"user_last_name" .= tmUserLastName m,
@@ -388,6 +391,7 @@ instance Aeson.FromJSON TelegramMessage where
(TelegramMessage </ (v .: "update_id"))
<*> (v .: "chat_id")
<*> (v .:? "chat_type" .!= Private)
+ <*> (v .:? "thread_id")
<*> (v .: "user_id")
<*> (v .: "user_first_name")
<*> (v .:? "user_last_name")
@@ -426,6 +430,9 @@ parseUpdate val = do
Just (Aeson.String "supergroup") -> Supergroup
Just (Aeson.String "channel") -> Channel
_ -> Private
+ let threadId = case KeyMap.lookup "message_thread_id" msgObj of
+ Just (Aeson.Number n) -> Just (round n)
+ _ -> Nothing
Aeson.Object fromObj <- KeyMap.lookup "from" msgObj
userId <- case KeyMap.lookup "id" fromObj of
Just (Aeson.Number n) -> Just (round n)
@@ -461,6 +468,7 @@ parseUpdate val = do
{ tmUpdateId = updateId,
tmChatId = chatId,
tmChatType = chatType,
+ tmThreadId = threadId,
tmUserId = userId,
tmUserFirstName = firstName,
tmUserLastName = lastName,