-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.py
52 lines (40 loc) · 1.1 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
43
44
45
46
47
48
49
50
51
52
import os
from api import api_bp
from config import *
from handlers import *
@app.route("/" + TOKEN, methods=["POST"])
def checkWebhook():
json_string = request.get_data().decode("utf-8")
update = telebot.types.Update.de_json(json_string)
bot.process_new_updates([update])
return "Your bot application is still active!", 200
@app.route("/", methods=["GET"])
def webhook():
bot.remove_webhook()
bot.set_webhook(url=WEBHOOK_URL + "/" + TOKEN)
return "Btcpay-Escrow Bot running!", 200
app.add_url_rule(
"/pay",
"process_payment",
lambda: process_merchant_webhook(bot),
methods=["POST", "GET"],
)
def run_web():
if __name__ == "__main__":
# # db.init_app(app)
# app.register_blueprint(api_bp)
app.run(
host="0.0.0.0",
threaded=True,
port=int(os.environ.get("PORT", 5004)),
)
def run_poll():
webhook_info = bot.get_webhook_info()
if webhook_info.url:
bot.delete_webhook()
bot.infinity_polling()
print("Bot polling!")
if WEBHOOK_MODE == "False":
run_poll()
else:
run_web()