Skip to main content

A mini framework for building bots using python and can be served using different ways.

Project description

iaBot

iaBot is a Python library for creating simple bots and serving it with the different ways available.

PyPI version Build

Installation

Use the package manager pip to install iaBot.

pip install iaBot

A simple bot

from iabot import CreateBot
from iabot.handlers import SystemInformationHandler
from iabot.servers import HttpServer

handlers = [
   SystemInformationHandler
]
bot = CreateBot(
   handlers=handlers
)
bot_server = HttpServer(bot)
bot_server.run()

This creates a simple bot that will be listening to HttpRequests on the port 8000. Using any tool available send a post request to http://<your_domain.com>:8000/ with the following data.

{
  "handler": "system",
  "action": "time"
}

On successfull request you will get time in the response as json.

Handlers

These are used to group a set of similar actions. You can create your own handlers by inheriting the base handler.

from iabot.handlers import BaseHandler

class StockHandler(BaseHandler):
    handle = 'stock'

    def get_stocks(self, *args, **kwargs):
      .....
      ....

Once you create a handler with the actions you can register it to a bot by adding the handler to the list of handlers.

Actions

These are functions that a bot can execute to do the job when asked for. In the above StockHandler, get_stocks is an action. The response of all the actions should be a dictionary.

When a request reaches the server it will execute the particular action inside the handler. You can also send some additional data to your actions by passing it as a dict using data key in the request data. Remember a handler should always return a dict.

{
  "handler": "stock",
  "action": "get_stocks",
  "data": {
     "date": "04-5-2010"
   }
}

Will be updating more and adding more type of servers to serve the bot.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

-

Python Powered

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iaBot-0.0.7.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distribution

iaBot-0.0.7-py3-none-any.whl (5.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page