mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-21 14:46:29 +01:00
Page:
PTB test writing knowledge base
Pages
Adding defaults to your bot
Arbitrary callback_data
Architecture
Ask Right
Ask Support
Avoiding flood limits
Bot API Forward Compatibility
Bots built with PTB
Builder Pattern
Code snippets
Concurrency
Emoji
Examples
Exception Handling
Exceptions, Warnings and Logging
Extensions Advanced Filters
Extensions JobQueue
Extensions Your first Bot
Extensions – Advanced Filters
Extensions – JobQueue
Extensions – Your first Bot
Frequently Asked Questions
Frequently requested design patterns
Handling network errors
Home
Hosting your bot
InlineKeyboard Example
Internal test bots
Introduction to the API
Local Bot API Server
MWE
Making your bot persistent
Notes about GAE Google App Engine
PTB test writing knowledge base
Performance Optimizations
Press
Project Bots, Groups and Channels
Related Projects
Storing bot, user and chat related data
Storing user and chat related data
Telegram Passport
Transition guide to Version 12.0
Transition guide to Version 13.0
Transition guide to Version 20.0
Transition guide to Version 4.0
Transition guide to Version 5.0
Type Checking
Types of Handlers
Webhooks
Where to host Telegram Bots
Working Behind a Proxy
Working with Files and Media
Writing Tests
No results
1
PTB test writing knowledge base
Poolitzer edited this page 2022-10-31 11:51:57 +01:00
Table of Contents
This page contains useful knowledge bits for writing tests for the PTB library. This might also help you out writing tests for your bots using PTB, but that is definitely not the goal of this document. If you have questions writing tests for PTB, feel free to ask them in the dev group. If you want to ask about writing tests for your bots, ask those either in @pythontelegrambotgroup or @pythontelegrambottalk.
How to generate encrypted passport files
For Passport encryption, decrypting data is clearly laid out by Telegram (for obvious reasons) while they only implicitly explain how they decrypt it. As of writing this document, I could not have been bothered figuring out the exact steps they take to encrypt the file, so I did the following:
- Setup a bot with botfather for passport decryption by providing the public key (with /setpublickey) from PTBs test private file. As of the time of writing that is
this Key.
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAstn3GNj9MRAz7Dsk2bY5
1//yxadHbYdLr6cro6cWw4JqsTHU3CweFcKuRhw/jOpv37GlTHk1VFrBlhchmvao
l6zdBLPQPXV5tMa3VQi/y03Y7Ax09C0rndAgjq6Xhsrnx/i1T8AUjBjbeqcuoiVf
0ZJwatGIODFRtf3CuXZifXlRYgyfrJEP8vd9SfkCHWQabSFE6z0m/vF3Yh4AjsRk
wugwWVWlOLhmTXHCSsnIPEZhdsuK1E85Nye7H1h68c+wYk07h1b01zlObCmJuS/L
Ct02JKEHNpCw0DAQF/3C+agLD2CFnN1j+m4RgZqqchVd0tsorGZKG7fMDu6vKOEh
WwIDAQAB
-----END PUBLIC KEY----- - Download the JS SDK and use it as described here. Fill out the stuff in the examples, don't forget the new lines in the public key. Set scope to the type you want to test.
- Once you press on the button, the tgdesktop app should open, and you can select a file to upload. Either the desktop or the the telegram servers compress pictures on upload and PTBs decryption compares hashes as it should, so have that in mind and download the decrypted part if needed.
- Once you done this, get the update, I copy pasted the json part of the PassportData.
- Setup a Bot object instance with the PTB private key and pass it to PassportData.
- Now you can use PassportData.de_json with the bot instance and the json string to generate a PassportData object.
- From there, you can either get the encrypted elements by accessing .credentials or .data[X], or get the decrypted ones with .decrypted_data().
Must read
Concepts & Important Elements
- Architecture Overview
- Builder Pattern for
Application
- Types of Handlers
- Working with Files and Media
- Exceptions, Warnings and Logging
- Concurrency in PTB
Notable Features
- Advanced Filters
- Storing data
- Making your bot persistent
- Adding Defaults
- Job Queue
- Arbitrary
callback_data
- Avoiding flood limits
- Webhooks
- Bot API Forward Compatiblity
Code Resources
- Frequently requested design patterns
- Code snippets
- Performance Optimizations
- Telegram Passport
- Bots built with PTB
- Automated Bot Tests
Examples explained
Networking
Other resources
- Where to host Telegram Bots
- How to host your bot
- Local API Server
- Type Checking with PTB
- Press
- Notes on GAE
- Related Projects
- Emoji
Transition Guides
Administration
- Wiki of
python-telegram-bot
© Copyright 2015-2024 – Licensed by Creative Commons