Skip to content

Commit 68b2d10

Browse files
committed
Add td_api::phoneNumberAuthenticationSettings and support automatic code retrival from SMS on Android.
GitOrigin-RevId: f97bd5bf3eb7449da1b14242fa47537801657b04
1 parent eed517a commit 68b2d10

File tree

15 files changed

+88
-79
lines changed

15 files changed

+88
-79
lines changed

example/cpp/td_example.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ class TdExample {
263263
std::cerr << "Enter phone number: ";
264264
std::string phone_number;
265265
std::cin >> phone_number;
266-
send_query(td_api::make_object<td_api::setAuthenticationPhoneNumber>(
267-
phone_number, false /*allow_flash_calls*/, false /*is_current_phone_number*/),
266+
send_query(td_api::make_object<td_api::setAuthenticationPhoneNumber>(phone_number, nullptr),
268267
create_authentication_query_handler());
269268
},
270269
[this](td_api::authorizationStateWaitEncryptionKey &) {

example/csharp/TdExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private static void OnAuthorizationStateUpdated(TdApi.AuthorizationState authori
9393
else if (_authorizationState is TdApi.AuthorizationStateWaitPhoneNumber)
9494
{
9595
string phoneNumber = ReadLine("Please enter phone number: ");
96-
_client.Send(new TdApi.SetAuthenticationPhoneNumber(phoneNumber, false, false), new AuthorizationRequestHandler());
96+
_client.Send(new TdApi.SetAuthenticationPhoneNumber(phoneNumber, null), new AuthorizationRequestHandler());
9797
}
9898
else if (_authorizationState is TdApi.AuthorizationStateWaitCode)
9999
{

example/java/org/drinkless/tdlib/example/Example.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private static void onAuthorizationStateUpdated(TdApi.AuthorizationState authori
108108
break;
109109
case TdApi.AuthorizationStateWaitPhoneNumber.CONSTRUCTOR: {
110110
String phoneNumber = promptString("Please enter phone number: ");
111-
client.send(new TdApi.SetAuthenticationPhoneNumber(phoneNumber, false, false), new AuthorizationRequestHandler());
111+
client.send(new TdApi.SetAuthenticationPhoneNumber(phoneNumber, null), new AuthorizationRequestHandler());
112112
break;
113113
}
114114
case TdApi.AuthorizationStateWaitCode.CONSTRUCTOR: {

example/uwp/app/MainPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private void Button_Click(object sender, RoutedEventArgs e)
9494
{
9595
var args = command.Split(" ".ToCharArray(), 2);
9696
AcceptCommand(command);
97-
_client.Send(new TdApi.SetAuthenticationPhoneNumber(args[1], false, false), _handler);
97+
_client.Send(new TdApi.SetAuthenticationPhoneNumber(args[1], null), _handler);
9898
}
9999
else if (command.StartsWith("cac"))
100100
{

td/generate/scheme/td_api.tl

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,14 @@ callStateError error:error = CallState;
16191619
call id:int32 user_id:int32 is_outgoing:Bool state:CallState = Call;
16201620

16211621

1622+
//@description Contains settings for the authentication of the user's phone number
1623+
//@allow_flash_call Pass true if the authentication code may be sent via flash call to the specified phone number
1624+
//@is_current_phone_number Pass true if the authenticated phone number is used on the current device
1625+
//@app_specific_sms_token If you want to automatically receive the authentication code from SMS in Android >= 26, pass a single use app specific 11-character token received from SmsManager.createAppSpecificSmsToken. If specified, this token is preferred over app_hash_string
1626+
//@app_hash_string If you want to use Android SMS Retriever API (requires Google Play Services >= 11.0), pass an 11-character hash string that identifies your app. See https://developers.google.com/identity/sms-retriever/ for more details
1627+
phoneNumberAuthenticationSettings allow_flash_call:Bool is_current_phone_number:Bool app_specific_sms_token:string app_hash_string:string = PhoneNumberAuthenticationSettings;
1628+
1629+
16221630
//@description Represents a list of animations @animations List of animations
16231631
animations animations:vector<animation> = Animations;
16241632

@@ -2720,9 +2728,10 @@ setTdlibParameters parameters:tdlibParameters = Ok;
27202728
//@description Checks the database encryption key for correctness. Works only when the current authorization state is authorizationStateWaitEncryptionKey @encryption_key Encryption key to check or set up
27212729
checkDatabaseEncryptionKey encryption_key:bytes = Ok;
27222730

2723-
//@description Sets the phone number of the user and sends an authentication code to the user. Works only when the current authorization state is authorizationStateWaitPhoneNumber
2724-
//@phone_number The phone number of the user, in international format @allow_flash_call Pass true if the authentication code may be sent via flash call to the specified phone number @is_current_phone_number Pass true if the phone number is used on the current device. Ignored if allow_flash_call is false
2725-
setAuthenticationPhoneNumber phone_number:string allow_flash_call:Bool is_current_phone_number:Bool = Ok;
2731+
//@description Sets the phone number of the user and sends an authentication code to the user. Works only when the current authorization state is authorizationStateWaitPhoneNumber,
2732+
//-or if there is no pending authentication query and the current authorization state is authorizationStateWaitCode or authorizationStateWaitPassword
2733+
//@phone_number The phone number of the user, in international format @settings Settings for the authentication of the user's phone number
2734+
setAuthenticationPhoneNumber phone_number:string settings:phoneNumberAuthenticationSettings = Ok;
27262735

27272736
//@description Re-sends an authentication code to the user. Works only when the current authorization state is authorizationStateWaitCode and the next_code_type of the result is not null
27282737
resendAuthenticationCode = Ok;
@@ -2772,7 +2781,7 @@ setPassword old_password:string new_password:string new_hint:string set_recovery
27722781
//@description Returns a 2-step verification recovery email address that was previously set up. This method can be used to verify a password provided by the user @password The password for the current user
27732782
getRecoveryEmailAddress password:string = RecoveryEmailAddress;
27742783

2775-
//@description Changes the 2-step verification recovery email address of the user. If a new recovery email address is specified, then the change will not be applied until the new recovery email address is confirmed
2784+
//@description Changes the 2-step verification recovery email address of the user. If a new recovery email address is specified, then the change will not be applied until the new recovery email address is confirmed.
27762785
//-If new_recovery_email_address is the same as the email address that is currently set up, this call succeeds immediately and aborts all other requests waiting for an email confirmation @password Password of the current user @new_recovery_email_address New recovery email address
27772786
setRecoveryEmailAddress password:string new_recovery_email_address:string = PasswordState;
27782787

@@ -3480,8 +3489,8 @@ setBio bio:string = Ok;
34803489
setUsername username:string = Ok;
34813490

34823491
//@description Changes the phone number of the user and sends an authentication code to the user's new phone number. On success, returns information about the sent code
3483-
//@phone_number The new phone number of the user in international format @allow_flash_call Pass true if the code can be sent via flash call to the specified phone number @is_current_phone_number Pass true if the phone number is used on the current device. Ignored if allow_flash_call is false
3484-
changePhoneNumber phone_number:string allow_flash_call:Bool is_current_phone_number:Bool = AuthenticationCodeInfo;
3492+
//@phone_number The new phone number of the user in international format @settings Settings for the authentication of the user's phone number
3493+
changePhoneNumber phone_number:string settings:phoneNumberAuthenticationSettings = AuthenticationCodeInfo;
34853494

34863495
//@description Re-sends the authentication code sent to confirm a new phone number for the user. Works only if the previously received authenticationCodeInfo next_code_type was not null
34873496
resendChangePhoneNumberCode = AuthenticationCodeInfo;
@@ -3712,8 +3721,8 @@ getPreferredCountryLanguage country_code:string = Text;
37123721

37133722

37143723
//@description Sends a code to verify a phone number to be added to a user's Telegram Passport
3715-
//@phone_number The phone number of the user, in international format @allow_flash_call Pass true if the authentication code may be sent via flash call to the specified phone number @is_current_phone_number Pass true if the phone number is used on the current device. Ignored if allow_flash_call is false
3716-
sendPhoneNumberVerificationCode phone_number:string allow_flash_call:Bool is_current_phone_number:Bool = AuthenticationCodeInfo;
3724+
//@phone_number The phone number of the user, in international format @settings Settings for the authentication of the user's phone number
3725+
sendPhoneNumberVerificationCode phone_number:string settings:phoneNumberAuthenticationSettings = AuthenticationCodeInfo;
37173726

37183727
//@description Re-sends the code to verify a phone number to be added to a user's Telegram Passport
37193728
resendPhoneNumberVerificationCode = AuthenticationCodeInfo;
@@ -3744,8 +3753,8 @@ sendPassportAuthorizationForm autorization_form_id:int32 types:vector<PassportEl
37443753

37453754

37463755
//@description Sends phone number confirmation code. Should be called when user presses "https://t.me/confirmphone?phone=*******&hash=**********" or "tg://confirmphone?phone=*******&hash=**********" link @hash Value of the "hash" parameter from the link
3747-
//@phone_number Value of the "phone" parameter from the link @allow_flash_call Pass true if the authentication code may be sent via flash call to the specified phone number @is_current_phone_number Pass true if the phone number is used on the current device. Ignored if allow_flash_call is false
3748-
sendPhoneNumberConfirmationCode hash:string phone_number:string allow_flash_call:Bool is_current_phone_number:Bool = AuthenticationCodeInfo;
3756+
//@phone_number Value of the "phone" parameter from the link @settings Settings for the authentication of the user's phone number
3757+
sendPhoneNumberConfirmationCode hash:string phone_number:string settings:phoneNumberAuthenticationSettings = AuthenticationCodeInfo;
37493758

37503759
//@description Resends phone number confirmation code
37513760
resendPhoneNumberConfirmationCode = AuthenticationCodeInfo;

td/generate/scheme/td_api.tlo

96 Bytes
Binary file not shown.

td/telegram/AuthManager.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ void AuthManager::check_bot_token(uint64 query_id, string bot_token) {
166166
DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off));
167167
}
168168

169-
void AuthManager::set_phone_number(uint64 query_id, string phone_number, bool allow_flash_call,
170-
bool is_current_phone_number) {
169+
void AuthManager::set_phone_number(uint64 query_id, string phone_number,
170+
td_api::object_ptr<td_api::phoneNumberAuthenticationSettings> settings) {
171171
if (state_ != State::WaitPhoneNumber) {
172172
if ((state_ == State::WaitCode || state_ == State::WaitPassword) && net_query_id_ == 0) {
173173
// ok
@@ -183,13 +183,11 @@ void AuthManager::set_phone_number(uint64 query_id, string phone_number, bool al
183183
return on_query_error(query_id, Status::Error(8, "Phone number can't be empty"));
184184
}
185185

186-
auto r_send_code =
187-
send_code_helper_.send_code(phone_number, allow_flash_call, is_current_phone_number, api_id_, api_hash_);
186+
auto r_send_code = send_code_helper_.send_code(phone_number, settings, api_id_, api_hash_);
188187
if (r_send_code.is_error()) {
189188
send_code_helper_ = SendCodeHelper();
190189
terms_of_service_ = TermsOfService();
191-
r_send_code =
192-
send_code_helper_.send_code(phone_number, allow_flash_call, is_current_phone_number, api_id_, api_hash_);
190+
r_send_code = send_code_helper_.send_code(phone_number, settings, api_id_, api_hash_);
193191
if (r_send_code.is_error()) {
194192
return on_query_error(query_id, r_send_code.move_as_error());
195193
}

td/telegram/AuthManager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class AuthManager : public NetActor {
3232
bool is_authorized() const;
3333
void get_state(uint64 query_id);
3434

35-
void set_phone_number(uint64 query_id, string phone_number, bool allow_flash_call, bool is_current_phone_number);
35+
void set_phone_number(uint64 query_id, string phone_number,
36+
td_api::object_ptr<td_api::phoneNumberAuthenticationSettings> settings);
3637
void resend_authentication_code(uint64 query_id);
3738
void check_code(uint64 query_id, string code, string first_name, string last_name);
3839
void check_bot_token(uint64 query_id, string bot_token);

td/telegram/PhoneNumberManager.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,24 @@ void PhoneNumberManager::process_send_code_result(uint64 query_id, T r_send_code
4747
start_net_query(NetQueryType::SendCode, G()->net_query_creator().create(create_storer(r_send_code.move_as_ok())));
4848
}
4949

50-
void PhoneNumberManager::set_phone_number(uint64 query_id, string phone_number, bool allow_flash_call,
51-
bool is_current_phone_number) {
50+
void PhoneNumberManager::set_phone_number(uint64 query_id, string phone_number, Settings settings) {
5251
if (phone_number.empty()) {
5352
return on_query_error(query_id, Status::Error(8, "Phone number can't be empty"));
5453
}
5554

5655
switch (type_) {
5756
case Type::ChangePhone:
58-
return process_send_code_result(
59-
query_id, send_code_helper_.send_change_phone_code(phone_number, allow_flash_call, is_current_phone_number));
57+
return process_send_code_result(query_id, send_code_helper_.send_change_phone_code(phone_number, settings));
6058
case Type::VerifyPhone:
61-
return process_send_code_result(
62-
query_id, send_code_helper_.send_confirm_phone_code(phone_number, allow_flash_call, is_current_phone_number));
59+
return process_send_code_result(query_id, send_code_helper_.send_confirm_phone_code(phone_number, settings));
6360
case Type::ConfirmPhone:
6461
default:
6562
UNREACHABLE();
6663
}
6764
}
6865

6966
void PhoneNumberManager::set_phone_number_and_hash(uint64 query_id, string hash, string phone_number,
70-
bool allow_flash_call, bool is_current_phone_number) {
67+
Settings settings) {
7168
if (phone_number.empty()) {
7269
return on_query_error(query_id, Status::Error(8, "Phone number can't be empty"));
7370
}
@@ -77,8 +74,7 @@ void PhoneNumberManager::set_phone_number_and_hash(uint64 query_id, string hash,
7774

7875
switch (type_) {
7976
case Type::ConfirmPhone:
80-
return process_send_code_result(query_id, send_code_helper_.send_verify_phone_code(
81-
hash, phone_number, allow_flash_call, is_current_phone_number));
77+
return process_send_code_result(query_id, send_code_helper_.send_verify_phone_code(hash, phone_number, settings));
8278
case Type::ChangePhone:
8379
case Type::VerifyPhone:
8480
default:

td/telegram/PhoneNumberManager.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ class PhoneNumberManager : public NetActor {
2323
PhoneNumberManager(Type type, ActorShared<> parent);
2424
void get_state(uint64 query_id);
2525

26-
void set_phone_number(uint64 query_id, string phone_number, bool allow_flash_call, bool is_current_phone_number);
27-
void set_phone_number_and_hash(uint64 query_id, string hash, string phone_number, bool allow_flash_call,
28-
bool is_current_phone_number);
26+
using Settings = td_api::object_ptr<td_api::phoneNumberAuthenticationSettings>;
27+
28+
void set_phone_number(uint64 query_id, string phone_number, Settings settings);
29+
void set_phone_number_and_hash(uint64 query_id, string hash, string phone_number, Settings settings);
2930

3031
void resend_authentication_code(uint64 query_id);
3132
void check_code(uint64 query_id, string code);

0 commit comments

Comments
 (0)