Async client API for the Telegram Group Calls

Overview

pytgcalls logo

PyTgCalls

pre-commit.ci status

This project allow to make Telegram group call with MTProto Api using Pyrogram and WebRTC, this is possible thanks to the power of NodeJS's WebRTC library, socketio-client and @evgeny-nadymov

Common Problems

Problem with pyrogram?

If do you have problems with pyrogram, reinstall by this command

pip install git+https://github.com/pyrogram/pyrogram -U

Live stream or ffmpeg live conversion stopped?

Check before if is changing the size of file(Is a method to check if ffmpeg is alive).

If is alive and stream is stopped, report to the issue with including last ultra verbose log and put in to nekobin.

Docs

Read the docs!

How to install?

Here's how to install the PyTgCalls lib, the commands are given below:

# With Git
pip install git+https://github.com/pytgcalls/pytgcalls -U

# With PyPi
pip install py-tgcalls -U

Conversion commands

From file to raw format

ffmpeg -i {INPUT_FILE} -f s16le -ac 1 -acodec pcm_s16le -ar {BITRATE} {OUTPUT_FILE}

From stream link to raw format

ffmpeg -y -i {STREAM_LINK} -f s16le -ac 1 -acodec pcm_s16le -ar {BITRATE} {OUTPUT_FILE}

From youtube video/live-stream to raw format

ffmpeg -i "$(youtube-dl -x -g "{YOUTUBE_LINK}")" -f s16le -ac 1 -acodec pcm_s16le -ar {BITRATE} {OUTPUT_FILE}

Credits

Big thanks to @evgeny-nadymov for allowing us to use their code from telegram-react

This library is based on tgcallsjs developed @AndrewLaneX and pyservercall by @Laky-64

