Files
mautrix-telegram/pkg/gotd/telegram/message/html/html_example_test.go
T
2025-06-27 20:03:37 -07:00

53 lines
2.1 KiB
Go

package html_test
import (
"context"
"fmt"
"os"
"os/signal"
"go.mau.fi/mautrix-telegram/pkg/gotd/telegram"
"go.mau.fi/mautrix-telegram/pkg/gotd/telegram/message"
"go.mau.fi/mautrix-telegram/pkg/gotd/telegram/message/html"
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
)
func sendHTML(ctx context.Context) error {
client, err := telegram.ClientFromEnvironment(telegram.Options{})
if err != nil {
return err
}
// This example creates a styled message from BotAPI examples
// and sends to your Saved Messages folder.
// See https://core.telegram.org/bots/api#html-style.
return client.Run(ctx, func(ctx context.Context) error {
_, err := message.NewSender(tg.NewClient(client)).
Self().StyledText(ctx, html.String(nil, `<b>bold</b>, <strong>bold</strong>
<i>italic</i>, <em>italic</em>
<u>underline</u>, <ins>underline</ins>
<s>strikethrough</s>, <strike>strikethrough</strike>, <del>strikethrough</del>
<span class="tg-spoiler">spoiler</span>, <tg-spoiler>spoiler</tg-spoiler>
<b>bold <i>italic bold <s>italic bold strikethrough <span class="tg-spoiler">italic bold strikethrough spoiler</span></s> <u>underline italic bold</u></i> bold</b>
<a href="http://www.example.com/">inline URL</a>
<a href="tg://user?id=123456789">inline mention of a user</a>
<tg-emoji emoji-id="5368324170671202286">👍</tg-emoji>
<code>inline fixed-width code</code>
<pre>pre-formatted fixed-width code block</pre>
<pre><code class="language-python">pre-formatted fixed-width code block written in the Python programming language</code></pre>
<blockquote>Block quotation started\nBlock quotation continued\nThe last line of the block quotation</blockquote>
<blockquote expandable>Expandable block quotation started\nExpandable block quotation continued\nExpandable block quotation continued\nHidden by default part of the block quotation started\nExpandable block quotation continued\nThe last line of the block quotation</blockquote>`))
return err
})
}
func ExampleString() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
if err := sendHTML(ctx); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%+v\n", err)
os.Exit(2)
}
}