0% found this document useful (0 votes)
21 views2 pages

Bottel 016

Bot tel 1

Uploaded by

mankleviokel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

Bottel 016

Bot tel 1

Uploaded by

mankleviokel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import requests

# Replace with your Telegram bot token


bot_token = '6492603811:AAF7WV4lgE-wsAOBn78IYZcqMyAFoF7FGTA' # Replace with your
actual bot token

def send_message(chat_id, text, reply_markup=None):


url = f'https://api.telegram.org/bot{bot_token}/sendMessage'
payload = {'chat_id': chat_id, 'text': text}
if reply_markup:
payload['reply_markup'] = reply_markup
response = requests.post(url, json=payload)
return response.json()
def create_inline_keyboard():
keyboard = [
[
{'text': 'Button 1', 'callback_data': 'button1_data'},
{'text': 'Button 2', 'callback_data': 'button2_data'}
]
]
return {'inline_keyboard': keyboard}

def handle_message(message):
chat_id = message['chat']['id']
if 'text' in message and message['text'] == '/start': # Check for message
and /start command
name = message['chat']['first_name'] if 'first_name' in message['chat']
else 'User'

# Personalized welcome message


welcome_text = f"Welcome, Mr. {name}!"

# Create inline keyboard


reply_markup = create_inline_keyboard()

send_message(chat_id, welcome_text, reply_markup=reply_markup)

def handle_callback_query(callback_query):
print(callback_query)
chat_id = callback_query['message']['chat']['id'] # Access message details
within callback_query
data = callback_query['data']

# Handle button presses (add your specific logic here)


response_text = f"You pressed button: {data}"
send_message(chat_id, response_text)

# Acknowledge callback (optional)


requests.post(f'https://api.telegram.org/bot{bot_token}/answerCallbackQuery',
json={'callback_query_id': callback_query['id']})

def main():
url = f'https://api.telegram.org/bot{bot_token}/getUpdates'
offset = 0

while True:
payload = {'offset': offset}
response = requests.get(url, json=payload)
data = response.json()
if data['result']:
for update in data['result']:
if update.get('message'):
handle_message(update['message'])
elif update.get('callback_query'):
handle_callback_query(update['callback_query'])
offset = update['update_id'] + 1

time.sleep(1)

if __name__ == '__main__':
import time
main()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy