コード例 #1
0
def webhook(token: str):
    if not tokens.get(token):
        return abort(404)

    if request.headers.get('content-type') != 'application/json':
        return abort(403)

    json_string = request.get_data().decode('utf-8')
    update = types.Update.de_json(json_string)
    if token == main_bot.token:
        main_bot.process_new_updates([update])
        return ''

    from_update_bot = TeleBot(token)
    register_handlers(from_update_bot)
    from_update_bot.process_new_updates([update])
    return ''
コード例 #2
0
ファイル: bots.py プロジェクト: Leosimetti/EORA-internship
async def endpoint_for_bots(request: Request, userid: UUID4, token: str):
    user = await user_db.find_one({"id": UUID4(f"{userid}".replace("-", ""))})
    user_tokens = lambda: list(map(lambda x: x["token"], user["bots"]))

    if (user is not None) and (token in user_tokens()):
        sas = await request.body()
        decoded = json.loads(sas.decode())

        telegram_bot = TeleBot(token)

        @telegram_bot.message_handler()
        def echo(m: Message):
            telegram_bot.send_message(m.chat.id, m.text)

        telegram_bot.process_new_updates([Update.de_json(decoded)])

        return sas.decode()
    else:
        raise HTTPException(status_code=403,
                            detail="This bot is not allowed here!")