@Memmo's answer is great and put me in the right direction. However, the script does not work anymore, because the indention was changing for Telegram exports. Also I wanted a version that works for all country origins. My output CSV can also be imported into Google Contacts without the necessary step to convert it to the VCard. Here is my modified version:
import re
pathToFile = 'lists/contacts.html'
with open(pathToFile, encoding='utf-8') as f:
lines = tuple(l for l in f.readlines())
with open('csvToConvert.csv', "w", encoding="utf-8") as outputFile:
outputFile.write('Name,Group Membership,Phone 1 - Type,Phone 1 - Value\n')
for i,l in enumerate(lines):
if '<div class="name bold">' in l and '<div class="details_entry details">' in lines[i+4]:
tel = re.sub('^00', '+', lines[i+5].replace(' ','').replace('\n',''))
outputFile.write(lines[i+1].replace('\n','') + ',* myContacts,,' + tel + '\n')
The data export can be found in Telegram Desktop in Settings > Advanced. The script above needs to be located in the resulting Data Export folder and needs to be run by Python3.
My final step was to merge the contacts using Merge + on my mobile after sync, because the script will make one entry per number, not per contact.