diff options
| author | Ben Sima <ben@bensima.com> | 2025-12-12 14:39:48 -0500 |
|---|---|---|
| committer | Ben Sima <ben@bensima.com> | 2025-12-12 14:39:48 -0500 |
| commit | f95dea670f2c528acd272ab5251457a77a1adb82 (patch) | |
| tree | e382b22a95dceb4cd54e14ad038535d6b593da95 /Omni/Agent/Telegram.hs | |
| parent | ec6dae5542a2b1eeb7e4a3e07f60b228e2672a93 (diff) | |
Fix telegram bot timeout and sendMessage 400 error
- Set response timeout to polling timeout + 10s for long polling
- Remove Markdown parse_mode to avoid 400 errors on special chars
Diffstat (limited to 'Omni/Agent/Telegram.hs')
| -rw-r--r-- | Omni/Agent/Telegram.hs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Omni/Agent/Telegram.hs b/Omni/Agent/Telegram.hs index 8e4591e..e089945 100644 --- a/Omni/Agent/Telegram.hs +++ b/Omni/Agent/Telegram.hs @@ -49,6 +49,7 @@ import Data.Aeson ((.!=), (.:), (.:?), (.=)) import qualified Data.Aeson as Aeson import qualified Data.Aeson.KeyMap as KeyMap import qualified Data.Text as Text +import qualified Network.HTTP.Client as HTTPClient import qualified Network.HTTP.Simple as HTTP import qualified Omni.Agent.Engine as Engine import qualified Omni.Agent.Memory as Memory @@ -242,10 +243,12 @@ getUpdates cfg offset = do "timeout" .= tgPollingTimeout cfg, "allowed_updates" .= (["message"] :: [Text]) ] + timeoutMicros = (tgPollingTimeout cfg + 10) * 1000000 req = HTTP.setRequestMethod "POST" <| HTTP.setRequestHeader "Content-Type" ["application/json"] <| HTTP.setRequestBodyLBS (Aeson.encode body) + <| HTTP.setRequestResponseTimeout (HTTPClient.responseTimeoutMicro timeoutMicros) <| req0 result <- try (HTTP.httpLBS req) case result of @@ -277,8 +280,7 @@ sendMessage cfg chatId text = do let body = Aeson.object [ "chat_id" .= chatId, - "text" .= text, - "parse_mode" .= ("Markdown" :: Text) + "text" .= text ] req = HTTP.setRequestMethod "POST" |
