Skip to content

Commit 80a1cbd

Browse files
committed
Small doc fixes.
1 parent a36ca53 commit 80a1cbd

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

docs/getting-started/README.md

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ approaches to solve common problems.
1010
## Installing
1111

1212
```bash
13-
go get -u github.com/go-telegram-bot-api/telegram-bot-api@develop
13+
go get -u github.com/go-telegram-bot-api/telegram-bot-api/v5@develop
1414
```
1515

1616
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].
3131
package main
3232

3333
import (
34-
"os"
34+
"os"
3535

36-
"github.com/go-telegram-bot-api/telegram-bot-api/v5"
36+
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
3737
)
3838

3939
func main() {
40-
bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_APITOKEN"))
41-
if err != nil {
42-
panic(err)
43-
}
40+
bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_APITOKEN"))
41+
if err != nil {
42+
panic(err)
43+
}
4444

45-
bot.Debug = true
45+
bot.Debug = true
4646
}
4747
```
4848

@@ -64,46 +64,46 @@ things. We can add this code in right after the line enabling debug mode.
6464
[get-me]: https://core.telegram.org/bots/api#getme
6565

6666
```go
67-
// Create a new UpdateConfig struct with an offset of 0. Offsets are used
68-
// to make sure Telegram knows we've handled previous values and we don't
69-
// need them repeated.
70-
updateConfig := tgbotapi.NewUpdate(0)
71-
72-
// Tell Telegram we should wait up to 30 seconds on each request for an
73-
// update. This way we can get information just as quickly as making many
74-
// frequent requests without having to send nearly as many.
75-
updateConfig.Timeout = 30
76-
77-
// Start polling Telegram for updates.
78-
updates := bot.GetUpdatesChan(updateConfig)
79-
80-
// Let's go through each update that we're getting from Telegram.
81-
for update := range updates {
82-
// Telegram can send many types of updates depending on what your Bot
83-
// is up to. We only want to look at messages for now, so we can
84-
// discard any other updates.
85-
if update.Message == nil {
86-
continue
87-
}
88-
89-
// Now that we know we've gotten a new message, we can construct a
90-
// reply! We'll take the Chat ID and Text from the incoming message
91-
// and use it to create a new message.
92-
msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text)
93-
// We'll also say that this message is a reply to the previous message.
94-
// For any other specifications than Chat ID or Text, you'll need to
95-
// set fields on the `MessageConfig`.
96-
msg.ReplyToMessageID = update.Message.MessageID
97-
98-
// Okay, we're sending our message off! We don't care about the message
99-
// we just sent, so we'll discard it.
100-
if _, err := bot.Send(msg); err != nil {
101-
// Note that panics are a bad way to handle errors. Telegram can
102-
// have service outages or network errors, you should retry sending
103-
// messages or more gracefully handle failures.
104-
panic(err)
105-
}
106-
}
67+
// Create a new UpdateConfig struct with an offset of 0. Offsets are used
68+
// to make sure Telegram knows we've handled previous values and we don't
69+
// need them repeated.
70+
updateConfig := tgbotapi.NewUpdate(0)
71+
72+
// Tell Telegram we should wait up to 30 seconds on each request for an
73+
// update. This way we can get information just as quickly as making many
74+
// frequent requests without having to send nearly as many.
75+
updateConfig.Timeout = 30
76+
77+
// Start polling Telegram for updates.
78+
updates := bot.GetUpdatesChan(updateConfig)
79+
80+
// Let's go through each update that we're getting from Telegram.
81+
for update := range updates {
82+
// Telegram can send many types of updates depending on what your Bot
83+
// is up to. We only want to look at messages for now, so we can
84+
// discard any other updates.
85+
if update.Message == nil {
86+
continue
87+
}
88+
89+
// Now that we know we've gotten a new message, we can construct a
90+
// reply! We'll take the Chat ID and Text from the incoming message
91+
// and use it to create a new message.
92+
msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text)
93+
// We'll also say that this message is a reply to the previous message.
94+
// For any other specifications than Chat ID or Text, you'll need to
95+
// set fields on the `MessageConfig`.
96+
msg.ReplyToMessageID = update.Message.MessageID
97+
98+
// Okay, we're sending our message off! We don't care about the message
99+
// we just sent, so we'll discard it.
100+
if _, err := bot.Send(msg); err != nil {
101+
// Note that panics are a bad way to handle errors. Telegram can
102+
// have service outages or network errors, you should retry sending
103+
// messages or more gracefully handle failures.
104+
panic(err)
105+
}
106+
}
107107
```
108108

109109
Congradulations! You've made your very own bot!

0 commit comments

Comments
 (0)