habit: Haskell message bot framework

[ bsd3, library, program, web ] [ Propose Tags ] [ Report a vulnerability ]

Framework for building text message bots for popular platforms


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.2.1.2, 0.2.2.0
Dependencies base (>=4.9 && <4.10), containers (>=0.5.7.1 && <0.6), cryptonite (>=0.21 && <0.22), 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 && <2.7), persistent-mysql (>=2.6 && <2.7), persistent-postgresql (>=2.6 && <2.7), persistent-sqlite (>=2.6 && <2.7), 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 BSD-3-Clause
Copyright Alexander Krupenkin
Author Alexander Krupenkin
Maintainer mail@akru.me
Category Web
Home page https://github.com/airalab/habit#readme
Source repo head: git clone https://github.com/airalab/habit
Uploaded by akru at 2017-01-25T23:50:08Z
Distributions
Executables hello-bot
Downloads 1466 total (6 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-01-26 [all 1 reports]

Readme for habit-0.2.2.0

[back to package description]

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.