The habit package

[Tags:bsd3, library, program]

Framework for building text message bots for popular platforms


[Skip to Readme]

Properties

Versions 0.2.1.2, 0.2.2.0
Dependencies base (==4.9.*), containers (>=0.5.7.1 && <0.6), cryptonite (==0.21.*), habit (>=0.2.2.0 && <0.3), http-client (>=0.4.31.2 && <0.5), http-client-tls (>=0.2.4.1 && <0.3), monad-control (>=1.0.1.0 && <1.1), monad-logger (>=0.3.20.1 && <0.4), persistent (==2.6.*), persistent-mysql (==2.6.*), persistent-postgresql (==2.6.*), persistent-sqlite (==2.6.*), persistent-template (>=2.5.1.6 && <2.6), pipes (>=4.1.9 && <4.2), resourcet (>=1.1.8.1 && <1.2), telegram-api (>=0.5.0.1 && <0.6), text (>=1.2.2.1 && <1.3), transformers (>=0.5.2.0 && <0.6), transformers-base (>=0.4.4 && <0.5) [details]
License BSD3
Copyright Alexander Krupenkin
Author Alexander Krupenkin
Maintainer mail@akru.me
Stability Unknown
Category Web
Home page https://github.com/airalab/habit#readme
Source repository head: git clone https://github.com/airalab/habit
Uploaded Wed Jan 25 23:50:08 UTC 2017 by akru
Distributions NixOS:0.2.2.0
Downloads 38 total (8 in the last 30 days)
Votes
0 []
Status Docs available [build log]
Last success reported on 2017-01-26 [all 1 reports]

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for habit

Readme for habit-0.2.2.0

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.