Skip to main content

Yet another common wrapper for Telegram bots and Alice skills

Project description

tgalice

This is yet another common Python wrapper for Telegram bots* and Alice skills.

Currently, it provides:

  • An (almost) unified interface between your bot and Telegram or Alice: DialogConnector
  • A number of simple dialogue constructors: BaseDialogManager and its flavors
  • A wrapper for storing dialogue state: BaseStorage and its flavors

This package may be installed with

pip install tgalice

The three components of tgalice may be combined as follows:

import tgalice
connector = tgalice.dialog_connector.DialogConnector(
    dialog_manager=tgalice.dialog_manager.BaseDialogManager(), 
    storage=tgalice.session_storage.BaseStorage()
)

Now you can plug both Alice and Telegram into the connector. In the example below, they are served with Flask.

@app.route("/" + ALICE_URL, methods=['POST'])
def alice_response():
    response = connector.respond(request.json, source='alice')
    return json.dumps(response, ensure_ascii=False, indent=2)


@bot.message_handler(func=lambda message: True)
def telegram_response(message):
    response = connector.respond(message, source='telegram')
    bot.reply_to(message, **response)

To reduce the amount of boilerplate code even more, you can use the FlaskServer class, which configures both Alice and Telegram for you, and can also run in pure command line mode (e.g. if you want to test your bot without internet connection).

server = tgalice.flask_server.FlaskServer(connector=connector)
server.parse_args_and_run()

The examples directory contains more detailed examples of how to create dialogs and serve the bot.

* The Telegram wrapper is based on the pyTelegramBotAPI package.

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

tgalice-0.0.5.tar.gz (10.3 kB view details)

Uploaded Source

File details

Details for the file tgalice-0.0.5.tar.gz.

File metadata

  • Download URL: tgalice-0.0.5.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.1

File hashes

Hashes for tgalice-0.0.5.tar.gz
Algorithm Hash digest
SHA256 a74d791f65b365994c044f9ef32a085a3c56d505244c7d07b85d18a95fbc79ae
MD5 2a7b90937bf5d6c771ec776b0a556089
BLAKE2b-256 a2324fe3c0c78138a84466f1f241eead2fd714db2cda3718a7582672f2f7b61a

See more details on using hashes here.

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