module Proof.Assistant.Request where
import Data.ByteString (ByteString)
import Data.Text.Encoding (encodeUtf8)
import Telegram.Bot.API
import Telegram.Bot.Simple.UpdateParser
data InterpreterRequest = InterpreterRequest
{ InterpreterRequest -> ChatId
interpreterRequestTelegramChatId :: !ChatId
, InterpreterRequest -> MessageId
interpreterRequestTelegramMessageId :: !MessageId
, InterpreterRequest -> ByteString
interpreterRequestMessage :: !ByteString
}
updateToRequest :: Update -> Maybe InterpreterRequest
updateToRequest :: Update -> Maybe InterpreterRequest
updateToRequest Update
upd = ChatId -> MessageId -> ByteString -> InterpreterRequest
InterpreterRequest
(ChatId -> MessageId -> ByteString -> InterpreterRequest)
-> Maybe ChatId
-> Maybe (MessageId -> ByteString -> InterpreterRequest)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Update -> Maybe ChatId
updateChatId Update
upd
Maybe (MessageId -> ByteString -> InterpreterRequest)
-> Maybe MessageId -> Maybe (ByteString -> InterpreterRequest)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((Message -> MessageId) -> Maybe Message -> Maybe MessageId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Message -> MessageId
messageMessageId (Maybe Message -> Maybe MessageId)
-> (Update -> Maybe Message) -> Update -> Maybe MessageId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Update -> Maybe Message
extractUpdateMessage) Update
upd
Maybe (ByteString -> InterpreterRequest)
-> Maybe ByteString -> Maybe InterpreterRequest
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Text -> ByteString
encodeUtf8 (Text -> ByteString) -> Maybe Text -> Maybe ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Update -> Maybe Text
updateMessageText Update
upd)