testing telegram webhook
This commit is contained in:
@@ -1,5 +1,15 @@
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.responses import HTMLResponse
|
from fastapi.responses import HTMLResponse
|
||||||
|
import os
|
||||||
|
import telebot
|
||||||
|
|
||||||
|
BOT_TOKEN = os.environ["BOT_TOKEN"]
|
||||||
|
bot = telebot.TeleBot(BOT_TOKEN)
|
||||||
|
|
||||||
|
@bot.message_handler(commands=["start"])
|
||||||
|
def start(message):
|
||||||
|
bot.reply_to(message, "Welcome!")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
@@ -8,9 +18,17 @@ app = FastAPI(
|
|||||||
version="1.0.0",
|
version="1.0.0",
|
||||||
)
|
)
|
||||||
|
|
||||||
@app.post("/api/echo")
|
|
||||||
async def foo(payload: dict):
|
@app.post("/api/telegram_webhook")
|
||||||
return {"received_payload": payload}
|
async def telegram_webhook(request: Request):
|
||||||
|
json_data = await request.json()
|
||||||
|
update = telebot.types.Update.de_json(json_data)
|
||||||
|
bot.process_new_updates([update])
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
@app.post("/api/test")
|
||||||
|
async def test():
|
||||||
|
return {"message": "Test successful"}
|
||||||
|
|
||||||
@app.get("/api/data")
|
@app.get("/api/data")
|
||||||
def get_sample_data():
|
def get_sample_data():
|
||||||
|
|||||||
Reference in New Issue
Block a user