Esempio n. 1
0
def get_telegram_user(message, create_new_user: bool) -> Optional[User]:
    telegram_id = message.from_user.id
    user = User.get_user_by_telegram_id(telegram_id=telegram_id)

    if not user:
        if create_new_user:
            first_name = message.from_user.first_name
            last_name = message.from_user.last_name

            user = User(
                user_id='',
                telegram_id=telegram_id,
                first_name=first_name,
                last_name=last_name,
            )
            user_id = user.add_to_db()
            init_user_state(user_id=user_id)
        else:
            return None

    return user
Esempio n. 2
0
def test_delete_and_add():
    u = User(user_id='', first_name='aa', last_name='bb', telegram_id='cc')
    u.add_to_db()
    print(u.user_id)
    assert DatastoreClient().get_client().collection(
        USERS_COLLECTION).document(u.user_id)