packages feed

telegram-bot-0.5.4.0: examples/Hello.hs

{-# LANGUAGE OverloadedLists #-}
module Main where

import Data.Text (Text, pack)
import Data.Monoid ((<>))
import Web.Telegram.Bot

type Name    = Text
type Surname = Text
type Age     = Int

hello :: Name -> Surname -> Age -> BotMessage
hello name surname age =
    toMessage $ "Hello, " <> name <> " " <> surname <> "!\n"
             <> "You lost " <> (pack $ show age) <> " years =)"

helloStory :: Story MyBot
helloStory _ = hello <$> question "How your name?"
                     <*> question "How your surname?"
                     <*> question "How old are you?"

helpMessage :: Text
helpMessage = "Hello, I'm hello bot!"

data MyBot = MyBot
instance BotConfig MyBot where
    authToken = const $ Token "bot..."

main :: IO ()
main = runBot MyBot $ do
            storyBot helpMessage [("/hello", helloStory)]