Total Complexity | 4 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # -*- coding:utf-8 -*- |
||
2 | """ |
||
3 | Providing routes for our application |
||
4 | """ |
||
5 | |||
6 | from flask import Blueprint, request as rq |
||
7 | from telebot import types |
||
8 | |||
9 | from app.bot.telegram import bot, TOKEN |
||
10 | |||
11 | bot_blueprint = Blueprint("route", __name__) |
||
12 | |||
13 | |||
14 | @bot_blueprint.route(f"/{TOKEN}", methods=["POST"]) |
||
15 | def get_message(): |
||
16 | """ |
||
17 | Get all messages |
||
18 | :return: |
||
19 | """ |
||
20 | bot.process_new_updates([types.Update.de_json(rq.stream.read().decode("utf-8"))]) |
||
21 | return "Ok", 200 |
||
22 | |||
23 | |||
24 | @bot_blueprint.route("/about") |
||
25 | def index(): |
||
26 | """ |
||
27 | Test functionality |
||
28 | :return: |
||
29 | """ |
||
30 | return {k: v for k, v in bot.get_me().__dict__.items() if v}, 200 |
||
31 | |||
32 | |||
33 | @bot_blueprint.route("/set") |
||
34 | def webhook(): |
||
35 | """ |
||
36 | Set telegram webhook |
||
37 | :return: |
||
38 | """ |
||
39 | app_site = rq.host |
||
40 | bot.remove_webhook() |
||
41 | bot.set_webhook(url=f"https://{app_site}/bot/{TOKEN}") |
||
42 | return "⚓ Webhook was set.", 200 |
||
43 | |||
44 | |||
45 | @bot_blueprint.route("/del") |
||
46 | def delete(): |
||
47 | """ |
||
48 | Delete telegram webhook |
||
49 | :return: |
||
50 | """ |
||
51 | bot.remove_webhook() |
||
52 | return "⚓ Webhook was deleted.", 200 |
||
53 |