{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
module Proof.Assistant.Response where
import Data.ByteString (ByteString)
import Data.Text.Encoding (decodeUtf8)
import Telegram.Bot.API
(ChatId, MessageId, ParseMode (..), SendMessageRequest (..), SomeChatId (..))
import Proof.Assistant.Request
data InterpreterResponse = InterpreterResponse
{ InterpreterResponse -> ChatId
interpreterResponseTelegramChatId :: !ChatId
, InterpreterResponse -> MessageId
interpreterResponseTelegramMessageId :: !MessageId
, InterpreterResponse -> ByteString
interpreterResponseResponse :: !ByteString
}
toSendMessageRequest :: Bool -> InterpreterResponse -> SendMessageRequest
toSendMessageRequest :: Bool -> InterpreterResponse -> SendMessageRequest
toSendMessageRequest Bool
isMonospace InterpreterResponse{ByteString
ChatId
MessageId
interpreterResponseResponse :: ByteString
interpreterResponseTelegramMessageId :: MessageId
interpreterResponseTelegramChatId :: ChatId
interpreterResponseResponse :: InterpreterResponse -> ByteString
interpreterResponseTelegramMessageId :: InterpreterResponse -> MessageId
interpreterResponseTelegramChatId :: InterpreterResponse -> ChatId
..} = SendMessageRequest :: SomeChatId
-> Text
-> Maybe ParseMode
-> Maybe [MessageEntity]
-> Maybe Bool
-> Maybe Bool
-> Maybe Bool
-> Maybe MessageId
-> Maybe Bool
-> Maybe SomeReplyMarkup
-> SendMessageRequest
SendMessageRequest
{ sendMessageChatId :: SomeChatId
sendMessageChatId = ChatId -> SomeChatId
SomeChatId ChatId
interpreterResponseTelegramChatId
, sendMessageText :: Text
sendMessageText
= if Bool
isMonospace
then Text
"```\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ByteString -> Text
decodeUtf8 ByteString
interpreterResponseResponse Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n```\n"
else ByteString -> Text
decodeUtf8 ByteString
interpreterResponseResponse Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n"
, sendMessageParseMode :: Maybe ParseMode
sendMessageParseMode = if Bool
isMonospace then ParseMode -> Maybe ParseMode
forall a. a -> Maybe a
Just ParseMode
MarkdownV2 else Maybe ParseMode
forall a. Maybe a
Nothing
, sendMessageEntities :: Maybe [MessageEntity]
sendMessageEntities = Maybe [MessageEntity]
forall a. Maybe a
Nothing
, sendMessageDisableWebPagePreview :: Maybe Bool
sendMessageDisableWebPagePreview = Maybe Bool
forall a. Maybe a
Nothing
, sendMessageDisableNotification :: Maybe Bool
sendMessageDisableNotification = Maybe Bool
forall a. Maybe a
Nothing
, sendMessageProtectContent :: Maybe Bool
sendMessageProtectContent = Maybe Bool
forall a. Maybe a
Nothing
, sendMessageReplyToMessageId :: Maybe MessageId
sendMessageReplyToMessageId = MessageId -> Maybe MessageId
forall a. a -> Maybe a
Just MessageId
interpreterResponseTelegramMessageId
, sendMessageAllowSendingWithoutReply :: Maybe Bool
sendMessageAllowSendingWithoutReply = Maybe Bool
forall a. Maybe a
Nothing
, sendMessageReplyMarkup :: Maybe SomeReplyMarkup
sendMessageReplyMarkup = Maybe SomeReplyMarkup
forall a. Maybe a
Nothing
}
makeTelegramResponse :: InterpreterRequest -> ByteString -> InterpreterResponse
makeTelegramResponse :: InterpreterRequest -> ByteString -> InterpreterResponse
makeTelegramResponse InterpreterRequest{ByteString
ChatId
MessageId
interpreterRequestMessage :: InterpreterRequest -> ByteString
interpreterRequestTelegramMessageId :: InterpreterRequest -> MessageId
interpreterRequestTelegramChatId :: InterpreterRequest -> ChatId
interpreterRequestMessage :: ByteString
interpreterRequestTelegramMessageId :: MessageId
interpreterRequestTelegramChatId :: ChatId
..} ByteString
response =
InterpreterResponse :: ChatId -> MessageId -> ByteString -> InterpreterResponse
InterpreterResponse
{ interpreterResponseTelegramChatId :: ChatId
interpreterResponseTelegramChatId = ChatId
interpreterRequestTelegramChatId
, interpreterResponseTelegramMessageId :: MessageId
interpreterResponseTelegramMessageId = MessageId
interpreterRequestTelegramMessageId
, interpreterResponseResponse :: ByteString
interpreterResponseResponse = ByteString
response
}