package telegram import ( "fmt" "net/http" ) type Handlers struct { client *Client chatID int64 } func NewHandlers(client *Client, chatID int64) *Handlers { return &Handlers{ client: client, chatID: chatID, } } func (h *Handlers) HandleFragment(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") var content string var statusBadge string var openAttr string if h.client == nil { statusBadge = `Not Configured` content = `

Setup Instructions:

See full setup guide

` openAttr = " open" } else { bot, err := h.client.GetMe() if err != nil { statusBadge = `Error` content = fmt.Sprintf(`

Error: %s

`, err) openAttr = " open" } else if h.chatID == 0 { statusBadge = fmt.Sprintf(`Needs Chat ID@%s`, bot.Username) content = `

Complete Setup:

` openAttr = " open" } else { statusBadge = fmt.Sprintf(`Linked@%s`, bot.Username) content = `

Unlink Instructions:

` openAttr = "" } } html := fmt.Sprintf(`
Telegram %s
%s
`, openAttr, statusBadge, content) _, _ = fmt.Fprint(w, html) } func (h *Handlers) IsEnabled() bool { return true } func (h *Handlers) GetClient() *Client { return h.client }