all repos — telegram-bot-api @ 80a1cbdb44925432834878e345d31cc4c3ad0094

Golang bindings for the Telegram Bot API

Small doc fixes.
Syfaro syfaro@huefox.com
Wed, 10 Mar 2021 16:47:14 -0500
commit

80a1cbdb44925432834878e345d31cc4c3ad0094

parent

a36ca539258ee740dc581ead09abafb622517621

1 files changed, 43 insertions(+), 43 deletions(-)

jump to
M docs/getting-started/README.mddocs/getting-started/README.md

@@ -10,7 +10,7 @@

## Installing ```bash -go get -u github.com/go-telegram-bot-api/telegram-bot-api@develop +go get -u github.com/go-telegram-bot-api/telegram-bot-api/v5@develop ``` It's currently suggested to use the develop branch. While there may be breaking

@@ -31,18 +31,18 @@ ```go

package main import ( - "os" + "os" - "github.com/go-telegram-bot-api/telegram-bot-api/v5" + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" ) func main() { - bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_APITOKEN")) - if err != nil { - panic(err) - } + bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_APITOKEN")) + if err != nil { + panic(err) + } - bot.Debug = true + bot.Debug = true } ```

@@ -64,46 +64,46 @@

[get-me]: https://core.telegram.org/bots/api#getme ```go - // Create a new UpdateConfig struct with an offset of 0. Offsets are used - // to make sure Telegram knows we've handled previous values and we don't - // need them repeated. - updateConfig := tgbotapi.NewUpdate(0) + // Create a new UpdateConfig struct with an offset of 0. Offsets are used + // to make sure Telegram knows we've handled previous values and we don't + // need them repeated. + updateConfig := tgbotapi.NewUpdate(0) - // Tell Telegram we should wait up to 30 seconds on each request for an - // update. This way we can get information just as quickly as making many - // frequent requests without having to send nearly as many. - updateConfig.Timeout = 30 + // Tell Telegram we should wait up to 30 seconds on each request for an + // update. This way we can get information just as quickly as making many + // frequent requests without having to send nearly as many. + updateConfig.Timeout = 30 - // Start polling Telegram for updates. - updates := bot.GetUpdatesChan(updateConfig) + // Start polling Telegram for updates. + updates := bot.GetUpdatesChan(updateConfig) - // Let's go through each update that we're getting from Telegram. - for update := range updates { - // Telegram can send many types of updates depending on what your Bot - // is up to. We only want to look at messages for now, so we can - // discard any other updates. - if update.Message == nil { - continue - } + // Let's go through each update that we're getting from Telegram. + for update := range updates { + // Telegram can send many types of updates depending on what your Bot + // is up to. We only want to look at messages for now, so we can + // discard any other updates. + if update.Message == nil { + continue + } - // Now that we know we've gotten a new message, we can construct a - // reply! We'll take the Chat ID and Text from the incoming message - // and use it to create a new message. - msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text) - // We'll also say that this message is a reply to the previous message. - // For any other specifications than Chat ID or Text, you'll need to - // set fields on the `MessageConfig`. - msg.ReplyToMessageID = update.Message.MessageID + // Now that we know we've gotten a new message, we can construct a + // reply! We'll take the Chat ID and Text from the incoming message + // and use it to create a new message. + msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text) + // We'll also say that this message is a reply to the previous message. + // For any other specifications than Chat ID or Text, you'll need to + // set fields on the `MessageConfig`. + msg.ReplyToMessageID = update.Message.MessageID - // Okay, we're sending our message off! We don't care about the message - // we just sent, so we'll discard it. - if _, err := bot.Send(msg); err != nil { - // Note that panics are a bad way to handle errors. Telegram can - // have service outages or network errors, you should retry sending - // messages or more gracefully handle failures. - panic(err) - } - } + // Okay, we're sending our message off! We don't care about the message + // we just sent, so we'll discard it. + if _, err := bot.Send(msg); err != nil { + // Note that panics are a bad way to handle errors. Telegram can + // have service outages or network errors, you should retry sending + // messages or more gracefully handle failures. + panic(err) + } + } ``` Congradulations! You've made your very own bot!