Comments
  •  JOIN_VOICE_CALL_ERROR -> 'transport'

    JOIN_VOICE_CALL_ERROR -> 'transport'

    I'm trying to join voice chat which is running but is pytgcalls showing an error

    JOIN_VOICE_CALL_ERROR -> 'transport' pytgcalls: joinCallRequestResult -> {"transport":null} pytgcalls: joinCallError -> Error: No active voice chat found on xxxxx

    when I try to join a test channel that is mine it joins, but when try to join other channels it shows this error.

    2022-07-22 01_01_50-Clipboard

    Investigation Needed 
    opened by Shahjahan123 21
  • JS Syntax error while calling run(app)

    JS Syntax error while calling run(app)

    My code:

    import pytgcalls
    from pyrogram import Client
    app = Client('session')
    
    tg = pytgcalls.PyTgCalls(port=6540, log_mode=True)
    tg.run(app)
    tg.join_group_call(chat_id,  'input.raw', 160)
    

    And this is the error I am getting while running tg.run(app):

    /home/chaitanya/my-python-stuff/pytgcalls_tests/pytgcalls/pytgcalls/js/rtc_connection.js:6
        #tgcalls = null;
        ^
    
    SyntaxError: Invalid or unexpected token
        at Module._compile (internal/modules/cjs/loader.js:723:23)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
        at Module.load (internal/modules/cjs/loader.js:653:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
        at Function.Module._load (internal/modules/cjs/loader.js:585:3)
        at Module.require (internal/modules/cjs/loader.js:692:17)
        at require (internal/modules/cjs/helpers.js:25:18)
        at Object.<anonymous> (/home/chaitanya/my-python-stuff/pytgcalls_tests/pytgcalls/pytgcalls/js/core.js:2:23)
        at Module._compile (internal/modules/cjs/loader.js:778:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    

    I don't understand what the problem is, have I set up something wrong?

    opened by gfish35 11
  • Add a way for streaming in live from a webcam

    Add a way for streaming in live from a webcam

    Is your feature request related to a problem? Please describe. From the API there are no way for streaming in live from a webcam

    Describe the solution you'd like A method for streaming from a webcam, maybe with the option of choosing from which webcam (in case there are more webcams connected)

    Describe alternatives you've considered

    Additional context

    opened by lucabinotti 10
  • Facing Some Server problems

    Facing Some Server problems

    Client booted successfully No any bug there but Still when j tryied to play its was saying ERROR: pytgcalls:Telegram Server is having some internal problems

    Some server r not support maybe I have United States, Lincoln, NE server

    Linux (please complete the following information):

    • OS: [Linux]
    • NodeJS Version [16]
    • Python Version [. 3.8.9]

    Pls try to fix

    opened by ITZ-ZAID 9
  • 'PyTgCalls' from 'pytgcalls'

    'PyTgCalls' from 'pytgcalls'

    Traceback (most recent call last): File "join_vc.py", line 7, in from pytgcalls import PyTgCalls ImportError: cannot import name 'PyTgCalls' from 'pytgcalls' (C:\Users\Kerim\AppData\Local\Temp_MEI1875682\pytgcalls_init_.pyc)

    What is the way to solve this problem ? It runs on my computer but when I carry it to another it doesn't work :/

    Here is my file:

    import os import time import pyrogram import pytgcalls

    from pyrogram import Client from pytgcalls import PyTgCalls from pytgcalls import StreamType from pytgcalls.types.input_stream import InputAudioStream from pytgcalls.types.input_stream import InputStream

    import argparse

    parser = argparse.ArgumentParser(description='A test program.') parser.add_argument('-session', '--session', help='Session') parser.add_argument('-api_id', '--api_id', help='api_id') parser.add_argument('-api_pass', '--api_pass', help='api_pass') parser.add_argument('-chat', '--chat', help='chat') args = parser.parse_args() app = Client( str(args.session), api_id=int(args.api_id), api_hash=str(args.api_pass) )

    print(args.session) call_py = PyTgCalls(app) call_py.start()

    app.join_chat(str(args.chat))

    chat = app.get_chat(args.chat)

    print(chat["id"])

    file = 'input.raw' while not os.path.exists(file): time.sleep(0.125) call_py.join_group_call( int(chat["id"]), InputStream( InputAudioStream( file, ), ), stream_type=StreamType().local_stream, ) from pytgcalls import idle idle()

    opened by kthenurseone 8
  • Not working on Termux

    Not working on Termux

    Traceback (most recent call last):
      File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/psutil/_common.py", line 403, in wrapper
        return cache[key]
    KeyError: (('/proc',), frozenset())
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/psutil/_pslinux.py", line 302, in <module>
        set_scputimes_ntuple("/proc")
      File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/psutil/_common.py", line 405, in wrapper
        ret = cache[key] = fun(*args, **kwargs)
      File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/psutil/_pslinux.py", line 269, in set_scputimes_ntuple
        with open_binary('%s/stat' % procfs_path) as f:
      File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/psutil/_common.py", line 711, in open_binary
        return open(fname, "rb", **kwargs)
    PermissionError: [Errno 13] Permission denied: '/proc/stat'
    Traceback (most recent call last):
      File "/storage/emulated/0/shubhendra/bot/telegram/ban-channel-accounts-in-vc/test.py", line 11, in <module>
        from pytgcalls import PyTgCalls
      File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/pytgcalls/__init__.py", line 2, in <module>
        from .methods.custom_api.custom_api import CustomAPI
      File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/pytgcalls/methods/__init__.py", line 3, in <module>
        from .core import Core
      File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/pytgcalls/methods/core/__init__.py", line 10, in <module>
        from .spawn_process import SpawnProcess
      File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/pytgcalls/methods/core/spawn_process.py", line 2, in <module>
        from collections import Callable
    ImportError: cannot import name 'Callable' from 'collections' (/data/data/com.termux/files/usr/lib/python3.10/collections/__init__.py)
    
    opened by TheShubhendra 8
  • app.get_active_call(chat_id) not returning active call from the group

    app.get_active_call(chat_id) not returning active call from the group

    I have tried this method with the group where the call is active and the user is a part of that call but not getting the correct response back, instead always getting an error.

    Group call not found with the chat id -100123123123

    I have also searched for this in the Official Telegram Group, Some people have faced this problem before but No solution was provided there.

    opened by Muhammad-Aadil 6
  • Option for additional_ffmpeg_parameter right after -i <video link>

    Option for additional_ffmpeg_parameter right after -i

    Is your feature request related to a problem? Please describe. My video file has multiple audio tracks. If I wanna play say 2nd audio track, The ffmpeg command should be: ffmpeg -i <video_link> -map 0: a :1 but there is no option to add parameters rights after input. (if i use -map at the very end using 'atend', its ignored by ffmpeg.)

    Describe the solution you'd like The additional_ffmpeg_parameters should be in this format: "<parameters before -i> -atmid <parameters after -i> -atend "

    Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

    Additional context Add any other context or screenshots about the feature request here.

    enhancement 
    opened by billa298 6
  • ERROR:root:joinCallError -> Error: No active voice chat found on XXXXX

    ERROR:root:joinCallError -> Error: No active voice chat found on XXXXX

    Describe the bug Hi,I have a problem when I using pytgcalls.I start main function from example/multiple_calls/example_multiple.py.And I can login 2 client successfully and I start video group call at group chat.But when I send message(!p1 or !p2) to group chat,the pytgcalls example printf error message ERROR:root:JOIN_VOICE_CALL_ERROR -> init() got an unexpected keyword argument 'video_stopped' ERROR:root:joinCallError -> Error: No active voice chat found on XXXXX I don't know hot to solve this and who can help me.Thank you.

    To Reproduce Steps to reproduce the behavior:

    1. Go to 'start example/multiple_calls/example_multiple.py by python example_multiple.py'
    2. Click on 'phone number to login account A and B'
    3. Using telegram app which is account A to create a group call in a group chat which A and B are all in the group chat
    4. Send message !p2 to start join group call request
    5. The error messages are printf at console

    Expected behavior Can recevie input.raw on account A in group call

    Log ERROR:root:JOIN_VOICE_CALL_ERROR -> init() got an unexpected keyword argument 'video_stopped' ERROR:root:joinCallError -> Error: No active voice chat found on XXXXX

    Window (please complete the following information):

    • OS: [e.g. Window 10]
    • NodeJS Version [e.g. v16.13.0]
    • Python Version [e.g. 3.8.5]
    opened by ChenMoGe2 6
  • ImportError: cannot import name 'EditGroupCallParticipant' from 'pyrogram.raw.functions.phone'

    ImportError: cannot import name 'EditGroupCallParticipant' from 'pyrogram.raw.functions.phone'

    Traceback (most recent call last):
      File "main.py", line 3, in <module>
        from callsmusic import run
      File "/app/callsmusic/__init__.py", line 1, in <module>
        from .callsmusic import pytgcalls, run
      File "/app/callsmusic/callsmusic.py", line 2, in <module>
        from pytgcalls import PyTgCalls
      File "/usr/local/lib/python3.7/dist-packages/pytgcalls/__init__.py", line 2, in <module>
        from .methods.logs.py_logs import PyLogs  # noqa: F401
      File "/usr/local/lib/python3.7/dist-packages/pytgcalls/methods/__init__.py", line 8, in <module>
        from .websocket import WebSocket
      File "/usr/local/lib/python3.7/dist-packages/pytgcalls/methods/websocket/__init__.py", line 2, in <module>
        from .change_volume_voice_call import ChangeVolumeVoiceCall
      File "/usr/local/lib/python3.7/dist-packages/pytgcalls/methods/websocket/change_volume_voice_call.py", line 5, in <module>
        from pyrogram.raw.functions.phone import EditGroupCallParticipant
    ImportError: cannot import name 'EditGroupCallParticipant' from 'pyrogram.raw.functions.phone' (/usr/local/lib/python3.7/dist-packages/pyrogram/raw/functions/phone/__init__.py)
    
    opened by SuperCosmicBeing 5
  • ZeroDivisionError when streaming videos with Cover Art

    ZeroDivisionError when streaming videos with Cover Art

    Describe the bug When trying to stream a video that has cover art, the below error is getting raised.

    Traceback (most recent call last):
      File "d:\projects\tgcall\bot.py", line 81, in start
        await call_py.join_group_call(
      File "D:\projects\tgcall\venv\lib\site-packages\pytgcalls\methods\groups\join_group_call.py", line 196, in join_group_call
        await stream.check_pipe()
      File "D:\projects\tgcall\venv\lib\site-packages\pytgcalls\types\input_stream\audio_video_piped.py", line 82, in check_pipe
        width, height = check_video_params(
      File "D:\projects\tgcall\venv\lib\site-packages\pytgcalls\types\input_stream\video_tools.py", line 47, in check_video_params
        width, height = resize_ratio(dest_width, dest_height, 100)
      File "D:\projects\tgcall\venv\lib\site-packages\pytgcalls\types\input_stream\video_tools.py", line 32, in resize_ratio
        rescaling = ((720 if h > 720 else h) * 100) / h
    ZeroDivisionError: division by zero
    

    To Reproduce Steps to reproduce the behavior:

    1. An example file can be found here
    2. Download the file and pass it to join_group_call method.
    call_py.join_group_call(
        m.chat.id,
        AudioVideoPiped(remote_url, HighQualityAudio(), HighQualityVideo()),
        stream_type=StreamType().pulse_stream,
    )
    

    Log Media info for this particular file: https://nekobin.com/qemelurulo

    Windows 10:

    • NodeJS Version v16.17.0
    • Python Version 3.10.4

    Additional context My guess is that, because this file has 2 video streams (actual video stream and the cover art, check the attached media info) in FFprobe.check_file, inside the for loop, this condition is true for the cover art stream, which is overwriting the actual video's width and height to 0. Maybe adding mjpeg to the image_codecs list will solve this issue, not sure whether it will have any other impact.

    opened by odysseusmax 3
  • join_group_call without playing anything

    join_group_call without playing anything

    Is your feature request related to a problem? Please describe. I want to join vidcall without playing anything, and just listen to other person when they talk

    Describe the solution you'd like Seems like join_group_call really needs a stream parameter, can we just set it to None ?https://github.com/pytgcalls/pytgcalls/blob/4e697ef4d9842ab88c0362eac278538e61ee134c/pytgcalls/methods/groups/join_group_call.py#L37-L44

    opened by rainrisa 0
  • pytgcalls.exceptions.NoActiveGroupCall: No active group call

    pytgcalls.exceptions.NoActiveGroupCall: No active group call

    Describe the bug Simplest possible example generates exception. Please give some hint of what is going wrong. In the Telegram group, what should one do to facilitate the streaming? I've tried starting a group call, it had no effect. Further, can Pytcalls proactively start a group call? The plan is to send the video stream from a surveillance camera when motion is detected.

    To Reproduce

    import os
    import time
    from telethon import TelegramClient
    from pytgcalls import idle
    from pytgcalls import PyTgCalls
    from pytgcalls.types import AudioPiped
    
    app = TelegramClient('py-tgcalls',api_id=xxxxxxxxxx ,api_hash='yyyyyyyyyyyyyyyyyyy')
    call_py = PyTgCalls(app)
    call_py.start()
    call_py.join_group_call(-zzzzzzzzzzzzzzzzzzzz, AudioPiped('http://docs.evostream.com/sample_content/assets/sintel1m720p.mp4'))
    idle()
    

    Expected behavior Some progress, instead of the error.

    Log

    `Traceback (most recent call last):
      File "/home/pi/tt2.py", line 12, in <module>
        call_py.join_group_call(-611527117, AudioPiped('http://docs.evostream.com/sample_content/assets/sintel1m720p.mp4'))
      File "/usr/local/lib/python3.9/dist-packages/pytgcalls/sync.py", line 35, in async_to_sync_wrap
        return loop.run_until_complete(coroutine)
      File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
        return future.result()
      File "/usr/local/lib/python3.9/dist-packages/pytgcalls/methods/groups/join_group_call.py", line 292, in join_group_call
        raise NoActiveGroupCall()
    pytgcalls.exceptions.NoActiveGroupCall: No active group call
    
    
    opened by magnusso 3
  • UpdateGroupCallConnection Problem and Python3.10 support

    UpdateGroupCallConnection Problem and Python3.10 support

    If do you have problem like:

        from pyrogram.raw.types import UpdateGroupCallConnection
    ImportError: cannot import name 'UpdateGroupCallConnection' from 'pyrogram.raw.types' (/python3/site-packages/pyrogram/raw/types/__init__.py)
    

    Or

      File "/python3\site-packages\async_lru.py", line 237, in wrapped
        return (yield from asyncio.shield(fut, loop=_loop))
    TypeError: shield() got an unexpected keyword argument 'loop'
    

    Just do this

    pip3 uninstall pyrogram && pip3 install git+https://github.com/pyrogram/pyrogram -U

    good first issue Common Problems pyrogram 
    opened by Laky-64 0
  • JoinGroupCall with create option

    JoinGroupCall with create option

    Can you add method for create (start) new voice chat? can you add change title of voice chat? + update if an admin change the title can you optimize consume of cpu and ram on linux?

    enhancement 
    opened by killteamseller 0
Telegram Group Calls Streaming bot with some useful features, written in Python with Pyrogram and Py-Tgcalls. Supporting platforms like Youtube, Spotify, Resso, AppleMusic, Soundcloud and M3u8 Links.

Yukki Music Bot Yukki Music Bot is a Powerful Telegram Music+Video Bot written in Python using Pyrogram and Py-Tgcalls by which you can stream songs,

Team Yukki 996 Dec 28, 2022
TgMusicBot is a telegram userbot for playing songs in telegram voice calls based on Pyrogram and PyTgCalls.

TgMusicBot [Stable] TgMusicBot is a telegram userbot for playing songs in telegram voice calls based on Pyrogram and PyTgCalls. Commands !start / !hel

Kürşad 21 Dec 25, 2022
🚧 finCLI's own News API. No more limited API calls. Unlimited credible and latest information on BTC, Ethereum, Indian and Global Finance.

?? finCLI's own News API. No more limited API calls. Unlimited credible and latest information on BTC, Ethereum, Indian and Global Finance.

finCLI 5 Jun 16, 2022
Experimental bridges between Telegram calls and other platforms.

Bridges by Calls Music Experimental bridges between Telegram calls and other platforms. Current bridges Bridge 1 (YouTube, Twitch, Facebook, etc...) B

Calls Music 14 Oct 8, 2022
HTTP Calls to Amazon Web Services Rest API for IoT Core Shadow Actions 💻🌐💡

aws-iot-shadow-rest-api HTTP Calls to Amazon Web Services Rest API for IoT Core Shadow Actions ?? ?? ?? This simple script implements the following aw

AIIIXIII 3 Jun 6, 2022
Signs API calls to SberCloud.Advanced with AK/SK

sbercloud-api-aksk Signs API calls to SberCloud.Advanced with AK/SK This script is a courtesy of @sadpdtchr Description Sometimes there is a need to m

Peter Predtechensky 1 Nov 30, 2021
Stock market bot that will be used to learn about API calls and database connections.

Stock market bot that will be used to learn about API calls and database connections.

null 1 Dec 24, 2021
Python wrapper to simplify calls to AncestryDNA API.

AncestryDNA API wrapper Ancestry exposes an undocumented REST API for its DNA features. This Python wrapper inventories the available calls, and expos

Matt 2 Jun 10, 2022
Async ready API wrapper for Revolt API written in Python.

Mutiny Async ready API wrapper for Revolt API written in Python. Installation Python 3.9 or higher is required To install the library, you can just ru

null 16 Mar 29, 2022
YARSAW is an Async Python API Wrapper for the Random Stuff API.

Yet Another Random Stuff API Wrapper - YARSAW YARSAW is an Async Python API Wrapper for the Random Stuff API. This module makes it simpler for you to

Bruce 6 Mar 27, 2022
veez music bot is a telegram music bot project, allow you to play music on voice chat group telegram.

?? Veez Music Bot Music bot for playing music on telegram voice chat group. Requirements ?? FFmpeg NodeJS nodesource.com Python 3.7+ PyTgCalls ?? Get

levina 143 Jun 19, 2022
veez music is a telegram music bot project, allow you to play music on voice chat group telegram.

?? VEEZ MUSIC BOT Veez Music is a telegram bot project that's allow you to play music on telegram voice chat group. Requirements ?? FFmpeg NodeJS node

levina 23 Aug 29, 2021
An Telegram Bot By @AsmSafone To Stream Videos in Telegram Voice Chat. This is Also The Source Code of The Bot Which is Being Used In @SafoTheBot Group! ❤️

Telegram Video Player Bot (Beta) An Telegram Bot By @AsmSafone To Stream Videos in Telegram Voice Chat. Special Features Supports Live Streaming From

SAF ONE 206 Jan 3, 2023
this is a telegram bot repository, that can stream video on telegram group video chat.

VIDEO STREAM BOT telegram bot project for streaming video on telegram video chat, powered by tgcalls and pyrogram ?? Commands: /vstream (reply to vide

levina 319 Aug 15, 2022
Video Stream is a telegram bot project that's allow you to play video on telegram group video chat

Video Stream is a telegram bot project that's allow you to play video on telegram group video chat ?? Get SESSION_NAME from below: Pyrogram ## ✨ Featu

null 1 Nov 10, 2021
Telegram Bot that's allow you to play Video & Music on Telegram Group Video Chat

WAR MUSIC / VIDEO PLAYER Bot Bot Link: ?? Get SESSION_NAME from below: Pyrogram ?? Preview ✨ Features Music & Video stream support MultiChat support P

Abhishek singh 11 Dec 25, 2022
A simple bot that lives in your Telegram group, logging messages to a Postgresql database and serving statistical tables and plots to users as Telegram messages.

telegram-stats-bot Telegram-stats-bot is a simple bot that lives in your Telegram group, logging messages to a Postgresql database and serving statist

null 22 Dec 26, 2022
Video Stream: an Advanced Telegram Bot that's allow you to play Video & Music on Telegram Group Video Chat

Video Stream is an Advanced Telegram Bot that's allow you to play Video & Music on Telegram Group Video Chat ?? Get SESSION_NAME from below: Pyrogram

Jonathan 6 Feb 8, 2022
Asad Alexa VC Bot Is A Telegram Bot Project That's Allow You To Play Audio And Video Music On Telegram Voice Chat Group.

Asad Alexa VC Bot Is A Telegram Bot Project That's Allow You To Play Audio And Video Music On Telegram Voice Chat Group.

Dr Asad Ali 6 Jun 20, 2022