Skip to content
Permalink
Browse files

Bot API 4.0 (#1168)

Telegram Passport (#1174):

- Add full support for telegram passport.
    - New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
    - New bot method: set_passport_data_errors
    - New filter: Filters.passport_data
    - Field passport_data field on Message
    - PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
    - PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.

Inputfile rework (#1184):

- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.

Other Bot API 4.0 changes:

- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
    - Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
    - Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)


Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
  • Loading branch information...
4 people committed Aug 29, 2018
1 parent 3534102 commit 4689a80c2e623a03976b7e5b878d358639396690
Showing with 4,024 additions and 529 deletions.
  1. +43 −0 CHANGES.rst
  2. +1 −1 README.rst
  3. +6 −0 docs/source/telegram.credentials.rst
  4. +6 −0 docs/source/telegram.datacredentials.rst
  5. +6 −0 docs/source/telegram.encryptedcredentials.rst
  6. +6 −0 docs/source/telegram.encryptedpassportelement.rst
  7. +6 −0 docs/source/telegram.filecredentials.rst
  8. +6 −0 docs/source/telegram.iddocumentdata.rst
  9. +6 −0 docs/source/telegram.inputmediaanimation.rst
  10. +6 −0 docs/source/telegram.inputmediaaudio.rst
  11. +6 −0 docs/source/telegram.inputmediadocument.rst
  12. +6 −0 docs/source/telegram.passportdata.rst
  13. +6 −0 docs/source/telegram.passportelementerror.rst
  14. +6 −0 docs/source/telegram.passportelementerrordatafield.rst
  15. +6 −0 docs/source/telegram.passportelementerrorfile.rst
  16. +6 −0 docs/source/telegram.passportelementerrorfiles.rst
  17. +6 −0 docs/source/telegram.passportelementerrorfrontside.rst
  18. +6 −0 docs/source/telegram.passportelementerrorreverseside.rst
  19. +6 −0 docs/source/telegram.passportfile.rst
  20. +6 −0 docs/source/telegram.personaldetails.rst
  21. +6 −0 docs/source/telegram.residentialaddress.rst
  22. +28 −1 docs/source/telegram.rst
  23. +6 −0 docs/source/telegram.securedata.rst
  24. +29 −0 examples/passportbot.html
  25. +99 −0 examples/passportbot.py
  26. +1 −0 requirements.txt
  27. +29 −6 telegram/__init__.py
  28. +6 −1 telegram/base.py
  29. +331 −66 telegram/bot.py
  30. +13 −0 telegram/chat.py
  31. +1 −1 telegram/ext/callbackqueryhandler.py
  32. +1 −1 telegram/ext/choseninlineresulthandler.py
  33. +1 −1 telegram/ext/commandhandler.py
  34. +2 −2 telegram/ext/dispatcher.py
  35. +18 −0 telegram/ext/filters.py
  36. +1 −1 telegram/ext/handler.py
  37. +1 −1 telegram/ext/inlinequeryhandler.py
  38. +1 −1 telegram/ext/messagehandler.py
  39. +1 −1 telegram/ext/precheckoutqueryhandler.py
  40. +1 −1 telegram/ext/regexhandler.py
  41. +1 −1 telegram/ext/shippingqueryhandler.py
  42. +8 −1 telegram/ext/updater.py
  43. +14 −1 telegram/{games → files}/animation.py
  44. +9 −1 telegram/files/audio.py
  45. +5 −1 telegram/files/contact.py
  46. +16 −1 telegram/files/file.py
  47. +39 −116 telegram/files/inputfile.py
  48. +323 −3 telegram/files/inputmedia.py
  49. +0 −65 telegram/files/inputmediaphoto.py
  50. +0 −89 telegram/files/inputmediavideo.py
  51. +7 −1 telegram/files/venue.py
  52. +2 −2 telegram/inline/inlinequeryresultaudio.py
  53. +2 −2 telegram/inline/inlinequeryresultcachedaudio.py
  54. +2 −2 telegram/inline/inlinequeryresultcachedgif.py
  55. +2 −2 telegram/inline/inlinequeryresultcachedmpeg4gif.py
  56. +2 −2 telegram/inline/inlinequeryresultcachedphoto.py
  57. +2 −2 telegram/inline/inlinequeryresultcachedvideo.py
  58. +2 −2 telegram/inline/inlinequeryresultcachedvoice.py
  59. +7 −0 telegram/inline/inlinequeryresultcontact.py
  60. +2 −2 telegram/inline/inlinequeryresultdocument.py
  61. +2 −2 telegram/inline/inlinequeryresultgif.py
  62. +2 −2 telegram/inline/inlinequeryresultmpeg4gif.py
  63. +2 −2 telegram/inline/inlinequeryresultphoto.py
  64. +9 −0 telegram/inline/inlinequeryresultvenue.py
  65. +2 −2 telegram/inline/inlinequeryresultvideo.py
  66. +6 −1 telegram/inline/inputcontactmessagecontent.py
  67. +9 −1 telegram/inline/inputvenuemessagecontent.py
  68. +60 −7 telegram/message.py
  69. +6 −1 telegram/messageentity.py
  70. 0 telegram/passport/__init__.py
  71. +446 −0 telegram/passport/credentials.py
  72. +109 −0 telegram/passport/data.py
  73. +183 −0 telegram/passport/encryptedpassportelement.py
  74. +105 −0 telegram/passport/passportdata.py
  75. +252 −0 telegram/passport/passportelementerrors.py
  76. +111 −0 telegram/passport/passportfile.py
  77. +13 −0 telegram/user.py
  78. +47 −16 telegram/utils/request.py
  79. +28 −2 tests/conftest.py
  80. BIN tests/data/thumb.jpg
  81. +69 −18 tests/test_animation.py
  82. +17 −5 tests/test_audio.py
  83. +11 −3 tests/test_bot.py
  84. +7 −0 tests/test_chat.py
  85. +6 −5 tests/test_document.py
  86. +75 −0 tests/test_encryptedcredentials.py
  87. +91 −0 tests/test_encryptedpassportelement.py
  88. +10 −0 tests/test_filters.py
  89. +1 −1 tests/test_game.py
  90. +5 −0 tests/test_inlinequeryresultvenue.py
  91. +18 −1 tests/test_inputfile.py
  92. +211 −17 tests/test_inputmedia.py
  93. +6 −1 tests/test_inputvenuemessagecontent.py
  94. +2 −12 tests/test_invoice.py
  95. +41 −11 tests/test_message.py
  96. +9 −6 tests/test_official.py
  97. +290 −0 tests/test_passport.py
  98. +88 −0 tests/test_passportelementerrordatafield.py
  99. +79 −0 tests/test_passportelementerrorfile.py
  100. +80 −0 tests/test_passportelementerrorfiles.py
  101. +79 −0 tests/test_passportelementerrorfrontside.py
  102. +79 −0 tests/test_passportelementerrorreverseside.py
  103. +79 −0 tests/test_passportelementerrorselfie.py
  104. +71 −0 tests/test_passportfile.py
  105. +4 −4 tests/test_photo.py
  106. +5 −8 tests/test_updater.py
  107. +7 −0 tests/test_user.py
  108. +9 −3 tests/test_venue.py
  109. +5 −9 tests/test_video.py
  110. +5 −8 tests/test_videonote.py
@@ -1,6 +1,49 @@
=======
Changes
=======

*Released 11.0.0*

Fully support Bot API version 4.0!

Telegram Passport (`#1174`_):

- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to `our telegram passport wiki page`_ for more info
- NOTE: Passport decryption requires new dependency `cryptography`.

Inputfile rework (`#1184`_):

- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send\_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.

Other Bot API 4.0 changes:

- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (`#1170`_)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (`#1166`_)
- Support new message entities: CASHTAG and PHONE_NUMBER. (`#1179`_)
- Cashtag seems to be things like `$USD` and `$GBP`, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (`#1172`_)


.. _`#1174`: https://github.com/python-telegram-bot/python-telegram-bot/pull/1174
.. _`#1184`: https://github.com/python-telegram-bot/python-telegram-bot/pull/1184
.. _`#1170`: https://github.com/python-telegram-bot/python-telegram-bot/pull/1170
.. _`#1166`: https://github.com/python-telegram-bot/python-telegram-bot/pull/1166
.. _`#1179`: https://github.com/python-telegram-bot/python-telegram-bot/pull/1179
.. _`#1172`: https://github.com/python-telegram-bot/python-telegram-bot/pull/1172
.. _`our telegram passport wiki page`: https://git.io/fAvYd

**2018-05-02**
*Released 10.1.0*

@@ -95,7 +95,7 @@ make the development of bots easy and straightforward. These classes are contain
Telegram API support
====================

All types and methods of the Telegram Bot API 3.6 are supported.
All types and methods of the Telegram Bot API **4.0** are supported.

==========
Installing
@@ -0,0 +1,6 @@
telegram.Credentials
====================

.. autoclass:: telegram.Credentials
:members:
:show-inheritance:
@@ -0,0 +1,6 @@
telegram.DataCredentials
========================

.. autoclass:: telegram.DataCredentials
:members:
:show-inheritance:
@@ -0,0 +1,6 @@
telegram.EncryptedCredentials
=============================

.. autoclass:: telegram.EncryptedCredentials
:members:
:show-inheritance:
@@ -0,0 +1,6 @@
telegram.EncryptedPassportElement
=================================

.. autoclass:: telegram.EncryptedPassportElement
:members:
:show-inheritance:
@@ -0,0 +1,6 @@
telegram.FileCredentials
========================

.. autoclass:: telegram.FileCredentials
:members:
:show-inheritance:
@@ -0,0 +1,6 @@
telegram.IdDocumentData
=======================

.. autoclass:: telegram.IdDocumentData
:members:
:show-inheritance:
@@ -0,0 +1,6 @@
telegram.InputMediaAnimation
============================

.. autoclass:: telegram.InputMediaAnimation
:members:
:show-inheritance:
@@ -0,0 +1,6 @@
telegram.InputMediaAudio
========================

.. autoclass:: telegram.InputMediaAudio
:members:
:show-inheritance:
@@ -0,0 +1,6 @@
telegram.InputMediaDocument
===========================

.. autoclass:: telegram.InputMediaDocument
:members:
:show-inheritance:
@@ -0,0 +1,6 @@
telegram.PassportData
=====================

.. autoclass:: telegram.PassportData
:members:
:show-inheritance:
@@ -0,0 +1,6 @@
telegram.PassportElementError
=============================

.. autoclass:: telegram.PassportElementError
:members:
:show-inheritance:
@@ -0,0 +1,6 @@
telegram.PassportElementErrorDataField
======================================

.. autoclass:: telegram.PassportElementErrorDataField
:members:
:show-inheritance:
@@ -0,0 +1,6 @@
telegram.PassportElementErrorFile
=================================

.. autoclass:: telegram.PassportElementErrorFile
:members:
:show-inheritance:
@@ -0,0 +1,6 @@
telegram.PassportElementErrorFiles
==================================

.. autoclass:: telegram.PassportElementErrorFiles
:members:
:show-inheritance:
@@ -0,0 +1,6 @@
telegram.PassportElementErrorFrontSide
======================================

.. autoclass:: telegram.PassportElementErrorFrontSide
:members:
:show-inheritance:
@@ -0,0 +1,6 @@
telegram.PassportElementErrorReverseSide
========================================

.. autoclass:: telegram.PassportElementErrorReverseSide
:members:
:show-inheritance:
@@ -0,0 +1,6 @@
telegram.PassportFile
=====================

.. autoclass:: telegram.PassportFile
:members:
:show-inheritance:
@@ -0,0 +1,6 @@
telegram.PersonalDetails
========================

.. autoclass:: telegram.PersonalDetails
:members:
:show-inheritance:
@@ -0,0 +1,6 @@
telegram.ResidentialAddress
===========================

.. autoclass:: telegram.ResidentialAddress
:members:
:show-inheritance:
@@ -5,6 +5,7 @@ telegram package

telegram.ext
telegram.utils
telegram.animation
telegram.audio
telegram.bot
telegram.callbackquery
@@ -22,6 +23,9 @@ telegram package
telegram.inlinekeyboardmarkup
telegram.inputfile
telegram.inputmedia
telegram.inputmediaanimation
telegram.inputmediaaudio
telegram.inputmediadocument
telegram.inputmediaphoto
telegram.inputmediavideo
telegram.keyboardbutton
@@ -106,10 +110,33 @@ Games
.. toctree::

telegram.game
telegram.animation
telegram.callbackgame
telegram.gamehighscore

Passport
--------

.. toctree::

telegram.passportelementerror
telegram.passportelementerrorfile
telegram.passportelementerrorreverseside
telegram.passportelementerrorfrontside
telegram.passportelementerrorfiles
telegram.passportelementerrordatafield
telegram.passportelementerrorfile
telegram.credentials
telegram.datacredentials
telegram.securedata
telegram.filecredentials
telegram.iddocumentdata
telegram.personaldetails
telegram.residentialaddress
telegram.passportdata
telegram.passportfile
telegram.encryptedpassportelement
telegram.encryptedcredentials


Module contents
---------------
@@ -0,0 +1,6 @@
telegram.SecureData
===================

.. autoclass:: telegram.SecureData
:members:
:show-inheritance:
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Telegram passport test!</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!--- Needs file from https://github.com/TelegramMessenger/TGPassportJsSDK downloaded --->
<script src="telegram-passport.js"></script>
<script>
"use strict";
Telegram.Passport.createAuthButton('telegram_passport_auth', {
bot_id: BOT_ID, // YOUR BOT ID
scope: ['id_document', 'phone_number', 'email'], // WHAT DATA YOU WANT TO RECEIVE
public_key: '-----BEGIN PUBLIC KEY----- ...', // YOUR PUBLIC KEY
payload: 'thisisatest', // YOUR BOT WILL RECEIVE THIS DATA WITH THE REQUEST
callback_url: 'https://example.org' // TELEGRAM WILL SEND YOUR USER BACK TO THIS URL
});
</script>
</head>
<body>
<h1>Telegram passport test</h1>

<div id="telegram_passport_auth"></div>
</body>
</html>
@@ -0,0 +1,99 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Simple Bot to print/download all incoming passport data
# This program is dedicated to the public domain under the CC0 license.
"""
See https://telegram.org/blog/passport for info about what telegram passport is.
See https://git.io/fAvYd for how to use Telegram Passport properly with python-telegram-bot.
"""
import logging

from telegram.ext import Updater, MessageHandler, Filters

# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.DEBUG)

logger = logging.getLogger(__name__)


def msg(bot, update):
# If we received any passport data
passport_data = update.message.passport_data
if passport_data:
# If our payload doesn't match what we think, this Update did not originate from us
# Ideally you would randomize the payload on the server
if passport_data.decrypted_credentials.payload != 'thisisatest':
return

# Print the decrypted credential data
# For all elements
# Print their decrypted data
# Files will be downloaded to current directory
for data in passport_data.decrypted_data: # This is where the data gets decrypted
if data.type == 'phone_number':
print('Phone: ', data.phone_number)
elif data.type == 'email':
print('Email: ', data.email)
if data.type in ('personal_details', 'passport', 'driver_license', 'identity_card',
'identity_passport', 'address'):
print(data.type, data.data)
if data.type in ('utility_bill', 'bank_statement', 'rental_agreement',
'passport_registration', 'temporary_registration'):
print(data.type, len(data.files), 'files')
for file in data.files:
actual_file = file.get_file()
print(actual_file)
actual_file.download()
if data.type in ('passport', 'driver_license', 'identity_card',
'internal_passport'):
if data.front_side:
file = data.front_side.get_file()
print(data.type, file)
file.download()
if data.type in ('driver_license' and 'identity_card'):
if data.reverse_side:
file = data.reverse_side.get_file()
print(data.type, file)
file.download()
if data.type in ('passport', 'driver_license', 'identity_card',
'internal_passport'):
if data.selfie:
file = data.selfie.get_file()
print(data.type, file)
file.download()


def error(bot, update, error):
"""Log Errors caused by Updates."""
logger.warning('Update "%s" caused error "%s"', update, error)


def main():
"""Start the bot."""
# Create the Updater and pass it your token and private key
updater = Updater("TOKEN", private_key=open('private.key', 'rb').read())

# Get the dispatcher to register handlers
dp = updater.dispatcher

# On messages that include passport data call msg
dp.add_handler(MessageHandler(Filters.passport_data, msg))

# log all errors
dp.add_error_handler(error)

# Start the Bot
updater.start_polling()

# Run the bot until you press Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()


if __name__ == '__main__':
main()
@@ -1,2 +1,3 @@
future>=0.16.0
certifi
cryptography
Oops, something went wrong.

0 comments on commit 4689a80

Please sign in to comment.
You can’t perform that action at this time.