Simple Telegram Bot

By
 import logging
from telegram import Update
from telegram.ext import (
    Updater,
    CommandHandler,
    MessageHandler,
    CallbackContext,
    Filters,
)

TELEGRAM_API_TOKEN = "YOUR_TELEGRAM_API_TOKEN_HERE"

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.WARNING)

def start(update: Update, context: CallbackContext) -> None:
    update.message.reply_text("Hi! I am your BasicTelegramBot.")

def echo(update: Update, context: CallbackContext) -> None:
    update.message.reply_text(update.message.text)

def hey(update: Update, context: CallbackContext) -> None:
    update.message.reply_text("What's up?")

About this template

Simple Telegram Bot is a simple example Telegram bot that can receive and send messages, and handle a custom command /hey which responds with "What's up?".

Introduction to the Simple Telegram Bot Template

This Telegram bot is designed to help you engage with your audience on Telegram by receiving and sending messages, as well as handling a custom command. With this template, you can set up your bot to respond with a friendly "Hi! I am your BasicTelegramBot." when a user starts a conversation, echo back any text messages it receives, and reply with "What's up?" when the /hey command is used.

To get started with this template, simply click Start with this Template on the Lazy platform. This will pre-populate the code in the Lazy Builder interface, so you won't need to copy or paste any code manually.

Setting Environment Secrets

Before you can interact with your Telegram bot, you'll need to set up an environment secret for your Telegram API token. This token is essential for your bot to authenticate with the Telegram API and start receiving and sending messages.

Here's how to set your environment secret:

     
  • Go to the Environment Secrets tab within the Lazy Builder.
  •  
  • Enter TELEGRAM_API_TOKEN as the key.
  •  
  • Paste your Telegram API token into the value field. You can obtain this token from the BotFather on Telegram after creating your bot.

Once you've set your environment secret, you're ready to move on to the next step.

External Integrations

No external integrations are required for this template beyond setting up your Telegram bot with BotFather and obtaining your API token, which you've already done if you've set your environment secret correctly.

Using the Test Button

After setting your environment secret, it's time to test your bot. Click the Test button on the Lazy platform. This will deploy your app and launch the Lazy CLI. If the code requires any additional user input, you will be prompted for it through the Lazy CLI at this stage.

Once your bot is deployed, you can interact with it on Telegram by sending messages and using the /hey command to see how it responds.

How to Use Your Telegram Bot

After deploying your bot, here's how you can use it:

     
  • Start a conversation with your bot on Telegram.
  •  
  • Send the /start command to receive a greeting message from your bot.
  •  
  • Type any message and your bot will echo it back to you.
  •  
  • Use the /hey command to receive a "What's up?" message from your bot.

That's it! You now have a functioning Telegram bot that can interact with users and provide a simple yet engaging experience. Enjoy building your audience and having conversations on Telegram with your BasicTelegramBot!

Category
Technology
Last published
April 7, 2024

More templates like this

Basic Telegram Bot

A good starting point for a telegram bot.

Telegram

Emoji Financial News Bot

This app creates a Telegram bot that fetches the latest financial news from Bloomberg's RSS feed, analyzes the news titles using LLM ability, and shares it with users in the form of emoji representations. The user will be asked for their API token when they run the app.

Python
Telegram

Emoji Financial News Bot

This app creates a Telegram bot that fetches the latest financial news from Bloomberg's RSS feed, analyzes the news titles using LLM ability, and shares it with users in the form of emoji representations. The user will be asked for their API token when they run the app.

Python
Telegram
Home
/
Simple Telegram Bot