Implement Telethon MTProto bridge
MarshalX opened this issue · 8 comments
Ability to implement custom mtproto client was added in #96
Whats need to know:
- Code with mtproto bridges available https://github.com/MarshalX/tgcalls/tree/add-custom-mtproto-clients-support branch
- 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
- 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
- After implementing (or during) to test u need to delete this line to enable TelethonBridge support
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...
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
TODO optional deps (telethon) https://setuptools.readthedocs.io/en/latest/userguide/dependency_management.html#optional-dependencies
ParticipantWrapper
renamed to GroupCallParticipantWrapper
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
nice
@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())
TODO optional deps (telethon) https://setuptools.readthedocs.io/en/latest/userguide/dependency_management.html#optional-dependencies
done in 1022669
Superb