diff options
Diffstat (limited to 'Omni/Agent')
| -rw-r--r-- | Omni/Agent/Telegram.hs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Omni/Agent/Telegram.hs b/Omni/Agent/Telegram.hs index 2bf7aed..57420a4 100644 --- a/Omni/Agent/Telegram.hs +++ b/Omni/Agent/Telegram.hs @@ -116,6 +116,13 @@ import qualified Omni.Test as Test import System.Environment (lookupEnv) import Text.Printf (printf) +safePutText :: Text -> IO () +safePutText msg = do + result <- try @SomeException (putText msg) + case result of + Left _ -> putText "[log encoding error - message contained unrepresentable characters]" + Right () -> pure () + defaultTelegramConfig :: Text -> [Int] -> Maybe Text -> Text -> Types.TelegramConfig defaultTelegramConfig = Types.defaultTelegramConfig @@ -623,7 +630,7 @@ runTelegramBot tgConfig provider = do handleBotAddedToGroup tgConfig addedEvent Nothing -> case Types.parseUpdate rawUpdate of Just msg -> do - putText <| "Received message from " <> Types.tmUserFirstName msg <> " in chat " <> tshow (Types.tmChatId msg) <> " (type: " <> tshow (Types.tmChatType msg) <> "): " <> Text.take 50 (Types.tmText msg) + safePutText <| "Received message from " <> Types.tmUserFirstName msg <> " in chat " <> tshow (Types.tmChatId msg) <> " (type: " <> tshow (Types.tmChatType msg) <> "): " <> Text.take 50 (Types.tmText msg) atomically (writeTVar offsetVar (Types.tmUpdateId msg + 1)) IncomingQueue.enqueueIncoming incomingQueues IncomingQueue.defaultBatchWindowSeconds msg Nothing -> do @@ -1329,7 +1336,7 @@ processEngagedMessage tgConfig provider engineCfg msg uid userName chatId userMe let baseResponse = Engine.resultFinalMessage agentResult response = baseResponse <> traceLink threadId = Types.tmThreadId msg - putText <| "Response text: " <> Text.take 200 response + safePutText <| "Response text: " <> Text.take 200 response if isGroup then void <| Memory.saveGroupMessage chatId threadId Memory.AssistantRole "Ava" response |
