MarshalX / tgcalls

Voice chats, private incoming and outgoing calls in Telegram for Developers
https://t.me/tgcallslib
GNU Lesser General Public License v3.0
516 stars 91 forks source link

Implement Telethon MTProto bridge #99

Closed MarshalX closed 3 years ago

MarshalX commented 3 years ago

Ability to implement custom mtproto client was added in #96

Whats need to know:

  1. Code with mtproto bridges available https://github.com/MarshalX/tgcalls/tree/add-custom-mtproto-clients-support branch
  2. File for Telethon bridge already created https://github.com/MarshalX/tgcalls/blob/add-custom-mtproto-clients-support/pytgcalls/pytgcalls/mtproto/telethon_bridge.py. You just need to implement methods in this class
  3. As an example of bridge implementation you can use Pyrogram bridge https://github.com/MarshalX/tgcalls/blob/add-custom-mtproto-clients-support/pytgcalls/pytgcalls/mtproto/pyrogram_bridge.py
  4. After implementing (or during) to test u need to delete this line to enable TelethonBridge support https://github.com/MarshalX/tgcalls/blob/741212fadd84088b72ae2478ca446f65803e85ba/pytgcalls/pytgcalls/group_call_factory.py#L48

Snippet how to create factory with Telethon MTProto bridge:

from pytgcalls import GroupCallFactory
telethon_group_call_factory = GroupCallFactory(
        client, GroupCallFactory.MTPROTO_CLIENT_TYPE.TELETHON, enable_logs_to_console=False
)

there client is Telethon app.

After that you can create file, device or raw group call instance:

file_group_call = group_call_factory.get_file_group_call('input.raw')
device_group_call = group_call_factory.get_device_group_call(audio_output_device='External Headphones')
# and so on...
MarshalX commented 3 years ago

Read comments in base class to understand what is need to implement https://github.com/MarshalX/tgcalls/blob/add-custom-mtproto-clients-support/pytgcalls/pytgcalls/mtproto/base_bridge.py

MarshalX commented 3 years ago

TODO optional deps (telethon) https://setuptools.readthedocs.io/en/latest/userguide/dependency_management.html#optional-dependencies

MarshalX commented 3 years ago

ParticipantWrapper renamed to GroupCallParticipantWrapper

MarshalX commented 3 years ago

To install pytgcalls version with Telethon support:

pip3 install -U git+https://github.com/MarshalX/tgcalls@add-custom-mtproto-clients-support#subdirectory=pytgcalls

also u need to install the last version of Telethon:

pip3 install -U telethon

some code snippet to run:

from telethon import TelegramClient
from pytgcalls import GroupCallFactory
client = TelegramClient(session_name, api_id, api_hash)
client.start()
group_call_factory = GroupCallFactory(client, GroupCallFactory.MTPROTO_CLIENT_TYPE.TELETHON)
group_call = group_call_factory.get_file_group_call('input.raw')
await group_call.start('@tgcallschat')
# and some idle here
Sunda001 commented 3 years ago

nice

nitanmarcel commented 3 years ago

@MarshalX commented on Jul 16, 2021, 4:58 PM GMT+3:

To install pytgcalls version with Telethon support:

pip3 install -U git+https://github.com/MarshalX/tgcalls@add-custom-mtproto-clients-support#subdirectory=pytgcalls

also u need to install the last version of Telethon:

pip3 install -U telethon

some code snippet to run:

from telethon import TelegramClient from pytgcalls import GroupCallFactory client \= TelegramClient(session_name, api_id, api_hash) client.start() group_call_factory \= GroupCallFactory(client, GroupCallFactory.MTPROTO_CLIENT_TYPE.TELETHON) group_call \= group_call_factory.get_file_group_call('input.raw') await group_call.start('@tgcallschat') # and some idle here

from telethon import TelegramClient from pytgcalls import GroupCallFactory

import asyncio
async def main():
    await client.start()
    group_call_factory = GroupCallFactory(client, GroupCallFactory.MTPROTO_CLIENT_TYPE.TELETHON)
    group_call = group_call_factory.get_file_group_call('input.raw')
    await group_call.start('@tgcallschat')

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())
MarshalX commented 3 years ago

TODO optional deps (telethon) https://setuptools.readthedocs.io/en/latest/userguide/dependency_management.html#optional-dependencies

done in https://github.com/MarshalX/tgcalls/commit/10226693076aaa8fc81a86cb350493653ddd2e07

LEGENDXOP commented 3 years ago

Superb