telegram-bot-simple icon indicating copy to clipboard operation
telegram-bot-simple copied to clipboard

SendMessage hangs indefinitely on some sendMessageText field values

Open tim2CF opened this issue 1 year ago • 1 comments

Example. No success or error returned, no exception is thrown, no logs produced, "SENT!" line is never reached. Basically everything just hangs on Tele.sendMessage line. Telegram Bot API might not support nested HTML tags, but in this case I expect some sort of exception. Current behaviour might be caused by the way how exceptions are handled inside servant client, but I don't know how to debug or fix it properly.

import qualified Telegram.Bot.API as Tele
import qualified Telegram.Bot.Simple as Tele
import qualified Telegram.Bot.Simple.Debug as Tele

sendTeleMsg :: Tele.BotM ()
sendTeleMsg = do
  putStrLn ("SENDING" :: Text)
  response <-
    Tele.liftClientM
      $ Tele.sendMessage
        Tele.SendMessageRequest
          { Tele.sendMessageChatId = Tele.SomeChatUsername chat,
            Tele.sendMessageMessageThreadId = Nothing,
            Tele.sendMessageText =
              "<a href=\"https://upload.wikimedia.org/wikipedia/commons/thumb/1/1c/Haskell-Logo.svg/2560px-Haskell-Logo.svg.png\"><span>[image]</span></a>",
            Tele.sendMessageParseMode = Just Tele.HTML,
            Tele.sendMessageEntities = Nothing,
            Tele.sendMessageDisableWebPagePreview = Just True,
            Tele.sendMessageDisableNotification = Just True,
            Tele.sendMessageProtectContent = Nothing,
            Tele.sendMessageReplyToMessageId = Nothing,
            Tele.sendMessageAllowSendingWithoutReply = Nothing,
            Tele.sendMessageReplyMarkup = Nothing
          }
  putStrLn ("SENT!" :: Text)

tim2CF avatar Dec 27 '23 03:12 tim2CF

I was manage to reach some limited success with decreasing Manager timeout. For example this env setup works ok, and gives timeout exception in case Telegram API does not reply (for whatever reason):

  man <-
    Http.newManager
      $ Http.tlsManagerSettings
        { Http.managerResponseTimeout = Http.responseTimeoutMicro 20_000_000
        }
  pusher <-
    Tele.startBotAsync teleBot
      . Servant.mkClientEnv man
      . Tele.botBaseUrl
      . Tele.Token
      $ token

However, if I increase timeout just a bit more to ~ 25.9 seconds, it behaves badly again, and never throw timeout exception. Might be this strange behavioural shift related to this line somehow? Any ideas for a good fix?

https://github.com/fizruk/telegram-bot-simple/blob/1f0a63680971fafcdcd5a789eed3fe64eb52f2d9/telegram-bot-simple/src/Telegram/Bot/Simple/BotApp/Internal.hs#L142

tim2CF avatar Dec 30 '23 02:12 tim2CF