コード例 #1
0
def delete_api_messages(chat_id: int, api_messages_list, telegram: Telegram):

    if len(api_messages_list) is 0:
        return

    telegram.call_method(
        'deleteMessages', {
            'chat_id':
            chat_id,
            'message_ids':
            list(set([api_message['id'] for api_message in api_messages_list]))
        })
コード例 #2
0
def login():
    """
        This function creates and authenticates Telegram client
        and calls the call_back with Telegram client, phone no
        and chat id as arguments.
    """

    (ph_no, chat_id, bup_folders) = load_data()

    tg_client = Telegram(api_id=API_ID,
                         api_hash=API_HASH,
                         files_directory=FILES_DIR,
                         database_encryption_key=DATABASE_ENCRYPTION_KEY,
                         tdlib_verbosity=0,
                         phone=ph_no)

    tg_client.call_method(
        "setTdlibParameters",
        {
            "use_file_database": True,
            "use_chat_info_database": True,
            "use_message_database": True,
            "application_version": VERSION
        },
    )

    if chat_id is None:
        print("A code has been sent to you via telegram.")

    try_login_with_code(tg_client)

    if chat_id is None:
        chat_id = get_chat_id(tg_client, ph_no, bup_folders)

        if confirm("Do you want to load previously backed-up file list?"):
            print("Getting file list, this might take some time...")
            tg_client.get_chats().wait()

    return tg_client, chat_id, bup_folders
コード例 #3
0
    tg = Telegram(api_id=args.api_id,
                  api_hash=args.api_hash,
                  phone=args.phone,
                  td_verbosity=5,
                  files_directory=os.path.expanduser("~/.telegram/" +
                                                     args.phone),
                  database_encryption_key=args.dbkey)
    tg.login()

    # if this is the first run, library needs to preload all chats
    # otherwise the message will not be sent
    r = tg.get_chats()
    r.wait()

    r = tg.call_method(
        'createCall', {
            'user_id': args.user_id,
            'protocol': {
                'udp_p2p': True,
                'udp_reflector': True,
                'min_layer': 65,
                'max_layer': 65
            }
        })
    r.wait()
    outgoing = r.update

    tg.add_handler(handler)
    tg.idle()  # blocking waiting for CTRL+C
コード例 #4
0
        print(product)


if __name__ == '__main__':
    tg = Telegram(
        api_id=API_ID,
        api_hash=API_HASH,
        phone=PHONE,
        database_encryption_key=DATABASE_ENCRYPTION_KEY,
    )

    tg.login()

    DOWNLOAD = False

    result = tg.call_method('searchPublicChat',
                            params={'username': '******'})
    result.wait()

    if 'id' in result.update:
        chat_id = result.update['id']

    if DOWNLOAD:
        download_full_history()

        single_photo_messages = os.listdir(SINGLE_DIR)
        for fn in single_photo_messages:
            update_url_id(fn, SINGLE_DIR)

        albums_dirs = os.listdir(ALBUMS_DIR)
        for album_dir in albums_dirs:
            full_album_dir_path = ALBUMS_DIR + album_dir