summaryrefslogtreecommitdiff
path: root/Omni
diff options
context:
space:
mode:
authorBen Sima <ben@bensima.com>2025-12-13 12:11:21 -0500
committerBen Sima <ben@bensima.com>2025-12-13 12:11:21 -0500
commite99cd405657ba3192c8ef6d46f5e1901b3916522 (patch)
tree44a44a02cc4241d8886981eeff64686089674394 /Omni
parent3d719bf5cd279bc9a900f375bc1bf3625e03a9a9 (diff)
Fix Telegram streaming markdown parse errors
Amp-Thread-ID: https://ampcode.com/threads/T-019b1894-b431-777d-aba3-65a51e720ef2 Co-authored-by: Amp <amp@ampcode.com>
Diffstat (limited to 'Omni')
-rw-r--r--Omni/Agent/Telegram.hs28
1 files changed, 24 insertions, 4 deletions
diff --git a/Omni/Agent/Telegram.hs b/Omni/Agent/Telegram.hs
index 091ad11..0089472 100644
--- a/Omni/Agent/Telegram.hs
+++ b/Omni/Agent/Telegram.hs
@@ -72,6 +72,7 @@ import qualified Data.Aeson.KeyMap as KeyMap
import qualified Data.ByteString.Lazy as BL
import Data.IORef (modifyIORef, newIORef, readIORef, writeIORef)
import qualified Data.Text as Text
+import qualified Data.Text.Encoding as TE
import Data.Time (UTCTime (..), getCurrentTime, utcToLocalTime)
import Data.Time.Format (defaultTimeLocale, formatTime)
import Data.Time.LocalTime (getCurrentTimeZone)
@@ -149,6 +150,20 @@ telegramSystemPrompt =
"",
"prioritize esoteric interpretations of literature, art, and philosophy.",
"",
+ "## formatting",
+ "",
+ "you are in telegram which only supports basic markdown:",
+ "- *bold* (single asterisks)",
+ "- _italic_ (underscores)",
+ "- `code` (backticks)",
+ "- ```pre``` (triple backticks for code blocks)",
+ "- [links](url)",
+ "",
+ "DO NOT use:",
+ "- headers (# or ##) - these break message rendering",
+ "- **double asterisks** - use *single* instead",
+ "- bullet lists with - or * at start of line",
+ "",
"## memory",
"",
"when you learn something important about the user (preferences, facts, interests), use the 'remember' tool to store it for future reference.",
@@ -275,8 +290,7 @@ editMessage cfg chatId messageId text = do
Aeson.object
[ "chat_id" .= chatId,
"message_id" .= messageId,
- "text" .= text,
- "parse_mode" .= ("Markdown" :: Text)
+ "text" .= text
]
req0 <- HTTP.parseRequest url
let req =
@@ -284,8 +298,14 @@ editMessage cfg chatId messageId text = do
<| HTTP.setRequestHeader "Content-Type" ["application/json"]
<| HTTP.setRequestBodyLBS (Aeson.encode body)
<| req0
- _ <- try @SomeException (HTTP.httpLBS req)
- pure ()
+ result <- try @SomeException (HTTP.httpLBS req)
+ case result of
+ Left err -> putText <| "Edit message failed: " <> tshow err
+ Right response -> do
+ let status = HTTP.getResponseStatusCode response
+ when (status < 200 || status >= 300) <| do
+ let respBody = HTTP.getResponseBody response
+ putText <| "Edit message HTTP " <> tshow status <> ": " <> TE.decodeUtf8 (BL.toStrict respBody)
sendTypingAction :: Types.TelegramConfig -> Int -> IO ()
sendTypingAction cfg chatId = do