Go to file
2015-12-05 11:40:55 +02:00
.gitignore Initial commit 2015-06-25 22:27:50 +03:00
.travis.yml Merging #20 into tucnak:master from aladine:patch-3 2015-10-16 19:36:20 +03:00
api.go Tiny code changes 2015-11-16 12:22:37 +02:00
bot.go Tiny code changes 2015-11-16 12:22:37 +02:00
file.go Getting rid of excessive error types, switching to fmt.Errorf 2015-10-15 18:17:09 +03:00
LICENSE Initial commit 2015-06-25 22:27:50 +03:00
message.go Fixing #21 issue, introducing Recipient interface 2015-10-17 01:36:07 +03:00
options.go Typo fix in ReplyMarkup structure 2015-10-13 17:33:14 +03:00
README.md Fix README example 2015-11-03 18:12:22 +03:00
telebot_test.go Fixing #21 issue, introducing Recipient interface 2015-10-17 01:36:07 +03:00
telebot.go Chat actions implemented 2015-07-06 19:15:59 +03:00
types.go Fixing critical API issue; resolves #26 2015-12-05 11:40:55 +02:00

Telebot

Telebot is a convenient wrapper to Telegram Bots API, written in Golang.

GoDoc Travis

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. Here is an example "helloworld" bot, written with telebot:

import (
    "time"
    "github.com/tucnak/telebot"
)

func main() {
    bot, err := telebot.NewBot("SECRET TOKEN")
    if err != nil {
        return
    }

    messages := make(chan telebot.Message)
    bot.Listen(messages, 1*time.Second)

    for message := range messages {
        if message.Text == "/hi" {
            bot.SendMessage(message.Chat,
                "Hello, "+message.Sender.FirstName+"!", nil)
        }
    }
}

You can also send any kind of resources from file system easily:

boom, err := telebot.NewFile("boom.ogg")
if err != nil {
    return err
}

audio := telebot.Audio{File: boom}

// Next time you send &audio, telebot won't issue
// an upload, but would re-use existing file.
err = bot.SendAudio(recipient, &audio, nil)

Sometimes you might want to send a little bit complicated messages, with some optional parameters:

// Send a selective force reply message.
bot.SendMessage(user, "pong", &telebot.SendOptions{
        ReplyMarkup: telebot.ReplyMarkup{
            ForceReply: true,
            Selective: true,
        },
    },
)