fizruk / telegram-bot-simple

Easy to use library for building Telegram bots in Haskell.
BSD 3-Clause "New" or "Revised" License
107 stars 54 forks source link

ExceptionInLinkedThread: Missing field in record construction sendMessageMessageEffectId #188

Closed thelissimus closed 5 months ago

thelissimus commented 5 months ago

The code:

{-# LANGUAGE OverloadedStrings #-}

module Assistant (module Assistant) where

import Data.Kind (Type)
import Data.Text (Text)

import Telegram.Bot.API (Token (..), Update, defaultTelegramClientEnv)
import Telegram.Bot.Simple (BotApp (..), startBot_, (<#))
import Telegram.Bot.Simple qualified as TBS
import Telegram.Bot.Simple.Debug (traceBotDefault)
import Telegram.Bot.Simple.UpdateParser (updateMessageText)

type Model :: Type
type Model = ()

type Action :: Type
data Action
  = ActionHoogleSearch Text
  deriving stock (Show)

assistantBot :: BotApp Model Action
assistantBot =
  BotApp
    { botInitialModel = ()
    , botAction = updateToAction
    , botHandler = handleAction
    , botJobs = []
    }

updateToAction :: Update -> Model -> Maybe Action
updateToAction update _ = ActionHoogleSearch <$> updateMessageText update

handleAction :: Action -> Model -> TBS.Eff Action Model
handleAction action model = case action of
  ActionHoogleSearch str ->
    model <# do
      -- todo
      pure str

run :: IO ()
run = do
  env <- defaultTelegramClientEnv (Token "<hidden>")
  startBot_ (traceBotDefault assistantBot) env

Is failing with the following error:

ExceptionInLinkedThread (ThreadId 11) src/Telegram/Bot/Simple/Reply.hs:(61,64)-(74,3): Missing field in record construction sendMessageMessageEffectId

Tried scraping all of my code off and copy-pasting examples from the repository and the lambdaconf-2018-workshop. No use. Probably some new feature introduced the bug.

gltronred commented 5 months ago

It seems that telegram-bot-api has updated. My code failed with the same error message with 7.4 version, but worked with 7.3.1.

So, a workaround is to add to cabal.project (or equivalent) the following line:

constraints: telegram-bot-api==7.3.1