-
-
Save v1ckxy/28045f9ba8986b25e9ac6c65771d602c to your computer and use it in GitHub Desktop.
Make a call using pyrogram
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #This is taken from https://github.com/LonamiWebs/Telethon-calls/blob/master/calls.py and modified | |
| import hashlib | |
| import os | |
| import random | |
| from pyrogram import Client | |
| from pyrogram.api.functions.messages import GetDhConfig | |
| from pyrogram.api.functions.phone import RequestCall | |
| from pyrogram.api.types import PhoneCallProtocol | |
| client = Client("my_account") | |
| client.start() | |
| def get_dh_config(): | |
| class DH: | |
| def __init__(self, dh_config): | |
| self.p = int.from_bytes(dh_config.p, 'big') | |
| self.g = dh_config.g | |
| self.resp = dh_config | |
| return DH(client.send(GetDhConfig(0, 256))) | |
| dh_config = get_dh_config() | |
| class DynamicDict: | |
| def __setattr__(self, key, value): | |
| self.__dict__[key] = value | |
| def get_rand_bytes(length=256): | |
| return bytes(x ^ y for x, y in zip( | |
| os.urandom(length), dh_config.resp.random | |
| )) | |
| def integer_to_bytes(integer): | |
| return int.to_bytes( | |
| integer, | |
| length=(integer.bit_length() + 8 - 1) // 8, # 8 bits per byte, | |
| byteorder='big', | |
| signed=False | |
| ) | |
| def call_me_maybe(input_user): | |
| PROTOCOL = PhoneCallProtocol(min_layer=93, max_layer=93, udp_p2p=True) | |
| dhc = get_dh_config() | |
| state = DynamicDict() | |
| state.incoming = False | |
| state.user_id = input_user | |
| state.random_id = random.randint(0, 0x7fffffff - 1) | |
| state.g = dhc.g | |
| state.p = dhc.p | |
| state.a = 0 | |
| while not (1 < state.a < state.p - 1): | |
| # "A chooses a random value of a, 1 < a < p-1" | |
| state.a = int.from_bytes(get_rand_bytes(), 'little') | |
| state.g_a = pow(state.g, state.a, state.p) | |
| state.g_a_hash = hashlib.sha256(integer_to_bytes(state.g_a)).digest() | |
| state.my_proto = PROTOCOL | |
| client.send(RequestCall( | |
| user_id=client.resolve_peer(state.user_id), | |
| random_id=state.random_id, | |
| g_a_hash=state.g_a_hash, | |
| protocol=state.my_proto)) | |
| call_me_maybe("insert the username here") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment