Bots are special Telegram accounts designed to handle messages automatically. Users can interact with bots by sending them command messages in private or group chats. These accounts serve as an interface for code running somewhere on your server.
Bots are special Telegram accounts designed to handle messages automatically. Users can interact with bots
by sending them command messages in private or group chats. These accounts serve as an interface for
code running somewhere on your server.
Telebot offers a convenient wrapper to Bots API, so you shouldn't even
care about networking at all. You may install it with
bother about networking at all. You may install it with
go get github.com/tucnak/telebot
(after setting up your `GOPATH` properly).
Since you are probably
hosting your bot in a public repository, we'll add an environment
variable for the token in this example. Please set it with
We highly recommend you to keep your bot access token outside the code base,
preferably as an environmental variable:
export BOT_TOKEN=<yourtokenhere>
Here is an example "helloworld" bot, written with telebot:
Take a look at a minimal functional bot setup:
```go
package main
import (
"log"
"time"
"os"
"time"
"github.com/tucnak/telebot"
)
@ -38,7 +38,7 @@ func main() {
log.Fatalln(err)
}
messages := make(chan telebot.Message)
messages := make(chan telebot.Message, 100)
bot.Listen(messages, 1*time.Second)
for message := range messages {
@ -51,9 +51,8 @@ func main() {
```
## Inline mode
As of January 4, 2016, Telegram added inline mode support for bots.
Telebot support inline mode in a fancy manner. Here's a nice way to handle both incoming messages and inline queries:
As of January 4, 2016, Telegram added inline mode support for bots. Here's
a nice way to handle both incoming messages and inline queries in the meantime:
Sometimes you wanna send a little complicated messages with some optional parameters. The third argument of all `Send*` methods accepts `telebot.SendOptions`, capable of defining an advanced reply markup: