Telegram API daemon - we glue successive messages


    Write a thought in one message


    I am one of those people who write the idea in the messengers on the same sentence. This creates some inconvenience when reading this stream of thought, as successive messages quickly take up free space vertically. This is especially noticeable in group chats - notifications are disabled and to view the discussion, you have to miss the chat if someone writes in this way.

    Enough tolerating this!


    I am not going to retrain myself - I don’t consider this a problem of the one who writes, it’s so convenient for him - to retrain millions of people is more difficult than teaching one program. Messages must be glued together by the client himself so that it is convenient for everyone , at least optionally. I didn’t wait for this from the Telegram team - so I solved the problem with a small client, the Python daemon, and decided to share the source code with the community.
    Details, source code and description under the cut.

    How it works


    One of the main advantages of Telegram is really fast synchronization between different clients. The open API allows you to create your clients and many alternatives have already been written. I see no point in writing a full-fledged client - synchronization allows you to create small services that extend the capabilities of all clients on all platforms at once. Earlier, I told you how to increase the download limit for bot files from 50MB to 1.5GB , create channels and other features that are not available through the Bot API.

    On the 24/7 server, an authorized daemon runs that synchronizes with other clients — it receives both incoming and outgoing messages that I send from other clients. If the pause between two consecutive outgoing messages is less than 30s - the first message is edited through the API - the text of the second message is added to it, and the second message is deleted. Due to fast synchronization, this happens almost instantly.

    A small video in the work




    It would also be nice to disable the alert from the same person in the chat if the interval between his messages is small and the messages are not read, but this is not done through the API - so we will wait for it from Telegram developers.
    UPD I thought and realized that you can - just mute the chat for a while, if there is a stream of messages from one person, but this should already be done by the recipient.

    Inline translator


    At the same time I built in a translator - I also think that this should be in the client itself. It is inconvenient to use inline bots for a number of reasons, but the main one is: I want to get the translated text into the input line, and not send it to chat without editing.
    As a rule, you need to remember some word / phrase, and not the whole sentence (often translated crookedly).

    The only way to synchronize entered text between clients without sending a message is drafts. Unfortunately, a draft is created when moving from chat to chat list, but still this crutch is more convenient and faster to use the google translator application, copy paste.

    At the end of the line, add the language code



    Swipe right go to the chat list



    Go back - we get the translated string



    The language of the translated string is determined automatically, google is used for translation.

    Supported Languages
    supported_langs = {'Afrikaans': 'af', 'Irish': 'ga', 'Albanian': 'sq', 'Italian': 'it', 'Arabic': 'ar',
                       'Japanese': 'ja', 'Azerbaijani': 'az', 'Kannada': 'kn', 'Basque': 'eu', 'Korean': 'ko',
                       'Bengali': 'bn', 'Latin': 'la', 'Belarusian': 'be', 'Latvian': 'lv', 'Bulgarian': 'bg',
                       'Lithuanian': 'lt', 'Catalan': 'ca', 'Macedonian': 'mk', 'Chinese Simplified': 'zh-CN',
                       'Malay': 'ms', 'Chinese Traditional': 'zh-TW', 'Maltese': 'mt', 'Croatian': 'hr', 'Norwegian': 'no',
                       'Czech': 'cs', 'Persian': 'fa', 'Danish': 'da', 'Polish': 'pl', 'Dutch': 'nl', 'Portuguese': 'pt',
                       'English': 'en', 'Romanian': 'ro', 'Esperanto': 'eo', 'Russian': 'ru', 'Estonian': 'et',
                       'Serbian': 'sr', 'Filipino': 'tl', 'Slovak': 'sk', 'Finnish': 'fi', 'Slovenian': 'sl',
                       'French': 'fr', 'Spanish': 'es', 'Galician': 'gl', 'Swahili': 'sw', 'Georgian': 'ka',
                       'Swedish': 'sv', 'German': 'de', 'Tamil': 'ta', 'Greek': 'el', 'Telugu': 'te', 'Gujarati': 'gu',
                       'Thai': 'th', 'Haitian Creole': 'ht', 'Turkish': 'tr', 'Hebrew': 'iw', 'Ukrainian': 'uk',
                       'Hindi': 'hi', 'Urdu': 'ur', 'Hungarian': 'hu', 'Vietnamese': 'vi', 'Icelandic': 'is',
                       'Welsh': 'cy', 'Indonesian': 'id', 'Yiddish': 'yi'}
    


    Python AsyncIO Sources


    Github
    Also added compiled executable files for linux and windows to the repository - you can also run on your home PC, but for 24/7 work it is better to use VDS.

    The latest version of the telethon library is used to access the API.

    If anyone has a desire to improve the project - well.

    Throw an idea, discuss and ask questions in the comments or in the telegrams in the profile info.

    Also popular now: