@hackage habit0.2.2.0

Haskell message bot framework

Haskell Bot it :: Message bot framework

Build Status Build status Hackage Hackage Dependencies Haskell Programming Language BSD3 License

Install

$ git clone https://github.com/airalab/habit && cd habit
$ stack setup
$ stack ghci

Run your story

The Story is an abstraction about sparsed data getted from user though dialogue.

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

As you see the story handler hello is apply though the questions to user responses.

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

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

To run the Story simple pass it to storyBot as value of mapping between command an story. APIToken type class defines token for given platform, e.g. Telegram platform.

instance APIToken Telegram where
    apiToken = "bot..."

main :: IO ()
main = runBot myBot
  where myBot :: Bot Telegram ()
        myBot = storyBot helpMsg [("/hello", helloStory)]

Full example text.