From 10e0e08bbb6513146dfc59acd22f4187db3bee85 Mon Sep 17 00:00:00 2001
From: Wizou <11647984+wiz0u@users.noreply.github.com>
Date: Wed, 30 Mar 2022 15:17:28 +0200
Subject: [PATCH] Examples for EntitiesTo* helpers
---
EXAMPLES.md | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/EXAMPLES.md b/EXAMPLES.md
index 81c45f0..eeba122 100644
--- a/EXAMPLES.md
+++ b/EXAMPLES.md
@@ -39,19 +39,23 @@ if (contacts.imported.Length > 0)
-### Send a Markdown or HTML-formatted message to ourself (Saved Messages)
+### Send an HTML/Markdown formatted message to ourself (Saved Messages)
```csharp
-// Markdown-style text:
-var text = $"Hello __dear *{Markdown.Escape(myself.first_name)}*__\n" +
- "Enjoy this `userbot` written with [WTelegramClient](https://github.com/wiz0u/WTelegramClient)";
-var entities = client.MarkdownToEntities(ref text);
-await client.SendMessageAsync(InputPeer.Self, text, entities: entities);
-
// HTML-formatted text:
-var text2 = $"Hello dear {HtmlText.Escape(myself.first_name)}\n" +
+var text = $"Hello dear {HtmlText.Escape(myself.first_name)}\n" +
"Enjoy this userbot written with WTelegramClient";
-var entities2 = client.HtmlToEntities(ref text2);
-await client.SendMessageAsync(InputPeer.Self, text2, entities: entities2);
+var entities = client.HtmlToEntities(ref text);
+var sent = await client.SendMessageAsync(InputPeer.Self, text, entities: entities);
+// if you need to convert a Message to HTML: (for easier storage)
+text = client.EntitiesToHtml(sent.message, sent.entities);
+
+// Markdown-style text:
+var text2 = $"Hello __dear *{Markdown.Escape(myself.first_name)}*__\n" +
+ "Enjoy this `userbot` written with [WTelegramClient](https://github.com/wiz0u/WTelegramClient)";
+var entities2 = client.MarkdownToEntities(ref text2);
+var sent2 = await client.SendMessageAsync(InputPeer.Self, text2, entities: entities2);
+// if you need to convert a Message to Markdown: (for easier storage)
+text2 = client.EntitiesToMarkdown(sent2.message, sent2.entities);
```
See [MarkdownV2 formatting style](https://core.telegram.org/bots/api/#markdownv2-style) and [HTML formatting style](https://core.telegram.org/bots/api/#html-style) for details.
*Note: For the `tg://user?id=` notation to work, that user's access hash must have been collected first ([see below](#collect-access-hash))*
@@ -411,7 +415,7 @@ foreach (var msg in messages.Messages)
If you don't want to store session data into files *(for example if your VPS Hosting doesn't allow that)*, or just for easier management,
you can choose to store the session data somewhere else, like in a database.
-The WTelegram.Client constructor takes an optional `sessionStore` parameter to allow storing sessions in a custom manner.
+The WTelegram.Client constructor takes an optional `sessionStore` parameter to allow storing sessions in an alternate manner.
Use it to pass a custom Stream-derived class that will **read** (first initial call to Length & Read) and **store** (subsequent Writes) session data to database.
You can find an example for such custom session store in [Examples/Program_Heroku.cs](https://github.com/wiz0u/WTelegramClient/blob/master/Examples/Program_Heroku.cs#L61)