Bottel 016
Bottel 016
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'
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']
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()