-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_bot.py
More file actions
40 lines (31 loc) · 1.41 KB
/
Copy pathbasic_bot.py
File metadata and controls
40 lines (31 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import requests
from telegram import Update
from telegram.ext import CommandHandler, Application, ContextTypes
from dotenv import load_dotenv
load_dotenv('token.env')
load_dotenv('server_address.env')
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
message = requests.get(f'{os.getenv("server_addr")}/start')
await update.message.reply_text(message.json()["Message"])
async def test(update: Update, context: ContextTypes.DEFAULT_TYPE):
message = requests.get(f'{os.getenv("server_addr")}/test')
await update.message.reply_text(message.json()["Message"])
async def store_random_num(update:Update,context:ContextTypes.DEFAULT_TYPE):
response = requests.get(f'{os.getenv("server_addr")}/generate')
if response.status_code == 200:
data = response.json()
await update.message.reply_text(f"Number generated and saved: {data['number']}")
else:
await update.message.reply_text(response.content.decode())
def main():
application = Application.builder().token(os.getenv("token")).build()
start_handler = CommandHandler('start', start)
test_handler = CommandHandler('test', test)
generate_handler = CommandHandler('generate', store_random_num)
application.add_handler(test_handler)
application.add_handler(start_handler)
application.add_handler(generate_handler)
application.run_polling()
if __name__ == '__main__':
main()