Commit 7fcea311 authored by Nicolas Lenz's avatar Nicolas Lenz

Hash message for id

parent c608c152
......@@ -7,6 +7,8 @@ import Data.Maybe
import Control.Applicative
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Encoding as T
import Data.ByteArray (convert)
import Data.Char
import qualified Telegram.Bot.API as Telegram
import Telegram.Bot.Simple
......@@ -14,6 +16,7 @@ import Telegram.Bot.Simple.Debug
import Telegram.Bot.Simple.UpdateParser
import Telegram.Bot.API.InlineMode
import Control.Monad.Reader
import Crypto.Hash
import Mock (styles, mockRandom)
import Mock.Help (styleHelp)
......@@ -82,13 +85,16 @@ handleAction (Reply message) model = model <# do
replyText message
pure NoAction
handleAction (InlineReply msgs) model = model <# do
let results = map (\(title, message) -> Telegram.InlineQueryResultArticle "article" (title <> "\n" <> message) title (Telegram.InputTextMessageContent message) message) msgs
let results = map (\(title, message) -> Telegram.InlineQueryResultArticle "article" (getInlineReplyId title message) title (Telegram.InputTextMessageContent message) message) msgs
answerInlineQuery results
pure NoAction
handleAction SendHelp model = model <# do
reply $ (toReplyMessage help) {replyMessageParseMode = Just Telegram.Markdown, replyMessageDisableWebPagePreview = Just True}
pure NoAction
getInlineReplyId :: Text -> Text -> Text
getInlineReplyId title message = T.decodeUtf8 $ convert $ hashWith Keccak_512 $ T.encodeUtf8 $ title <> "\n" <> message
-- | Run bot with a given 'Telegram.Token'.
run :: Text -> IO ()
run token = do
......
......@@ -4,7 +4,7 @@ cabal-version: 2.2
--
-- see: https://github.com/sol/hpack
--
-- hash: 3d6ddc0a63909e16d9138d7792b39eb08b1b03951aa55c0e5af71a058d7549e4
-- hash: 7a3dff0fdd818b0e6a8697eb3807dd245287be140a833da3f3031246b85f903b
name: mock-telegram-bot
version: 0.2.0
......@@ -33,6 +33,8 @@ executable mock-telegram-bot
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base
, cryptonite
, memory
, mock
, mtl
, telegram-bot-simple
......
......@@ -19,6 +19,8 @@ dependencies:
- mock
- text
- mtl
- cryptonite
- memory
executables:
mock-telegram-bot:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment