From 80a1cbdb44925432834878e345d31cc4c3ad0094 Mon Sep 17 00:00:00 2001 From: Syfaro Date: Wed, 10 Mar 2021 16:47:14 -0500 Subject: [PATCH] Small doc fixes. --- docs/getting-started/README.md | 86 +++++++++++++++++----------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/docs/getting-started/README.md b/docs/getting-started/README.md index ca8e066..25c0f92 100644 --- a/docs/getting-started/README.md +++ b/docs/getting-started/README.md @@ -10,7 +10,7 @@ approaches to solve common problems. ## 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 @@ Let's start by constructing a new [BotAPI][bot-api-docs]. 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 @@ things. We can add this code in right after the line enabling debug mode. [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!