No project description provided
Project description
Firebase Persistence for python-telegram-bot
This is an implementation of python-telegram-bot BasePersistence
class that uses Google Firebase as persistence back-end.
This has a very nice advantage of being able to look at your user_data
, chat_data
, bot_data
and convesations
real-time using the firebase web app.
Installation
Usage
Before you start: obtain credentials from firebase
First of all you need to obtain firebase credentials, that look like this:
{
"type": "service_account",
"project_id": "YOUR_ID",
"private_key_id": "YOUR_PRIVATE_KEY",
"private_key": "-----BEGIN PRIVATE KEY-----\nMII...EwQ=\n-----END PRIVATE KEY-----\n",
"client_email": "firebase-adminsdk-odh1e@SOME_DOMAIN.iam.gserviceaccount.com",
"client_id": "11743776666698009",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-SOMES_STRING.iam.gserviceaccount.com"
}
and the firebase database url that looks like this, something like https://YOUR_APP.firebaseio.com
Instantiation
From environment variables (recommended)
Store the database URL in an environment variable FIREBASE_URL
and the config as a json string in an environment variable
FIREBASE_CREDENTIALS
.
After that instantiation is as easy as:
from ptb_firebase_persistence import FirebasePersistence
from telegram.ext import Updater
persistence = FirebasePersistence.from_environment()
updater: Updater = Updater(
'BOT_TOKEN',
persistence=my_persistence,
use_context=True,
)
Direct instantiation
You can also just pass the firebase credentials as URL as simple init params:
from ptb_firebase_persistence import FirebasePersistence
from telegram.ext import Updater
persistence = FirebasePersistence(database_url='YOUR_DATABASE_URL', credentials='YOUR_CREDENTIALS_DICT')
updater: Updater = Updater(
'BOT_TOKEN',
persistence=my_persistence,
use_context=True,
)
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
Built Distribution
Hashes for ptb_firebase_persistence-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 283fa577a6bed9a0d35020c3784000b0a937d179f1846e193c2b81ace3fa82d6 |
|
MD5 | 9a94b10b88b165bebc416435c10933f8 |
|
BLAKE2b-256 | eba85df1e7b5a36d6b25068a4b8671187d2a044e36e210fda088a7a7b28f2987 |
Hashes for ptb_firebase_persistence-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32ea443d238d6dce985798c391e37edfe7795ec28977da8baf2287c1877d3d19 |
|
MD5 | 7b7bd93570a8184e80c21d5f3e0731fe |
|
BLAKE2b-256 | e02a6a7c5e7351a6220854cf6c00f3d811ebf2260795fbec52a162960a142ae9 |