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
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
go get github.com/tucnak/telebot
(after setting up your `GOPATH` properly).
(after setting up your `GOPATH` properly).
Since you are probably
We highly recommend you to keep your bot access token outside the code base,
hosting your bot in a public repository, we'll add an environment
preferably as an environmental variable:
variable for the token in this example. Please set it with
export BOT_TOKEN=<yourtokenhere>
export BOT_TOKEN=<yourtokenhere>
Take a look at a minimal functional bot setup:
Here is an example "helloworld" bot, written with telebot:
```go
```go
package main
package main
import (
import (
"log"
"log"
"time"
"os"
"os"
"time"
"github.com/tucnak/telebot"
"github.com/tucnak/telebot"
)
)
@ -38,7 +38,7 @@ func main() {
log.Fatalln(err)
log.Fatalln(err)
}
}
messages := make(chan telebot.Message)
messages := make(chan telebot.Message, 100)
bot.Listen(messages, 1*time.Second)
bot.Listen(messages, 1*time.Second)
for message := range messages {
for message := range messages {
@ -51,9 +51,8 @@ func main() {
```
```
## Inline mode
## Inline mode
As of January 4, 2016, Telegram added inline mode support for bots. Here's
As of January 4, 2016, Telegram added inline mode support for bots.
a nice way to handle both incoming messages and inline queries in the meantime:
Telebot support inline mode in a fancy manner. Here's a nice way to handle both incoming messages and inline queries:
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:
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: