mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
ToString for SendMessageAction
This commit is contained in:
parent
b01eed2042
commit
2520a57f20
|
|
@ -24,7 +24,7 @@ namespace WTelegramClientTest
|
||||||
await client.ConnectAsync();
|
await client.ConnectAsync();
|
||||||
var my = await client.LoginUserIfNeeded();
|
var my = await client.LoginUserIfNeeded();
|
||||||
users[my.id] = my;
|
users[my.id] = my;
|
||||||
// note that on logging, Telegram may sends a bunch of updates/messages that happened in the past and were not acknowledged
|
// note that on login Telegram may sends a bunch of updates/messages that happened in the past and were not acknowledged
|
||||||
Console.WriteLine($"We are logged-in as {my.username ?? my.first_name + " " + my.last_name} (id {my.id})");
|
Console.WriteLine($"We are logged-in as {my.username ?? my.first_name + " " + my.last_name} (id {my.id})");
|
||||||
var dialogsBase = await client.Messages_GetDialogs(default, 0, null, 0, 0);
|
var dialogsBase = await client.Messages_GetDialogs(default, 0, null, 0, 0);
|
||||||
if (dialogsBase is Messages_Dialogs dialogs)
|
if (dialogsBase is Messages_Dialogs dialogs)
|
||||||
|
|
@ -46,7 +46,7 @@ namespace WTelegramClientTest
|
||||||
private static readonly Dictionary<long, UserBase> users = new();
|
private static readonly Dictionary<long, UserBase> users = new();
|
||||||
private static readonly Dictionary<long, ChatBase> chats = new();
|
private static readonly Dictionary<long, ChatBase> chats = new();
|
||||||
private static string AUser(long user_id) => users.TryGetValue(user_id, out var user) ? user.DisplayName : $"User {user_id}";
|
private static string AUser(long user_id) => users.TryGetValue(user_id, out var user) ? user.DisplayName : $"User {user_id}";
|
||||||
private static string AChat(long chat_id) => chats.TryGetValue(chat_id, out var chat) ? chat.Title : $"Chat {chat_id}";
|
private static string AChat(long chat_id) => chats.TryGetValue(chat_id, out var chat) ? chat.ToString() : $"Chat {chat_id}";
|
||||||
private static string APeer(Peer peer) => peer is null ? null : peer is PeerUser user ? AUser(user.user_id)
|
private static string APeer(Peer peer) => peer is null ? null : peer is PeerUser user ? AUser(user.user_id)
|
||||||
: peer is PeerChat chat ? AChat(chat.chat_id) : peer is PeerChannel channel ? AChat(channel.channel_id) : $"Peer {peer.ID}";
|
: peer is PeerChat chat ? AChat(chat.chat_id) : peer is PeerChannel channel ? AChat(channel.channel_id) : $"Peer {peer.ID}";
|
||||||
|
|
||||||
|
|
@ -80,9 +80,9 @@ namespace WTelegramClientTest
|
||||||
case UpdateEditMessage uem: Console.Write("(Edit): "); DisplayMessage(uem.message); break;
|
case UpdateEditMessage uem: Console.Write("(Edit): "); DisplayMessage(uem.message); break;
|
||||||
case UpdateDeleteChannelMessages udcm: Console.WriteLine($"{udcm.messages.Length} message(s) deleted in {AChat(udcm.channel_id)}"); break;
|
case UpdateDeleteChannelMessages udcm: Console.WriteLine($"{udcm.messages.Length} message(s) deleted in {AChat(udcm.channel_id)}"); break;
|
||||||
case UpdateDeleteMessages udm: Console.WriteLine($"{udm.messages.Length} message(s) deleted"); break;
|
case UpdateDeleteMessages udm: Console.WriteLine($"{udm.messages.Length} message(s) deleted"); break;
|
||||||
case UpdateUserTyping uut: Console.WriteLine($"{AUser(uut.user_id)} is {uut.action.GetType().Name[11..^6]}"); break;
|
case UpdateUserTyping uut: Console.WriteLine($"{AUser(uut.user_id)} is {uut.action}"); break;
|
||||||
case UpdateChatUserTyping ucut: Console.WriteLine($"{APeer(ucut.from_id)} is {ucut.action.GetType().Name[11..^6]} in {AChat(ucut.chat_id)}"); break;
|
case UpdateChatUserTyping ucut: Console.WriteLine($"{APeer(ucut.from_id)} is {ucut.action} in {AChat(ucut.chat_id)}"); break;
|
||||||
case UpdateChannelUserTyping ucut2: Console.WriteLine($"{APeer(ucut2.from_id)} is {ucut2.action.GetType().Name[11..^6]} in {AChat(ucut2.channel_id)}"); break;
|
case UpdateChannelUserTyping ucut2: Console.WriteLine($"{APeer(ucut2.from_id)} is {ucut2.action} in {AChat(ucut2.channel_id)}"); break;
|
||||||
case UpdateChatParticipants { participants: ChatParticipants cp }: Console.WriteLine($"{cp.participants.Length} participants in {AChat(cp.chat_id)}"); break;
|
case UpdateChatParticipants { participants: ChatParticipants cp }: Console.WriteLine($"{cp.participants.Length} participants in {AChat(cp.chat_id)}"); break;
|
||||||
case UpdateUserStatus uus: Console.WriteLine($"{AUser(uus.user_id)} is now {uus.status.GetType().Name[10..]}"); break;
|
case UpdateUserStatus uus: Console.WriteLine($"{AUser(uus.user_id)} is now {uus.status.GetType().Name[10..]}"); break;
|
||||||
case UpdateUserName uun: Console.WriteLine($"{AUser(uun.user_id)} has changed profile name: @{uun.username} {uun.first_name} {uun.last_name}"); break;
|
case UpdateUserName uun: Console.WriteLine($"{AUser(uun.user_id)} has changed profile name: @{uun.username} {uun.first_name} {uun.last_name}"); break;
|
||||||
|
|
|
||||||
14
README.md
14
README.md
|
|
@ -1,7 +1,7 @@
|
||||||
[](https://www.nuget.org/packages/WTelegramClient/)
|
[](https://www.nuget.org/packages/WTelegramClient/)
|
||||||
[](https://dev.azure.com/wiz0u/WTelegramClient/_packaging?_a=package&feed=WTelegramClient&package=WTelegramClient&protocolType=NuGet)
|
[](https://dev.azure.com/wiz0u/WTelegramClient/_packaging?_a=package&feed=WTelegramClient&package=WTelegramClient&protocolType=NuGet)
|
||||||
[](https://dev.azure.com/wiz0u/WTelegramClient/_build?definitionId=7)
|
[](https://dev.azure.com/wiz0u/WTelegramClient/_build?definitionId=7)
|
||||||
[](https://schema.horner.tj)
|
[](https://corefork.telegram.org/methods)
|
||||||
[](https://t.me/WTelegramClient)
|
[](https://t.me/WTelegramClient)
|
||||||
|
|
||||||
# <img src="logo.png" width="32"/> WTelegramClient
|
# <img src="logo.png" width="32"/> WTelegramClient
|
||||||
|
|
@ -27,7 +27,7 @@ Then it will attempt to sign-in as a user for which you must enter the **phone_n
|
||||||
|
|
||||||
If the verification succeeds but the phone number is unknown to Telegram, the user might be prompted to sign-up (accepting the Terms of Service) and enter their **first_name** and **last_name**.
|
If the verification succeeds but the phone number is unknown to Telegram, the user might be prompted to sign-up (accepting the Terms of Service) and enter their **first_name** and **last_name**.
|
||||||
|
|
||||||
And that's it, you now have access to the [full range of Telegram services](https://core.telegram.org/methods), mainly through calls to `await client.Some_TL_Method(...)`
|
And that's it, you now have access to the [full range of Telegram services](https://corefork.telegram.org/methods), mainly through calls to `await client.Some_TL_Method(...)`
|
||||||
|
|
||||||
# Saved session
|
# Saved session
|
||||||
If you run this program again, you will notice that only **api_id** and **api_hash** are requested, the other prompts are gone and you are automatically logged-on and ready to go.
|
If you run this program again, you will notice that only **api_id** and **api_hash** are requested, the other prompts are gone and you are automatically logged-on and ready to go.
|
||||||
|
|
@ -64,12 +64,12 @@ Its `int` argument is the log severity, compatible with the classic [LogLevel en
|
||||||
|
|
||||||
ℹ️ The Telegram API makes extensive usage of base and derived classes, so be ready to use the various syntaxes C# offer to check/cast base classes into the more useful derived classes (`is`, `as`, `case DerivedType` )
|
ℹ️ The Telegram API makes extensive usage of base and derived classes, so be ready to use the various syntaxes C# offer to check/cast base classes into the more useful derived classes (`is`, `as`, `case DerivedType` )
|
||||||
|
|
||||||
To find which derived classes are available for a given base class, the fastest is to check our [TL.Schema.cs](src/TL.Schema.cs) source file as they are listed in groups.
|
To find which derived classes are available for a given base class, the fastest is to check our [TL.Schema.cs](https://github.com/wiz0u/WTelegramClient/blob/master/src/TL.Schema.cs) source file as they are listed in groups.
|
||||||
Intellisense tooltips on API structures/methods will also display a web link to the adequate Telegram documentation page.
|
Intellisense tooltips on API structures/methods will also display a web link to the adequate Telegram documentation page.
|
||||||
|
|
||||||
The Telegram [API object classes](https://core.telegram.org/schema) are defined in the `TL` namespace, and the [API functions](https://core.telegram.org/methods) are available as async methods of `Client`.
|
The Telegram [API object classes](https://corefork.telegram.org/schema) are defined in the `TL` namespace, and the [API functions](https://corefork.telegram.org/methods) are available as async methods of `Client`.
|
||||||
|
|
||||||
Below is an example of calling the [messages.getAllChats](https://core.telegram.org/method/messages.getAllChats) API function and enumerating the various groups/channels the user is in, and then using `client.SendMessageAsync` helper function to easily send a message:
|
Below is an example of calling the [messages.getAllChats](https://corefork.telegram.org/method/messages.getAllChats) API function and enumerating the various groups/channels the user is in, and then using `client.SendMessageAsync` helper function to easily send a message:
|
||||||
```csharp
|
```csharp
|
||||||
using TL;
|
using TL;
|
||||||
...
|
...
|
||||||
|
|
@ -98,7 +98,7 @@ await client.SendMessageAsync(target, "Hello, World");
|
||||||
|
|
||||||
The Client class also offers an `Update` event that is triggered when Telegram servers sends unsollicited Updates or notifications/information/status/service messages, independently of your API requests.
|
The Client class also offers an `Update` event that is triggered when Telegram servers sends unsollicited Updates or notifications/information/status/service messages, independently of your API requests.
|
||||||
|
|
||||||
An invalid API request can result in a `RpcException` being raised, reflecting the [error code and status text](https://core.telegram.org/api/errors) of the problem.
|
An invalid API request can result in a `RpcException` being raised, reflecting the [error code and status text](https://revgram.github.io/errors.html) of the problem.
|
||||||
|
|
||||||
The other configuration items that you can override include: **session_pathname, server_address, device_model, system_version, app_version, system_lang_code, lang_pack, lang_code, user_id**
|
The other configuration items that you can override include: **session_pathname, server_address, device_model, system_version, app_version, system_lang_code, lang_pack, lang_code, user_id**
|
||||||
|
|
||||||
|
|
@ -106,7 +106,7 @@ Optional API parameters have a default value of `null` when unset. Passing `null
|
||||||
|
|
||||||
I've added several useful converters or implicit cast to various API object so that they are more easy to manipulate.
|
I've added several useful converters or implicit cast to various API object so that they are more easy to manipulate.
|
||||||
|
|
||||||
Beyond the TL async methods, the Client class offers a few other methods to simplify the sending of files, medias or messages.
|
Beyond the TL async methods, the Client class offers a few other methods to simplify the sending/receiving of files, medias or messages.
|
||||||
|
|
||||||
This library works best with **.NET 5.0+** and is also available for **.NET Standard 2.0** (.NET Framework 4.6.1+ & .NET Core 2.0+)
|
This library works best with **.NET 5.0+** and is also available for **.NET Standard 2.0** (.NET Framework 4.6.1+ & .NET Core 2.0+)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -279,4 +279,23 @@ namespace TL
|
||||||
return sb.Append('}').ToString();
|
return sb.Append('}').ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
partial class SendMessageAction
|
||||||
|
{
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
var type = GetType().Name[11..^6];
|
||||||
|
for (int i = 1; i < type.Length; i++)
|
||||||
|
if (char.IsUpper(type[i]))
|
||||||
|
return type.ToLowerInvariant().Insert(i, "ing ");
|
||||||
|
return type.ToLowerInvariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
partial class SpeakingInGroupCallAction { public override string ToString() => "speaking in group call"; }
|
||||||
|
partial class SendMessageTypingAction { public override string ToString() => "typing"; }
|
||||||
|
partial class SendMessageCancelAction { public override string ToString() => "stopping"; }
|
||||||
|
partial class SendMessageGeoLocationAction { public override string ToString() => "selecting a location"; }
|
||||||
|
partial class SendMessageGamePlayAction { public override string ToString() => "playing a game"; }
|
||||||
|
partial class SendMessageHistoryImportAction{ public override string ToString() => "importing history"; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue