46 lines
1.2 KiB
Python
Executable File
46 lines
1.2 KiB
Python
Executable File
# router.bale_bot.py
|
||
from fastapi import Depends, APIRouter, Request
|
||
import requests, traceback
|
||
from router.bale.bale_handle import BaleBot, BaleUpdate
|
||
from dependencies import _get_bale_token, _get_bale_bot
|
||
|
||
|
||
##############
|
||
router = APIRouter(tags=["bale-bot"])
|
||
##############
|
||
|
||
"""
|
||
deleteMessage
|
||
message_id
|
||
chat_id
|
||
"""
|
||
|
||
# @app.post(f"/webhook/{TOKEN}")
|
||
@router.post("/webhook/{token}", description="ربات قانون یار")
|
||
async def webhook(
|
||
request: Request,
|
||
token: str = Depends(_get_bale_token),
|
||
bale_bot: BaleBot = Depends(_get_bale_bot),
|
||
):
|
||
raw = await request.json()
|
||
|
||
try:
|
||
update = BaleUpdate(**raw)
|
||
except Exception as e:
|
||
print("❌ Parse Error", e)
|
||
return {"ok": True}
|
||
|
||
# print(f"update {update}")
|
||
return await bale_bot.render_update(update)
|
||
|
||
|
||
def initialize_webhook(webhook_url, set_webhook_url):
|
||
"""
|
||
این تابع برای ربات اجباری است
|
||
به سرور بله مشخص میکند که به چه server ایی درخواست ها را با این توکن داده شده ارسال کند
|
||
"""
|
||
params = {"url": webhook_url}
|
||
r = requests.get(set_webhook_url, params=params)
|
||
print("Webhook set status:", r.status_code)
|
||
print("Webhook set response:", r.json())
|