mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
added User.MainUsername to help with multiple usernames
This commit is contained in:
parent
fd42d3e6df
commit
d9b137d41c
2
.github/dev.yml
vendored
2
.github/dev.yml
vendored
|
|
@ -2,7 +2,7 @@ pr: none
|
||||||
trigger:
|
trigger:
|
||||||
- master
|
- master
|
||||||
|
|
||||||
name: 3.0.2-dev.$(Rev:r)
|
name: 3.0.4-dev.$(Rev:r)
|
||||||
|
|
||||||
pool:
|
pool:
|
||||||
vmImage: ubuntu-latest
|
vmImage: ubuntu-latest
|
||||||
|
|
|
||||||
18
EXAMPLES.md
18
EXAMPLES.md
|
|
@ -7,7 +7,7 @@ using System.Linq;
|
||||||
using TL;
|
using TL;
|
||||||
|
|
||||||
using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
|
using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
|
||||||
var myself = await client.LoginUserIfNeeded();
|
await client.LoginUserIfNeeded();
|
||||||
```
|
```
|
||||||
|
|
||||||
In this case, environment variables are used for configuration so make sure to
|
In this case, environment variables are used for configuration so make sure to
|
||||||
|
|
@ -58,7 +58,7 @@ If the username is invalid/unused, the API call raises an RpcException.*
|
||||||
### Convert message to/from HTML or Markdown, and send it to ourself (Saved Messages)
|
### Convert message to/from HTML or Markdown, and send it to ourself (Saved Messages)
|
||||||
```csharp
|
```csharp
|
||||||
// HTML-formatted text:
|
// HTML-formatted text:
|
||||||
var text = $"Hello <u>dear <b>{HtmlText.Escape(myself.first_name)}</b></u>\n" +
|
var text = $"Hello <u>dear <b>{HtmlText.Escape(client.User.first_name)}</b></u>\n" +
|
||||||
"Enjoy this <code>userbot</code> written with <a href=\"https://github.com/wiz0u/WTelegramClient\">WTelegramClient</a>";
|
"Enjoy this <code>userbot</code> written with <a href=\"https://github.com/wiz0u/WTelegramClient\">WTelegramClient</a>";
|
||||||
var entities = client.HtmlToEntities(ref text);
|
var entities = client.HtmlToEntities(ref text);
|
||||||
var sent = await client.SendMessageAsync(InputPeer.Self, text, entities: entities);
|
var sent = await client.SendMessageAsync(InputPeer.Self, text, entities: entities);
|
||||||
|
|
@ -67,7 +67,7 @@ text = client.EntitiesToHtml(sent.message, sent.entities);
|
||||||
```
|
```
|
||||||
```csharp
|
```csharp
|
||||||
// Markdown-style text:
|
// Markdown-style text:
|
||||||
var text2 = $"Hello __dear *{Markdown.Escape(myself.first_name)}*__\n" +
|
var text2 = $"Hello __dear *{Markdown.Escape(client.User.first_name)}*__\n" +
|
||||||
"Enjoy this `userbot` written with [WTelegramClient](https://github.com/wiz0u/WTelegramClient)";
|
"Enjoy this `userbot` written with [WTelegramClient](https://github.com/wiz0u/WTelegramClient)";
|
||||||
var entities2 = client.MarkdownToEntities(ref text2);
|
var entities2 = client.MarkdownToEntities(ref text2);
|
||||||
var sent2 = await client.SendMessageAsync(InputPeer.Self, text2, entities: entities2);
|
var sent2 = await client.SendMessageAsync(InputPeer.Self, text2, entities: entities2);
|
||||||
|
|
@ -147,7 +147,7 @@ var participants = await client.Channels_GetAllParticipants(channel);
|
||||||
You can use specific filters, for example to list only the channel owner/admins:
|
You can use specific filters, for example to list only the channel owner/admins:
|
||||||
```csharp
|
```csharp
|
||||||
var participants = await client.Channels_GetParticipants(channel, filter: new ChannelParticipantsAdmins());
|
var participants = await client.Channels_GetParticipants(channel, filter: new ChannelParticipantsAdmins());
|
||||||
foreach (var participant in participants.participants) // This is the correct way to enumerate the result
|
foreach (var participant in participants.participants) // This is the better way to enumerate the result
|
||||||
{
|
{
|
||||||
var user = participants.users[participant.UserID];
|
var user = participants.users[participant.UserID];
|
||||||
if (participant is ChannelParticipantCreator cpc) Console.WriteLine($"{user} is the owner '{cpc.rank}'");
|
if (participant is ChannelParticipantCreator cpc) Console.WriteLine($"{user} is the owner '{cpc.rank}'");
|
||||||
|
|
@ -232,7 +232,7 @@ var inputMedias = new List<InputMedia>
|
||||||
{
|
{
|
||||||
photoFromTelegram, // PhotoBase has implicit conversion to InputMediaPhoto
|
photoFromTelegram, // PhotoBase has implicit conversion to InputMediaPhoto
|
||||||
new InputMediaUploadedPhoto { file = uploadedFile },
|
new InputMediaUploadedPhoto { file = uploadedFile },
|
||||||
new InputMediaPhotoExternal() { url = photoUrl },
|
new InputMediaPhotoExternal { url = photoUrl },
|
||||||
};
|
};
|
||||||
await client.SendAlbumAsync(InputPeer.Self, inputMedias, "My first album");
|
await client.SendAlbumAsync(InputPeer.Self, inputMedias, "My first album");
|
||||||
```
|
```
|
||||||
|
|
@ -349,7 +349,7 @@ var messages = await client.Messages_Search<InputMessagesFilterPinned>(chat, lim
|
||||||
foreach (var msg in messages.Messages)
|
foreach (var msg in messages.Messages)
|
||||||
await client.Messages_SendReaction(chat, msg.ID, reaction: new[] { reaction });
|
await client.Messages_SendReaction(chat, msg.ID, reaction: new[] { reaction });
|
||||||
```
|
```
|
||||||
*Note: you can find custom emoji document IDs via API methods like [Messages_GetFeaturedEmojiStickers](https://corefork.telegram.org/method/messages.getFeaturedEmojiStickers) or inspecting incoming messages. Access hash is not required*
|
*Note: you can find custom emoji document IDs via API methods like [Messages_GetFeaturedEmojiStickers](https://corefork.telegram.org/methods#working-with-custom-animated-emojis) or inspecting incoming messages. Access hash is not required*
|
||||||
|
|
||||||
|
|
||||||
<a name="join-channel"></a>
|
<a name="join-channel"></a>
|
||||||
|
|
@ -407,7 +407,7 @@ var contacts = await client.Contacts_ImportContacts(new[] { new InputPhoneContac
|
||||||
if (contacts.imported.Length > 0)
|
if (contacts.imported.Length > 0)
|
||||||
await client.SendMessageAsync(contacts.users[contacts.imported[0].user_id], "Hello!");
|
await client.SendMessageAsync(contacts.users[contacts.imported[0].user_id], "Hello!");
|
||||||
```
|
```
|
||||||
*Note: Don't use this method too much. To prevent spam, Telegram may restrict your ability to add new phone numbers.*
|
*Note: Don't use this method too much. To prevent spam, Telegram may restrict your ability to add new phone numbers or ban your account.*
|
||||||
|
|
||||||
<a name="contacts"></a>
|
<a name="contacts"></a>
|
||||||
### Retrieve the current user's contacts list
|
### Retrieve the current user's contacts list
|
||||||
|
|
@ -457,7 +457,7 @@ client.TcpHandler = async (address, port) =>
|
||||||
var proxy = new Socks5ProxyClient(ProxyHost, ProxyPort, ProxyUsername, ProxyPassword);
|
var proxy = new Socks5ProxyClient(ProxyHost, ProxyPort, ProxyUsername, ProxyPassword);
|
||||||
return proxy.CreateConnection(address, port);
|
return proxy.CreateConnection(address, port);
|
||||||
};
|
};
|
||||||
var myself = await client.LoginUserIfNeeded();
|
await client.LoginUserIfNeeded();
|
||||||
```
|
```
|
||||||
or with [xNetStandard](https://www.nuget.org/packages/xNetStandard/):
|
or with [xNetStandard](https://www.nuget.org/packages/xNetStandard/):
|
||||||
```csharp
|
```csharp
|
||||||
|
|
@ -472,7 +472,7 @@ MTProxy (MTProto proxy) can be used to prevent ISP blocking Telegram servers, th
|
||||||
```csharp
|
```csharp
|
||||||
using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
|
using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
|
||||||
client.MTProxyUrl = "http://t.me/proxy?server=...&port=...&secret=...";
|
client.MTProxyUrl = "http://t.me/proxy?server=...&port=...&secret=...";
|
||||||
var myself = await client.LoginUserIfNeeded();
|
await client.LoginUserIfNeeded();
|
||||||
```
|
```
|
||||||
You can find a list of working MTProxies in channels like [@ProxyMTProto](https://t.me/ProxyMTProto) or [@MTProxyT](https://t.me/MTProxyT) *(right-click the "Connect" buttons)*
|
You can find a list of working MTProxies in channels like [@ProxyMTProto](https://t.me/ProxyMTProto) or [@MTProxyT](https://t.me/MTProxyT) *(right-click the "Connect" buttons)*
|
||||||
If your Telegram client is already connected to such MTPROTO proxy, you can also export its URL by clicking on the shield button  and then **⋮** > **Share**
|
If your Telegram client is already connected to such MTPROTO proxy, you can also export its URL by clicking on the shield button  and then **⋮** > **Share**
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,7 @@ namespace TL
|
||||||
{
|
{
|
||||||
public override long ID => id;
|
public override long ID => id;
|
||||||
public override bool IsActive => (flags & Flags.deleted) == 0;
|
public override bool IsActive => (flags & Flags.deleted) == 0;
|
||||||
|
public string MainUsername => username ?? usernames?.FirstOrDefault(u => u.flags.HasFlag(Username.Flags.active))?.username;
|
||||||
public override string ToString() => username != null ? '@' + username : last_name == null ? first_name : $"{first_name} {last_name}";
|
public override string ToString() => username != null ? '@' + username : last_name == null ? first_name : $"{first_name} {last_name}";
|
||||||
public override InputPeer ToInputPeer() => new InputPeerUser(id, access_hash);
|
public override InputPeer ToInputPeer() => new InputPeerUser(id, access_hash);
|
||||||
protected override InputUser ToInputUser() => new(id, access_hash);
|
protected override InputUser ToInputUser() => new(id, access_hash);
|
||||||
|
|
|
||||||
|
|
@ -3207,7 +3207,7 @@ namespace TL
|
||||||
public DateTime date;
|
public DateTime date;
|
||||||
/// <summary>New profile photo</summary>
|
/// <summary>New profile photo</summary>
|
||||||
public UserProfilePhoto photo;
|
public UserProfilePhoto photo;
|
||||||
/// <summary>(<see cref="Bool.True"/>), if one of the previously used photos is set a profile photo.</summary>
|
/// <summary>(<see langword="true"/>), if one of the previously used photos is set a profile photo.</summary>
|
||||||
public bool previous;
|
public bool previous;
|
||||||
}
|
}
|
||||||
/// <summary>New encrypted message. <para>See <a href="https://corefork.telegram.org/constructor/updateNewEncryptedMessage"/></para></summary>
|
/// <summary>New encrypted message. <para>See <a href="https://corefork.telegram.org/constructor/updateNewEncryptedMessage"/></para></summary>
|
||||||
|
|
|
||||||
|
|
@ -290,7 +290,7 @@ namespace TL
|
||||||
/// <param name="no_muted">Avoid receiving (silent and invisible background) notifications. Useful to save battery.</param>
|
/// <param name="no_muted">Avoid receiving (silent and invisible background) notifications. Useful to save battery.</param>
|
||||||
/// <param name="token_type">Device token type, see <a href="https://corefork.telegram.org/api/push-updates#subscribing-to-notifications">PUSH updates</a> for the possible values.</param>
|
/// <param name="token_type">Device token type, see <a href="https://corefork.telegram.org/api/push-updates#subscribing-to-notifications">PUSH updates</a> for the possible values.</param>
|
||||||
/// <param name="token">Device token, see <a href="https://corefork.telegram.org/api/push-updates#subscribing-to-notifications">PUSH updates</a> for the possible values.</param>
|
/// <param name="token">Device token, see <a href="https://corefork.telegram.org/api/push-updates#subscribing-to-notifications">PUSH updates</a> for the possible values.</param>
|
||||||
/// <param name="app_sandbox">If <see cref="Bool.True"/> is transmitted, a sandbox-certificate will be used during transmission.</param>
|
/// <param name="app_sandbox">If <see langword="true"/> is transmitted, a sandbox-certificate will be used during transmission.</param>
|
||||||
/// <param name="secret">For FCM and APNS VoIP, optional encryption key used to encrypt push notifications</param>
|
/// <param name="secret">For FCM and APNS VoIP, optional encryption key used to encrypt push notifications</param>
|
||||||
/// <param name="other_uids">List of user identifiers of other users currently using the client</param>
|
/// <param name="other_uids">List of user identifiers of other users currently using the client</param>
|
||||||
public static Task<bool> Account_RegisterDevice(this Client client, int token_type, string token, bool app_sandbox, byte[] secret, long[] other_uids, bool no_muted = false)
|
public static Task<bool> Account_RegisterDevice(this Client client, int token_type, string token, bool app_sandbox, byte[] secret, long[] other_uids, bool no_muted = false)
|
||||||
|
|
@ -354,7 +354,7 @@ namespace TL
|
||||||
});
|
});
|
||||||
|
|
||||||
/// <summary>Updates online user status. <para>See <a href="https://corefork.telegram.org/method/account.updateStatus"/></para> <para>Possible <see cref="RpcException"/> codes: 403 (<a href="https://corefork.telegram.org/method/account.updateStatus#possible-errors">details</a>)</para></summary>
|
/// <summary>Updates online user status. <para>See <a href="https://corefork.telegram.org/method/account.updateStatus"/></para> <para>Possible <see cref="RpcException"/> codes: 403 (<a href="https://corefork.telegram.org/method/account.updateStatus#possible-errors">details</a>)</para></summary>
|
||||||
/// <param name="offline">If <see cref="Bool.True"/> is transmitted, user status will change to <see cref="UserStatusOffline"/>.</param>
|
/// <param name="offline">If <see langword="true"/> is transmitted, user status will change to <see cref="UserStatusOffline"/>.</param>
|
||||||
public static Task<bool> Account_UpdateStatus(this Client client, bool offline)
|
public static Task<bool> Account_UpdateStatus(this Client client, bool offline)
|
||||||
=> client.Invoke(new Account_UpdateStatus
|
=> client.Invoke(new Account_UpdateStatus
|
||||||
{
|
{
|
||||||
|
|
@ -1656,7 +1656,7 @@ namespace TL
|
||||||
|
|
||||||
/// <summary>Send typing event by the current user to a secret chat. <para>See <a href="https://corefork.telegram.org/method/messages.setEncryptedTyping"/></para> <para>Possible <see cref="RpcException"/> codes: 400 (<a href="https://corefork.telegram.org/method/messages.setEncryptedTyping#possible-errors">details</a>)</para></summary>
|
/// <summary>Send typing event by the current user to a secret chat. <para>See <a href="https://corefork.telegram.org/method/messages.setEncryptedTyping"/></para> <para>Possible <see cref="RpcException"/> codes: 400 (<a href="https://corefork.telegram.org/method/messages.setEncryptedTyping#possible-errors">details</a>)</para></summary>
|
||||||
/// <param name="peer">Secret chat ID</param>
|
/// <param name="peer">Secret chat ID</param>
|
||||||
/// <param name="typing">Typing.<br/><strong>Possible values</strong>:<br/><see cref="Bool.True"/>, if the user started typing and more than <strong>5 seconds</strong> have passed since the last request<br/><see cref="Bool.False"/>, if the user stopped typing</param>
|
/// <param name="typing">Typing.<br/><strong>Possible values</strong>:<br/><see langword="true"/>, if the user started typing and more than <strong>5 seconds</strong> have passed since the last request<br/><see langword="false"/>, if the user stopped typing</param>
|
||||||
public static Task<bool> Messages_SetEncryptedTyping(this Client client, InputEncryptedChat peer, bool typing)
|
public static Task<bool> Messages_SetEncryptedTyping(this Client client, InputEncryptedChat peer, bool typing)
|
||||||
=> client.Invoke(new Messages_SetEncryptedTyping
|
=> client.Invoke(new Messages_SetEncryptedTyping
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue