Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PTB test writing knowledge base

Poolitzer edited this pageOct 31, 2022 ·1 revision

This page contains useful knowledge bits for writing tests for the PTB library. This might also help you out writing tests for your botsusing 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 thedev 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) fromPTBs 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 describedhere. 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().

Wiki ofpython-telegram-bot © Copyright 2015-2025 – Licensed byCreative Commons

Must read

  1. Introduction to the API
  2. Tutorial: Your first bot
  3. FAQ
  4. How to ask good questions
  5. How to write an MWE

Concepts & Important Elements

  1. Architecture Overview
  2. Builder Pattern forApplication
  3. Types of Handlers
  4. Working with Files and Media
  5. Exceptions, Warnings and Logging
  6. Concurrency in PTB

Notable Features

  1. Advanced Filters
  2. Storing data
  3. Making your bot persistent
  4. Adding Defaults
  5. Job Queue
  6. Arbitrarycallback_data
  7. Avoiding flood limits
  8. Webhooks
  9. Bot API Forward Compatiblity

Code Resources

  1. Frequently requested design patterns
  2. Code snippets
  3. Performance Optimizations
  4. Telegram Passport
  5. Bots built with PTB
  6. Automated Bot Tests

Examples explained

  1. InlineKeyboard Example

Networking

  1. Working Behind a Proxy
  2. Handling network errors

Other resources

  1. Where to host Telegram Bots
  2. How to host your bot
  3. Local API Server
  4. Type Checking with PTB
  5. Press
  6. Notes on GAE
  7. Related Projects
  8. Emoji

Transition Guides

Administration

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp