0

I know that a bot can be created in a telegram if you send the command /newbot to the bot @BotFather. But to do this, you need to take your device, open Telegram, open a chat with @BotFather and send him the command /newbot. Can all of the above be done programmatically?

P.S.: this is not laziness, but an attempt to optimize the solution.

Paolo
  • 20,112
  • 21
  • 72
  • 113

1 Answers1

4

Yes, it's possible to create such interaction with mtproto libraries (pyrogram, telethon, madelineproto, etc...)

Here is a PoC script using telethon (python3 -m pip install -U telethon first to install the dependency):

from telethon import TelegramClient, events

api_id = ...
api_hash = "..."
client = TelegramClient('session', api_id, api_hash)

BOT_NAME="..."
BOT_USER_NAME="..." # must end with -bot

@client.on(events.NewMessage)
async def message_handler(event):
    if 'Please choose a name for your bot' in event.raw_text:
        await event.reply(BOT_NAME)
    elif 'choose a username for your bot' in event.raw_text:
        await event.reply(BOT_USER_NAME)
    elif 'Done! Congratulations on your new bot' in event.raw_text:
        print("Bot created!")
        await client.disconnect()

async def main():
    await client.send_message('botfather', '/newbot')


with client:
    client.loop.run_until_complete(main())
    client.run_until_disconnected()

You acquire the app_id and app_hash values from https://my.telegram.org/ and here is telethon's doc.

Paolo
  • 20,112
  • 21
  • 72
  • 113
Tibebes. M
  • 6,940
  • 5
  • 15
  • 36