Esempio n. 1
0
 def on_post(self, req: falcon.Request, resp: falcon.Response):
     for message in req.media:
         chats = Chat.get_chats_by_token(message.get('token'))
         for chat in chats:
             send_message(chat, message.get('text'),
                          message.get('disable_notification'))
     resp.status = falcon.HTTP_200
Esempio n. 2
0
def _set_token(message):
    text_split = message.text.split()
    if len(text_split) != 2:
        return

    token = text_split[1]
    chat = Chat.set_token(message.chat.id, token)

    send_message(chat, 'New token {}'.format(chat.token))
Esempio n. 3
0
    def on_get(self, req: falcon.Request, resp: falcon.Response):
        token = req.params.get('token')
        if token is None:
            raise falcon.HTTP_BAD_REQUEST

        text = req.params.get('text')
        if text is None:
            raise falcon.HTTP_BAD_REQUEST

        disable_notification = req.params.get('disable_notification', False)

        chats = Chat.get_chats_by_token(token)
        for chat in chats:
            send_message(chat, text, disable_notification)

        resp.status = falcon.HTTP_200
Esempio n. 4
0
def chat():
    return Chat.get_chat(123)
Esempio n. 5
0
def test_get_chats_by_token(chat):
    obj = Chat.get_chats_by_token(chat.token)

    assert chat in obj
Esempio n. 6
0
def test_get_token():
    token = Chat.get_token(123)

    assert isinstance(token, str)
    assert len(token) == 32
Esempio n. 7
0
def test_set_token(random_token):
    Chat.set_token(123, random_token)
    chat = Chat.get_chat(123)

    assert chat.token == random_token
Esempio n. 8
0
def test_get_chat():
    chat = Chat.get_chat(123)

    assert isinstance(chat, Chat)
    assert chat.id == 123
Esempio n. 9
0
def _send_token(message):
    chat = Chat.get_chat(message.chat.id)
    send_message(chat, chat.token)