Code Monkey home page Code Monkey logo

gramhopper's Introduction

gramhopper

image image image

A bot platform for automatic responses based on various triggers.

Click to view this demo's configuration
triggers:
  - name: cat
    type: text.has_exact_word
    word:
      - Meow
      - meow
  - name: duck
    type: text.has_exact_word
    word: Quack
responses:
  - name: found_dog
    type: preset.reply
    preset_response:
      - Hey, here's a dog!
rules:
  # Identifies a cat (a global "cat" trigger) and sends "Hello cat!" (an inline response).
  - trigger: cat
    response:
      type: preset.message
      preset_response: Hello cat!
  # Identifies a dog (an inline trigger) and replies "Hey, here's a dog!"
  # (a global "found_dog" response).
  - trigger:
      type: text.has_substring
      substring:
        - Woof
        - woof
        - Ruff
        - ruff
    response: found_dog
  # Identifies an animal sound (an inline trigger) and replies 
  # 'I hear "(the animal sound)"' (an inline response), with a 30% probability.
  - trigger:
      type: text.regexp
      pattern: ^(Quack|Meow|Woof|Moo)$
    response:
      type: match.message
      template: I hear "{0}"
    probability: 0.3
  # Identifies 5 occurrences in 60 seconds of a duck sound (an inline event_streak
  # trigger that uses a global "duck" trigger") and replies "Shut up duck!".
  - trigger:
      type: event_streak
      counting_event_trigger: duck
      streak_timeout_sec: 60
      event_count: 5
    response:
      type: preset.message
      preset_response: Shut up duck!

Setup and Configuration

Follow this tutorial to setup a bot and configure gramhopper.

Install and Run

To run gramhopper, just run:

From installed package

pip install gramhopper
gramhopper
Specify configuration file
gramhopper --config=/path/to/rules_file.yml

From docker image

docker pull orbin/gramhopper:latest
docker run -it -v /your/configuration/dir:/root/.gramhopper orbin/gramhopper:latest

Documentation

Read more about the various triggers and responses in our documentation.

Contributing

You are welcome to contribute to gramhopper - read the contribution guidelines to get started.

gramhopper's People

Contributors

orbin avatar meirhalachmi avatar dependabot[bot] avatar

Stargazers

lmalma avatar  avatar Artium Nihamkin avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

lmalma

gramhopper's Issues

Write tests for configuration parsing

As a follow-up task for #10, we have to write tests for the parsing of the configuration.

We haven't defined yet the details of what should be tested, but this issue refers to the code in gramhopper/configuration/.

Write basic documentation

  • Instructions for setting up a bot with BotFather
  • Basic explanation of what this platform is
  • Explanation of basic platform usage

Refactor filter triggers

As explained here, some of the filter triggers are instances, not classes.
Try to make them all the same, preferably make them all classes.

End-to-end tests

Note: This is a follow-up task for #10.

We should create end-to-end tests for gramhopper.

The flow will be a creation of CombinedConversationHandler and/or CombinedMessageHandler, with mocked parts.
The idea is mocking the bot parameter/object, in order to log the responses so they can be tested.
For the mock, we probably should inherit CombinedMessageHandler, because it inherits MessageHandler and uses MessageHandler.handle_update() to call the updates-handling callback with the bot parameter. Maybe the dispatcher has to be mocked/inherited too.

We haven't yet thought about how to deeply mock incoming updates/messages - maybe we would like to override the function (I don't know which one it is) that checks for incoming updates and handles them (I guess it's in one of Update or Dispatcher classes).

We will begin with reading and parsing the configuration, through generating test messages to trigger the triggers, and checking the responded messages in the end.

Enable rules reading from a configuration file

  • Decide which configuration file type to use (yaml? json?)
  • Read triggers configuration (Note: handling &, | and ~ operators and handling event streak trigger will have a separate issue)
  • Read responses configuration

Support running on Windows

Currently, the configuration location is based on linux paths.
We should enable Windows paths, too.
The default Windows path should be decided (with permissions in mind).

Enable probabilistic list of responses for preset responses

Preset responses currently receive a preset single response or list of responses.
If a list of responses is given, the response to be sent is chosen randomly from the list.
We want to enable probabilistic selection, for example: the user wants to configure a bot to respond with a certain response in 75% of the times, and with another one in 25% of the times.

Points for thinking:

  • How the configuration should look?
  • Creating a type (dataclass?) for the probabilistic input (?)
  • Validating that the probabilities sum up to 100%

Before implementing this task, please post your suggestion for the configuration structure (an example configuration may be enough).

Watch rules file for changes and reload

Currently, the rules file is loaded once when the bot is started.
Gramhopper should watch changes on the rules file and then reload it and restart the bot.

Add docstrings

Add docstrings to classes, modules and functions.
Remove disable=missing-docstring from .pylintrc.

Related to #26.

Integrate a task runner for the project tasks

In the current stage of the project, there are a lot of tasks (for example: building, linting, generating docs) and it's hard to remember the commands for each of them.

This issue is a call to find and integrate a task runner (such as gulp/grunt) in the project.
Even though task runner for JS can do the job, a task runner for python is preferred (from a short search, I think that doit seems fine, but Invoke seems better).

The required tasks are:

  • build (package)
  • generate docs / build docs
  • lint
  • test (if they already exist)
  • publish package (possibly separate to publishing to test PyPI and publishing to "real" PyPI)
  • clean (remove all of the artifacts/outputs of other tasks)

This issue is labeled as a "good first issue". If this is your first issue, please consult with one of the maintainers before choosing which task runner to use.

Update dockerfile

The dockerfile is old and not relevant.
It should be updated for the new form of running the bot.

Add Windows to the CI process

The tests, lint, build and everything else (if there's anything else) should be able to run on Windows, too.
For this reason, we'd like to use another CI system that supports Windows.
AppVeyor does so, and is very common for this use case.

Document filter triggers

This issue was split up from #26.
Filter triggers should be documented just like other triggers (for a reference, look at the documentation for match triggers).

Work on this issue should begin only after #39 is done.

Document available triggers and responses

Add a list of available triggers and responses and their parameters to the documentation.
Check using auto-generated docs like readthedocs for example, maybe it can help

Set up elementary CI

Use Travis CI to create docker image, for the first step.
Later on, we will add lint, PyPI uploading, etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.