Added contacts list & GUI examples

This commit is contained in:
Wizou 2021-12-16 14:41:43 +01:00
parent 9cc164b9ec
commit 8fe0c086bb
3 changed files with 35 additions and 2 deletions

View file

@ -191,6 +191,39 @@ for (int offset = 0; ;)
}
```
<a name="contacts"></a>
### Retrieve the current user's contacts list
There are two different methods. Here is the simpler one:
```csharp
using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
await client.LoginUserIfNeeded();
var contacts = await client.Contacts_GetContacts(0);
foreach (User contact in contacts.users.Values)
Console.WriteLine($"{contact} {contact.phone}");
```
<a name="takeout"></a>
The second method uses the more complex GDPR export, **takeout session** system.
Here is an example on how to implement it:
```csharp
using TL.Methods; // methods structures, for InvokeWithTakeout
using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
await client.LoginUserIfNeeded();
var takeout = await client.Account_InitTakeoutSession(contacts: true);
var finishTakeout = new Account_FinishTakeoutSession();
try
{
var savedContacts = await client.InvokeWithTakeout(takeout.id, new Contacts_GetSaved());
foreach (SavedPhoneContact contact in savedContacts)
Console.WriteLine($"{contact.first_name} {contact.last_name} {contact.phone}, added on {contact.date}");
finishTakeout.flags = Account_FinishTakeoutSession.Flags.success;
}
finally
{
await client.InvokeWithTakeout(takeout.id, finishTakeout);
}
```
<a name="updates"></a>
### Monitor all Telegram events happening for the user

2
FAQ.md
View file

@ -34,7 +34,7 @@ An easy solution is to call `Interaction.InputBox("Enter verification code")` in
This might require adding a reference *(and `using`)* to the Microsoft.VisualBasic assembly.
A more complex solution requires the use of a `ManualResetEventSlim` that you will wait for in Config callback,
and when the user has provided the verification_code through your GUI, you "set" the event to release your Config callback so it can return the code.
and when the user has provided the verification_code through your GUI, you "set" the event to release your Config callback so it can return the code. ([see example](https://stackoverflow.com/a/70379582/3365403))
<a name="access-hash"></a>
#### 4. Where to get the access_hash? Why the error `CHANNEL_INVALID` or `USER_ID_INVALID`?

View file

@ -10,7 +10,7 @@
# How to use
>⚠️ This library relies on asynchronous C# programming (`async/await`) so make sure you are familiar with this advanced topic before proceeding.
>If you are a beginner in C#, making a project based on this library might not be a great idea.
>If you are a beginner in C#, starting a project based on this library might not be a great idea.
After installing WTelegramClient through Nuget, your first Console program will be as simple as:
```csharp