Skip to main content
Glama
main.go1.78 kB
package main import ( "context" "os" "os/signal" "strconv" "github.com/chaindead/telegram-mcp/internal/tg" "github.com/pkg/errors" "github.com/rs/zerolog" "github.com/rs/zerolog/log" ) func main() { zerolog.TimeFieldFormat = zerolog.TimeFormatUnix log.Logger = log.Output(zerolog.ConsoleWriter{ Out: os.Stderr, TimeFormat: zerolog.TimeFormatUnix, }) appIDStr, apiHash, sessionPath := os.Getenv("TG_APP_ID"), os.Getenv("TG_API_HASH"), os.Getenv("TG_SESSION_PATH") if appIDStr == "" { log.Fatal().Msg("TG_APP_ID is required") } if apiHash == "" { log.Fatal().Msg("TG_API_HASH is required") } if sessionPath == "" { log.Fatal().Msg("TG_SESSION_PATH is required") } appID, err := strconv.Atoi(appIDStr) if err != nil { log.Fatal().Err(err).Msg("TG_APP_ID app id") } ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) defer cancel() client := tg.New(appID, apiHash, sessionPath).T() if err := client.Run(ctx, func(ctx context.Context) error { self, err := client.Self(ctx) if err != nil { return errors.Wrap(err, "get self") } log.Info(). Str("first_name", self.FirstName). Str("last_name", self.LastName). Str("username", self.Username). Int64("id", self.ID). Msg("Logged in as") messages, err := getUnreadMessages(ctx, client) if err != nil { return errors.Wrap(err, "get unread messages") } for _, msg := range messages { log.Info(). Int("id", msg.ID). Str("text", msg.Text). Time("date", msg.Date). Int64("from_id", msg.FromID). Str("from_name", msg.FromName). Str("chat_type", msg.ChatType). Str("chat_title", msg.ChatTitle). Msg("Unread message") } return nil }); err != nil { log.Fatal().Err(err).Msg("client error") } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/chaindead/telegram-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server