-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example code execution failed #3
Comments
example.go package main
import (
"fmt"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"time"
"log/slog"
slogtelegram "github.com/samber/slog-telegram/v2"
)
func main() {
token := "7294492055:AAEHDKzd1Yg8p3HuNBzOfaKV18v0D6YYwJ0"
username := "@slog_test"
logger := slog.New(slogtelegram.Option{Level: slog.LevelDebug, Token: token, Username: username, MessageConfigurator: Configurator}.NewTelegramHandler())
logger = logger.With("release", "v1.0.0")
logger.
With(
slog.Group("user",
slog.String("id", "user-123"),
slog.Time("created_at", time.Now().AddDate(0, 0, -1)),
),
).
With("environment", "dev").
With("error", fmt.Errorf("an error")).
Error("A message")
time.Sleep(10 * time.Second)
}
// Configurator Make the message support markdown
func Configurator(config tgbotapi.MessageConfig, attr []slog.Attr) tgbotapi.MessageConfig {
config.ParseMode = tgbotapi.ModeMarkdown
return config
} handler.go ...
func (h *TelegramHandler) Handle(ctx context.Context, record slog.Record) error {
message := h.option.Converter(h.option.AddSource, h.option.ReplaceAttr, h.attrs, h.groups, &record)
msg := tgbotapi.NewMessageToChannel(h.option.Username, message)
if h.option.MessageConfigurator != nil {
msg = h.option.MessageConfigurator(msg, h.attrs)
}
// non-blocking
go func() {
_, err := h.client.Send(msg)
fmt.Println(err)
}()
return nil
}
... output
|
Did you check the syntax of your message ? |
I'm running the example code of this repository. https://github.com/samber/slog-telegram/blob/main/example%2Fexample.go |
I made some tests and I think this is due to Can you confirm ? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Telegram bot api return error:
Bad Request: can't parse entities: Can't find end of the entity starting at byte offset 70
The text was updated successfully, but these errors were encountered: