Skip to content

Commit 64907d1

Browse files
authored
Merge pull request #871 from noplanman/bot_api_4.0_passport
Bot API 4.0 & 4.1 - Telegram Passport (without decryption helpers)
2 parents f76bee4 + 12e0c84 commit 64907d1

21 files changed

+586
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
66
## [Unreleased]
77
:exclamation: After updating to this version, you will need to execute the [SQL migration script][unreleased-sql-migration] on your database.
88
### Added
9-
- Bot API 4.0 (without Passport)
9+
- Bot API 4.0
1010
### Changed
1111
- [:exclamation:][unreleased-bc-move-animation-out-of-games-namespace] Move Animation entity out of Games namespace.
1212
### Deprecated

src/DB.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,15 +833,15 @@ public static function insertMessageRequest(Message $message)
833833
`location`, `venue`, `new_chat_members`, `left_chat_member`,
834834
`new_chat_title`,`new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
835835
`supergroup_chat_created`, `channel_chat_created`,
836-
`migrate_from_chat_id`, `migrate_to_chat_id`, `pinned_message`, `connected_website`
836+
`migrate_from_chat_id`, `migrate_to_chat_id`, `pinned_message`, `connected_website`, `passport_data`
837837
) VALUES (
838838
:message_id, :user_id, :chat_id, :date, :forward_from, :forward_from_chat, :forward_from_message_id,
839839
:forward_date, :reply_to_chat, :reply_to_message, :media_group_id, :text, :entities, :audio, :document,
840840
:animation, :game, :photo, :sticker, :video, :voice, :video_note, :caption, :contact,
841841
:location, :venue, :new_chat_members, :left_chat_member,
842842
:new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created,
843843
:supergroup_chat_created, :channel_chat_created,
844-
:migrate_from_chat_id, :migrate_to_chat_id, :pinned_message, :connected_website
844+
:migrate_from_chat_id, :migrate_to_chat_id, :pinned_message, :connected_website, :passport_data
845845
)
846846
');
847847

@@ -904,6 +904,7 @@ public static function insertMessageRequest(Message $message)
904904
$sth->bindValue(':migrate_to_chat_id', $message->getMigrateToChatId());
905905
$sth->bindValue(':pinned_message', $message->getPinnedMessage());
906906
$sth->bindValue(':connected_website', $message->getConnectedWebsite());
907+
$sth->bindValue(':passport_data', $message->getPassportData());
907908

908909
return $sth->execute();
909910
} catch (PDOException $e) {

src/Entities/Message.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Longman\TelegramBot\Entities\Games\Game;
1414
use Longman\TelegramBot\Entities\Payments\Invoice;
1515
use Longman\TelegramBot\Entities\Payments\SuccessfulPayment;
16+
use Longman\TelegramBot\Entities\TelegramPassport\PassportData;
1617

1718
/**
1819
* Class Message
@@ -56,6 +57,7 @@
5657
* @method Invoice getInvoice() Optional. Message is an invoice for a payment, information about the invoice.
5758
* @method SuccessfulPayment getSuccessfulPayment() Optional. Message is a service message about a successful payment, information about the payment.
5859
* @method string getConnectedWebsite() Optional. The domain name of the website on which the user has logged in.
60+
* @method PassportData getPassportData() Optional. Telegram Passport data
5961
*/
6062
class Message extends Entity
6163
{
@@ -90,6 +92,7 @@ protected function subEntities()
9092
'pinned_message' => Message::class,
9193
'invoice' => Invoice::class,
9294
'successful_payment' => SuccessfulPayment::class,
95+
'passport_data' => PassportData::class,
9396
];
9497
}
9598

@@ -304,6 +307,7 @@ public function getType()
304307
'pinned_message',
305308
'invoice',
306309
'successful_payment',
310+
'passport_data',
307311
];
308312

309313
$is_command = strlen($this->getCommand()) > 0;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* This file is part of the TelegramBot package.
4+
*
5+
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Longman\TelegramBot\Entities\TelegramPassport;
12+
13+
use Longman\TelegramBot\Entities\Entity;
14+
15+
/**
16+
* Class EncryptedCredentials
17+
*
18+
* Contains data required for decrypting and authenticating EncryptedCredentials. See the Telegram Passport Documentation for a complete description of the data decryption and authentication processes.
19+
*
20+
* @link https://core.telegram.org/bots/api#encryptedcredentials
21+
*
22+
* @method string getData() Base64-encoded encrypted JSON-serialized data with unique user's payload, data hashes and secrets required for EncryptedPassportElement decryption and authentication
23+
* @method string getHash() Base64-encoded data hash for data authentication
24+
* @method string getSecret() Base64-encoded secret, encrypted with the bot's public RSA key, required for data decryption
25+
**/
26+
class EncryptedCredentials extends Entity
27+
{
28+
29+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* This file is part of the TelegramBot package.
4+
*
5+
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Longman\TelegramBot\Entities\TelegramPassport;
12+
13+
use Longman\TelegramBot\Entities\Entity;
14+
15+
/**
16+
* Class EncryptedPassportElement
17+
*
18+
* Contains information about documents or other Telegram Passport elements shared with the bot by the user.
19+
*
20+
* @link https://core.telegram.org/bots/api#encryptedpassportelement
21+
*
22+
* @method string getType() Element type. One of “personal_details”, “passport”, “driver_license”, “identity_card”, “internal_passport”, “address”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”, “phone_number”, “email”.
23+
* @method string getData() Optional. Base64-encoded encrypted Telegram Passport element data provided by the user, available for “personal_details”, “passport”, “driver_license”, “identity_card”, “identity_passport” and “address” types. Can be decrypted and verified using the accompanying EncryptedCredentials.
24+
* @method string getPhoneNumber() Optional. User's verified phone number, available only for “phone_number” type
25+
* @method string getEmail() Optional. User's verified email address, available only for “email” type
26+
* @method PassportFile getFrontSide() Optional. Encrypted file with the front side of the document, provided by the user. Available for “passport”, “driver_license”, “identity_card” and “internal_passport”. The file can be decrypted and verified using the accompanying EncryptedCredentials.
27+
* @method PassportFile getReverseSide() Optional. Encrypted file with the reverse side of the document, provided by the user. Available for “driver_license” and “identity_card”. The file can be decrypted and verified using the accompanying EncryptedCredentials.
28+
* @method PassportFile getSelfie() Optional. Encrypted file with the selfie of the user holding a document, provided by the user; available for “passport”, “driver_license”, “identity_card” and “internal_passport”. The file can be decrypted and verified using the accompanying EncryptedCredentials.
29+
* @method string getHash() Base64-encoded element hash for using in PassportElementErrorUnspecified
30+
**/
31+
class EncryptedPassportElement extends Entity
32+
{
33+
/**
34+
* {@inheritdoc}
35+
*/
36+
protected function subEntities()
37+
{
38+
return [
39+
'files' => PassportFile::class,
40+
'front_side' => PassportFile::class,
41+
'reverse_side' => PassportFile::class,
42+
'selfie' => PassportFile::class,
43+
'translation' => PassportFile::class,
44+
];
45+
}
46+
47+
/**
48+
* Optional. Array of encrypted files with documents provided by the user, available for “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration” and “temporary_registration” types. Files can be decrypted and verified using the accompanying EncryptedCredentials.
49+
*
50+
* This method overrides the default getFiles method
51+
* and returns a nice array of PassportFile objects.
52+
*
53+
* @return null|PassportFile[]
54+
*/
55+
public function getFiles()
56+
{
57+
$pretty_array = $this->makePrettyObjectArray(PassportFile::class, 'files');
58+
59+
return empty($pretty_array) ? null : $pretty_array;
60+
}
61+
62+
/**
63+
* Optional. Array of encrypted files with translated versions of documents provided by the user. Available if requested for “passport”, “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration” and “temporary_registration” types. Files can be decrypted and verified using the accompanying EncryptedCredentials.
64+
*
65+
* This method overrides the default getTranslation method
66+
* and returns a nice array of PassportFile objects.
67+
*
68+
* @return null|PassportFile[]
69+
*/
70+
public function getTranslation()
71+
{
72+
$pretty_array = $this->makePrettyObjectArray(PassportFile::class, 'translation');
73+
74+
return empty($pretty_array) ? null : $pretty_array;
75+
}
76+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* This file is part of the TelegramBot package.
4+
*
5+
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Longman\TelegramBot\Entities\TelegramPassport;
12+
13+
use Longman\TelegramBot\Entities\Entity;
14+
15+
/**
16+
* Class PassportData
17+
*
18+
* Contains information about Telegram Passport data shared with the bot by the user.
19+
*
20+
* @link https://core.telegram.org/bots/api#passportdata
21+
*
22+
* @method EncryptedCredentials getCredentials() Encrypted credentials required to decrypt the data
23+
**/
24+
class PassportData extends Entity
25+
{
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
protected function subEntities()
30+
{
31+
return [
32+
'data' => EncryptedPassportElement::class,
33+
'credentials' => EncryptedCredentials::class,
34+
];
35+
}
36+
37+
/**
38+
* Array with information about documents and other Telegram Passport elements that was shared with the bot
39+
*
40+
* This method overrides the default getData method
41+
* and returns a nice array of EncryptedPassportElement objects.
42+
*
43+
* @return null|EncryptedPassportElement[]
44+
*/
45+
public function getData()
46+
{
47+
$pretty_array = $this->makePrettyObjectArray(EncryptedPassportElement::class, 'data');
48+
49+
return empty($pretty_array) ? null : $pretty_array;
50+
}
51+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* This file is part of the TelegramBot package.
4+
*
5+
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Entities\TelegramPassport\PassportElementError;
12+
13+
interface PassportElementError
14+
{
15+
16+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* This file is part of the TelegramBot package.
4+
*
5+
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Entities\TelegramPassport\PassportElementError;
12+
13+
use Longman\TelegramBot\Entities\Entity;
14+
15+
/**
16+
* Class PassportElementErrorDataField
17+
*
18+
* Represents an issue in one of the data fields that was provided by the user. The error is considered resolved when the field's value changes.
19+
*
20+
* @link https://core.telegram.org/bots/api#passportelementerrordatafield
21+
*
22+
* @method string getSource() Error source, must be data
23+
* @method string getType() The section of the user's Telegram Passport which has the error, one of “personal_details”, “passport”, “driver_license”, “identity_card”, “internal_passport”, “address”
24+
* @method string getFieldName() Name of the data field which has the error
25+
* @method string getDataHash() Base64-encoded data hash
26+
* @method string getMessage() Error message
27+
*/
28+
class PassportElementErrorDataField extends Entity implements PassportElementError
29+
{
30+
/**
31+
* PassportElementErrorDataField constructor
32+
*
33+
* @param array $data
34+
*
35+
* @throws \Longman\TelegramBot\Exception\TelegramException
36+
*/
37+
public function __construct(array $data = [])
38+
{
39+
$data['source'] = 'data';
40+
parent::__construct($data);
41+
}
42+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* This file is part of the TelegramBot package.
4+
*
5+
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Entities\TelegramPassport\PassportElementError;
12+
13+
use Longman\TelegramBot\Entities\Entity;
14+
15+
/**
16+
* Class PassportElementErrorFile
17+
*
18+
* Represents an issue with a document scan. The error is considered resolved when the file with the document scan changes.
19+
*
20+
* @link https://core.telegram.org/bots/api#passportelementerrorfile
21+
*
22+
* @method string getSource() Error source, must be file
23+
* @method string getType() The section of the user's Telegram Passport which has the issue, one of “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”
24+
* @method string getFileHash() Base64-encoded file hash
25+
* @method string getMessage() Error message
26+
*/
27+
class PassportElementErrorFile extends Entity implements PassportElementError
28+
{
29+
/**
30+
* PassportElementErrorFile constructor
31+
*
32+
* @param array $data
33+
*
34+
* @throws \Longman\TelegramBot\Exception\TelegramException
35+
*/
36+
public function __construct(array $data = [])
37+
{
38+
$data['source'] = 'file';
39+
parent::__construct($data);
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* This file is part of the TelegramBot package.
4+
*
5+
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Entities\TelegramPassport\PassportElementError;
12+
13+
use Longman\TelegramBot\Entities\Entity;
14+
15+
/**
16+
* Class PassportElementErrorFiles
17+
*
18+
* Represents an issue with a list of scans. The error is considered resolved when the list of files containing the scans changes.
19+
*
20+
* @link https://core.telegram.org/bots/api#passportelementerrorfiles
21+
*
22+
* @method string getSource() Error source, must be files
23+
* @method string getType() The section of the user's Telegram Passport which has the issue, one of “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”
24+
* @method string[] getFileHashes() List of base64-encoded file hashes
25+
* @method string getMessage() Error message
26+
*/
27+
class PassportElementErrorFiles extends Entity implements PassportElementError
28+
{
29+
/**
30+
* PassportElementErrorFiles constructor
31+
*
32+
* @param array $data
33+
*
34+
* @throws \Longman\TelegramBot\Exception\TelegramException
35+
*/
36+
public function __construct(array $data = [])
37+
{
38+
$data['source'] = 'files';
39+
parent::__construct($data);
40+
}
41+
}

0 commit comments

Comments
 (0)