Skip to main content

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

Project description

dialogic

PyPI version

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

Currently, it provides:

  • An (almost) unified interface between your bot and Alice/SalutTelegram/Facebook/VK: DialogConnector, for which you can create or customize adapters.
  • A number of simple dialogue constructors: BaseDialogManager and its flavors, including:
    • a simple FAQ dialog manager
    • a simple form-filling dialog manager
    • a flexible finite state automaton dialog manager
    • an even more flexible turn-based 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 dialogic.

A brief how-to

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 dialogic may be combined into a working app as follows:

import dialogic

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

connector = dialogic.dialog_connector.DialogConnector(
    dialog_manager=EchoDialogManager(), 
    storage=dialogic.session_storage.BaseStorage()
)
server = dialogic.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, Salut and Facebook will be available, respectively, at {BASE_URL}/alice/, {BASE_URL}/salut/, 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.

If you have questions, you can ask them in the Telegram chat Dialogic.Digital support.

* 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

dialogic-0.3.12.tar.gz (60.5 kB view details)

Uploaded Source

File details

Details for the file dialogic-0.3.12.tar.gz.

File metadata

  • Download URL: dialogic-0.3.12.tar.gz
  • Upload date:
  • Size: 60.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.9

File hashes

Hashes for dialogic-0.3.12.tar.gz
Algorithm Hash digest
SHA256 911f91903e6b433bfb26147428a6d04a9583188748847607b5686499636ca125
MD5 8d44fc2ff0a2aab7f1628d23fb04c212
BLAKE2b-256 8f96f0df636d002165b70ceafc3affde118f5efe3ebd63a445d0cb84f36af1d2

See more details on using hashes here.

Supported by

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