Skip to content

Commit eec9f8b

Browse files
authored
Merge pull request #2687 from Shivansh-Jain-github/master
Master
2 parents 2300867 + cf813ea commit eec9f8b

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

Telegram Bot code/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
```markdown
3+
# Simple Telegram Bot Example
4+
5+
This repository contains a simple example of a Telegram bot using the `python-telegram-bot` library in Python.
6+
7+
## Prerequisites
8+
9+
- `python-telegram-bot` library
10+
11+
You can install the required library using the following command:
12+
13+
```bash
14+
pip install python-telegram-bot
15+
```
16+
17+
## Description
18+
19+
This Telegram bot responds to user messages with a predefined message. It includes the following functionality:
20+
21+
- Responding to the `/start` command with a welcome message.
22+
- Echoing back any other text messages sent by users.
23+
24+
## Setup
25+
26+
1. Create a new bot on Telegram using the BotFather and obtain the bot token.
27+
2. Replace `'YOUR_BOT_TOKEN'` in the code (`telegram_bot.py`) with your actual bot token.
28+
29+
## Usage
30+
31+
1. Run the script using a Python interpreter:
32+
33+
```bash
34+
python telegram_bot.py
35+
```
36+
37+
2. Start a conversation with the bot on Telegram.
38+
3. Use the `/start` command to receive a welcome message.
39+
4. Send any other text message to receive an echo response.
40+
41+
## Customization
42+
43+
You can customize and extend the bot's functionality according to your requirements. Refer to the `python-telegram-bot` documentation for more advanced features and options.
44+
45+
## Author
46+
47+
Shivansh-Jain-github

Telegram Bot code/script.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
2+
3+
# Replace 'YOUR_BOT_TOKEN' with your actual bot token
4+
BOT_TOKEN = 'YOUR_BOT_TOKEN'
5+
6+
# Define the function for the /start command
7+
def start(update, context):
8+
update.message.reply_text("Hello! I'm your Telegram bot. How can I assist you?")
9+
10+
# Define the function to respond to user messages
11+
def reply_to_message(update, context):
12+
user_message = update.message.text
13+
response = f"You said: {user_message}"
14+
update.message.reply_text(response)
15+
16+
def main():
17+
updater = Updater(token=BOT_TOKEN, use_context=True)
18+
dispatcher = updater.dispatcher
19+
20+
# Create a handler for the /start command
21+
start_handler = CommandHandler('start', start)
22+
dispatcher.add_handler(start_handler)
23+
24+
# Create a handler for user messages
25+
message_handler =

0 commit comments

Comments
 (0)