mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
Added contacts list & GUI examples
This commit is contained in:
parent
9cc164b9ec
commit
8fe0c086bb
33
EXAMPLES.md
33
EXAMPLES.md
|
|
@ -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>
|
<a name="updates"></a>
|
||||||
### Monitor all Telegram events happening for the user
|
### Monitor all Telegram events happening for the user
|
||||||
|
|
||||||
|
|
|
||||||
2
FAQ.md
2
FAQ.md
|
|
@ -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.
|
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,
|
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>
|
<a name="access-hash"></a>
|
||||||
#### 4. Where to get the access_hash? Why the error `CHANNEL_INVALID` or `USER_ID_INVALID`?
|
#### 4. Where to get the access_hash? Why the error `CHANNEL_INVALID` or `USER_ID_INVALID`?
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
# How to use
|
# How to use
|
||||||
|
|
||||||
>⚠️ This library relies on asynchronous C# programming (`async/await`) so make sure you are familiar with this advanced topic before proceeding.
|
>⚠️ 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:
|
After installing WTelegramClient through Nuget, your first Console program will be as simple as:
|
||||||
```csharp
|
```csharp
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue