|
| 1 | +# Pyrogram - Telegram MTProto API Client Library for Python |
| 2 | +# Copyright (C) 2017-present Dan <https://github.com/delivrance> |
| 3 | +# |
| 4 | +# This file is part of Pyrogram. |
| 5 | +# |
| 6 | +# Pyrogram is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU Lesser General Public License as published |
| 8 | +# by the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# Pyrogram is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU Lesser General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU Lesser General Public License |
| 17 | +# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +import logging |
| 20 | +import re |
| 21 | + |
| 22 | +import pyrogram |
| 23 | +from pyrogram import raw, types |
| 24 | + |
| 25 | +log = logging.getLogger(__name__) |
| 26 | + |
| 27 | + |
| 28 | +class ChangePhoneNumber: |
| 29 | + async def change_phone_number( |
| 30 | + self: "pyrogram.Client", phone_number: str, phone_code_hash: str, phone_code: str |
| 31 | + ) -> "types.User": |
| 32 | + """Change a user phone number in Telegram with a valid confirmation code. |
| 33 | +
|
| 34 | + .. include:: /_includes/usable-by/users.rst |
| 35 | +
|
| 36 | + Parameters: |
| 37 | + phone_number (``str``): |
| 38 | + Phone number in international format (includes the country prefix). |
| 39 | +
|
| 40 | + phone_code_hash (``str``): |
| 41 | + Code identifier taken from the result of :meth:`~pyrogram.Client.send_phone_number_code`. |
| 42 | +
|
| 43 | + phone_code (``str``): |
| 44 | + The valid confirmation code you received from SMS in your phone number. |
| 45 | +
|
| 46 | + Returns: |
| 47 | + :obj:`~pyrogram.types.User`: On success, in case the change completed, the user is returned. |
| 48 | + """ |
| 49 | + phone_number = re.sub(r"\D", "", phone_number) |
| 50 | + |
| 51 | + r = await self.invoke( |
| 52 | + raw.functions.account.ChangePhone( |
| 53 | + phone_number=phone_number, |
| 54 | + phone_code_hash=phone_code_hash, |
| 55 | + phone_code=phone_code |
| 56 | + ) |
| 57 | + ) |
| 58 | + |
| 59 | + return types.User._parse(self, r) |
0 commit comments