Yet another common wrapper for Telegram bots and Alice skills
Project description
tgalice
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 Telegram or Alice:
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
)
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()
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 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file tgalice-0.1.4.tar.gz
.
File metadata
- Download URL: tgalice-0.1.4.tar.gz
- Upload date:
- Size: 14.8 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 829f402ff5fb8060018b941586e86bfeb8e79d6eb27f0cc9910c509d5c8ca3a6 |
|
MD5 | 7291e87dae676e75a74047a3ce3d84b1 |
|
BLAKE2b-256 | a9a399105e0989b062a50172cc7936f76cc9147f8c1dd3ea2fffdb2cdf584627 |