Passed
Push — master ( 653794...1bc565 )
by torrua
01:28
created

app.telegram_bot.routes   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 4

4 Functions

Rating   Name   Duplication   Size   Complexity  
A get_message() 0 8 1
A delete() 0 8 1
A index() 0 8 1
A webhook() 0 9 1
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.telegram_bot.bot import bot, APP_SITE, TOKEN
10
11
bot_routes = Blueprint("route", __name__)
12
13
14
@bot_routes.route(f"/telegram_bot/{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_routes.route("/telegram_bot/")
25
@bot_routes.route("/telegram_bot/heartbeat")
26
def index():
27
    """
28
    Test functionality
29
    :return:
30
    """
31
    return {k: v for k, v in bot.get_me().__dict__.items() if v}, 200
32
33
34
@bot_routes.route("/telegram_bot/set")
35
def webhook():
36
    """
37
    Set telegram webhook
38
    :return:
39
    """
40
    bot.remove_webhook()
41
    bot.set_webhook(url=f"https://{APP_SITE}/{TOKEN}")
42
    return "⚓ Webhook was set.", 200
43
44
45
@bot_routes.route("/telegram_bot/delete")
46
def delete():
47
    """
48
    Delete telegram webhook
49
    :return:
50
    """
51
    bot.remove_webhook()
52
    return "⚓ Webhook was deleted.", 200
53