from aiogram import types
@dp.message_handler(content_types=types.ContentType.CONTACT)
async def handle_contact(message: types.Message):
user = message.contact
print(f"User ID: {user.user_id}")
print(f"Phone number: {user.phone_number}")
print(f"First name: {user.first_name}")
print(f"Last name: {user.last_name}")
# Save user data in a file or a database
with open('user_data.txt', 'w') as f:
f.write(f"User ID: {user.user_id}n")
f.write(f"Phone number: {user.phone_number}n")
f.write(f"First name: {user.first_name}n")
f.write(f"Last name: {user.last_name}n")