move gotd fork into repo. (#111)
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package message_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/styling"
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
||||
)
|
||||
|
||||
func sendStyledText(ctx context.Context) error {
|
||||
client, err := telegram.ClientFromEnvironment(telegram.Options{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// This example creates a big message with different style lines
|
||||
// and sends to your Saved Messages folder.
|
||||
return client.Run(ctx, func(ctx context.Context) error {
|
||||
formats := []message.StyledTextOption{
|
||||
styling.Plain("plaintext"), styling.Plain("\n\n"),
|
||||
styling.Mention("@durov"), styling.Plain("\n\n"),
|
||||
styling.Hashtag("#hashtag"), styling.Plain("\n\n"),
|
||||
styling.BotCommand("/command"), styling.Plain("\n\n"),
|
||||
styling.URL("https://google.org"), styling.Plain("\n\n"),
|
||||
styling.Email("example@example.org"), styling.Plain("\n\n"),
|
||||
styling.Bold("bold"), styling.Plain("\n\n"),
|
||||
styling.Italic("italic"), styling.Plain("\n\n"),
|
||||
styling.Underline("underline"), styling.Plain("\n\n"),
|
||||
styling.Strike("strike"), styling.Plain("\n\n"),
|
||||
styling.Code("fmt.Println(`Hello, World!`)"), styling.Plain("\n\n"),
|
||||
styling.Pre("fmt.Println(`Hello, World!`)", "Go"), styling.Plain("\n\n"),
|
||||
styling.TextURL("clickme", "https://google.com"), styling.Plain("\n\n"),
|
||||
styling.Phone("+71234567891"), styling.Plain("\n\n"),
|
||||
styling.Cashtag("$CASHTAG"), styling.Plain("\n\n"),
|
||||
styling.Blockquote("blockquote", false), styling.Plain("\n\n"),
|
||||
styling.BankCard("5550111111111111"), styling.Plain("\n\n"),
|
||||
}
|
||||
|
||||
_, err := message.NewSender(tg.NewClient(client)).
|
||||
Self().StyledText(ctx, formats...)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func ExampleBuilder_StyledText() {
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||
defer cancel()
|
||||
|
||||
if err := sendStyledText(ctx); err != nil {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "%+v\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user