Signing In as a Bot Account

You can also use Telethon for your bots (normal bot accounts, not users). You will still need an API ID and hash, but the process is very similar:

from telethon.sync import TelegramClient

api_id = 12345
api_hash = '0123456789abcdef0123456789abcdef'
bot_token = '12345:0123456789abcdef0123456789abcdef'

# We have to manually call "start" if we want an explicit bot token
bot = TelegramClient('bot', api_id, api_hash).start(bot_token=bot_token)

# But then we can use the client instance as usual
with bot:
    ...

To get a bot account, you need to talk with @BotFather.

Can I delete my messages?

Yes. You can always delete any messages you sent or received for both sides in any one-on-one conversation (in groups, it’s still your own messages only). You can also clear the entire chat history on both ends. On Telegram, deleted messages do not leave a mark in the chat.

Together with privacy settings for forwarded messages, this makes exchanging Telegram messages similar to talking face to face (without a tape recorder). As a result, users no longer need to worry about the data accumulating in their chats over the years. Both parties in a conversation have full control over what does and what doesn’t belong to their online identity.

Telethon Editing the Code

This is a little introduction for those new to Python programming in general.

We will write our code inside hello.py, so you can use any text editor that you like. To run the code, use python3 hello.py from the terminal.

Important

Don’t call your script telethon.py! Python will try to import the client from there and it will fail with an error such as “ImportError: cannot import name ‘TelegramClient’ …”.

What is People Nearby?

People Nearby is an optional feature that allows Telegram users to explore local groupsfind friends to chat with in their area, or quickly exchange contacts with people who are close.

You can find it in Contacts > Find People Nearby, as well as directly in the side menu on Android.

While you have the People Nearby section open on your screen, people who are very close will be able to see you there. If you don’t open the section, others will never see you in ‘People Nearby’.

You can also choose to permanently add your profile to the list of nearby people by tapping Make Myself Visible. After becoming visible, you can remove your profile from the list at any time by tapping Stop Showing Me.

Note: People Nearby is never turned on by default – users must manually enable it. If you are receiving messages from someone you don’t know, see Q: Who can contact me?

Telethon Signing In

Before working with Telegram’s API, you need to get your own API ID and hash:

  1. Login to your Telegram account with the phone number of the developer account to use.
  2. Click under API Development tools.
  3. Create new application window will appear. Fill in your application details. There is no need to enter any URL, and only the first two fields (App title and Short name) can currently be changed later.
  4. Click on Create application at the end. Remember that your API hash is secret and Telegram won’t let you revoke it. Don’t post it anywhere!

Note

This API ID and hash is the one used by your application, not your phone number. You can use this API ID and hash with any phone number or even for bot accounts.

Who can see me ‘online’?

The last seen rules apply to your online status as well. People can only see you online if you’re sharing your last seen status with them.

There are some exceptions because sometimes it is obvious that you are online. Regardless of the last seen settings, people will see you online for a brief period (~30 seconds) if you do the following:

  • Send them a message in a one-on-one chat or in a group where you both are members.
  • Read a message they sent you in a one-on-one chat.
  • Broadcast a “typing…” status to their chat with you or to a group where you both are members.

If you’re not sharing your last seen timestamp with someone and don’t do anything of the above, they’ll never see you online. Another way of achieving this is to block that person.