-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
42 lines (34 loc) · 1.05 KB
/
main.py
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
41
42
import os
from flask import Flask, request
from dotenv import load_dotenv
from telegram import Update
from telegram.ext import (
ApplicationBuilder,
CommandHandler,
MessageHandler,
filters,
)
import handler
from webhook.setup import set_webhook
load_dotenv()
WEBHOOK_URL = os.getenv("WEBHOOK_URL")
TELEGRAM_BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
bot = ApplicationBuilder().token(TELEGRAM_BOT_TOKEN).build()
bot.add_handler(CommandHandler("start", handler.start))
bot.add_handler(CommandHandler("verify", handler.verify))
bot.add_handler(MessageHandler(filters.TEXT, handler.website))
bot.add_handler(MessageHandler(filters.CONTACT, handler.contact))
flask_app = Flask(__name__)
@flask_app.route("/webhook", methods=["POST"])
async def webhook():
update = Update.de_json(request.get_json(), bot.bot)
await bot.process_update(update)
return "ok"
if __name__ == "__main__":
set_webhook()
bot.run_webhook(
listen="0.0.0.0",
port=8000,
url_path="webhook",
webhook_url=f"{WEBHOOK_URL}/webhook",
)