Skip to main content

Yet another common wrapper for Alice skills and Facebook/Telegram bots

Project description

tgalice

PyPI version

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

Currently, it provides:

  • An (almost) unified interface between your bot and Alice/Telegram/Facebook: DialogConnector
  • A number of simple dialogue constructors: BaseDialogManager and its flavors, including:
    • a simple FAQ dialog manager
    • a simple form-filling dialog manager
  • A wrapper for storing dialogue state: BaseStorage and its flavors (specifially, MongoBasedStorage)
  • Yet another wrapper for serving your bot as a Flask application

This package may be installed with pip install tgalice

To create your own bot, you need either to write a config for an existing dialog manager, or to inherit your own dialog manager from BaseDialogManager.

The components of tgalice may be combined into a working app as follows:

import tgalice

class EchoDialogManager(tgalice.dialog_manager.BaseDialogManager):
    def respond(self, ctx: tgalice.dialog.Context):
        return tgalice.dialog.Response(text=ctx.message_text)

connector = tgalice.dialog_connector.DialogConnector(
    dialog_manager=EchoDialogManager(), 
    storage=tgalice.session_storage.BaseStorage()
)
server = tgalice.flask_server.FlaskServer(connector=connector)

if __name__ == '__main__':
    server.parse_args_and_run()

Now, if your app is hosted on address {BASE_URL}, then webhooks for Alice and Facebook will be available, respectively, at {BASE_URL}/alice/ and {BASE_URL}/fb/ (and you can reconfigure it, if you want). The webhook for Telegram will be set automatically, if you set the TOKEN environment variable to the token given to you by the @BotFather.

If you want to test your app locally, you can run it with command line args:

  • --cli - to read and type messages in command line, completely offline
  • --poll - to run a Telegram bot locally, in long polling mode (in some countries, you need a VPN to do this)
  • --ngrok - to run the bot locally, using the ngrok tool** to create a tunnel from your machine into the internet. This is probably the simplest way to test Alice skills without deploying them anywhere .

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.

** The ngrok connector was taken from the flask-ngrok library. It will be refactored to a dependency, as soon as the library is updated on PyPI.

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.2.1.tar.gz (26.6 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for tgalice-0.2.1.tar.gz
Algorithm Hash digest
SHA256 6bc3f41501939d13bf2ed35fa1dff37d21480d484542ae3106d6f260c07dd1c7
MD5 09e8c34f94d2d5033c6e844b471dc99d
BLAKE2b-256 e6036f3af7ab1643425dd2bba508cf97d358d2631d4fe0b562921fb5e56c6373

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