Skip to content

Latest commit

 

History

History
74 lines (54 loc) · 3.39 KB

File metadata and controls

74 lines (54 loc) · 3.39 KB

Creating and Configuring a Telegram Bot Token

A Telegram bot token is a unique identifier that allows your application to communicate with Telegram's API, enabling you to send messages, respond to user inputs, and automate various tasks. This guide will help you create a Telegram bot, obtain the bot token, and set it up in your project.

Step 1: Create a Telegram Bot

  1. Open Telegram: Make sure you have the Telegram app installed on your device. You can also use the Telegram Web version.

  2. Start a Chat with BotFather:

    • In the Telegram search bar, type BotFather and select the verified account with a blue checkmark.
    • BotFather is the official bot used to manage all Telegram bots.
  3. Create a New Bot:

    • Type /newbot and send the command to BotFather.
    • You will be prompted to enter a name for your bot (e.g., Chatz Bot). This is the display name of your bot.
    • Next, you will be asked to enter a username for your bot. The username must be unique and end with bot (e.g., chatz_bot).
  4. Get the Bot Token:

    • After creating your bot, BotFather will generate a message containing your new bot’s API token. The token will look something like this:
      123456789:ABCDefGhIjKlMnOpQRsTuVwXyZ123456789
      
    • Copy this token, as it will be used to authenticate and connect your bot with the Telegram API.

Step 2: Configure Bot Settings (Optional)

  1. Set a Profile Picture:

    • Send /setuserpic to BotFather, select your bot, and upload an image file to set as the bot’s profile picture.
  2. Set Commands for Your Bot:

    • You can define specific commands that your bot can handle using /setcommands.
    • Enter commands in the format:
      command1 - Description for command1
      command2 - Description for command2
      
  3. Enable Privacy Mode:

    • By default, bots cannot see messages sent by users unless they are commands starting with /. Use /setprivacy to adjust this setting.

Step 3: Using the Bot Token in Your Application (e.g., Chatz)

  1. Set Up Environment Variables:

    • Store the Bot Token in an environment variable to keep it secure. Add the following line to your ~/.chatz.ini file:
      [default]
      PROVIDER=telegram
      TOKEN=123456789:ABCDefGhIjKlMnOpQRsTuVwXyZ123456789
      CHAT_ID=123456789
  2. Example Configuration in Chatz:

    • Make sure your application reads the token correctly from the environment variables and is set up to send messages via Telegram.

Step 4: Testing Your Telegram Bot

  1. Start a Chat with Your Bot:

    • Search for your bot by its username in Telegram and start a chat.
  2. Send a Test Message:

    chatz -o "Test message."

Troubleshooting Tips

  • Invalid Token Error: Double-check your bot token and make sure there are no spaces or missing characters.
  • Bot Not Responding: Make sure your bot is started and has the correct permissions to read and send messages.
  • Incorrect Chat ID: Make sure you are using the correct chat ID when sending messages. You can obtain the chat ID by interacting with your bot and checking the updates received via the Telegram API.

Security Considerations

  • Keep your Telegram bot token secret. Never expose it in public repositories or share it openly.
  • Regenerate the token via BotFather if you suspect it has been compromised.