Go to file
2017-11-21 14:55:46 +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 NewBot, Settings, Poller, LongPoller - new bot creation API. 2017-11-21 01:41:39 +02:00
bot.go Command routing fix. 2017-11-21 14:40:49 +02:00
callbacks.go Massive refactoring and file structure changes. 2017-11-18 15:06:20 +02:00
chat.go Telebot now compiles! :-) 2017-11-18 16:44:57 +02:00
editable.go Cleanup, documentation, bikeshedding. 2017-11-19 17:21:25 +02:00
file.go Good news Edit() now works for all Editable text messages! 2017-11-18 20:47:04 +02:00
inline_types.go Documentation for newly introduced methods. 2016-11-10 20:05:52 +02:00
inline.go Cleanup, documentation, bikeshedding. 2017-11-19 17:21:25 +02:00
input_types.go Fixes lots of complete bollocks that got into the codebase. 2016-11-10 21:34:02 +02:00
LICENSE Initial commit 2015-06-25 22:27:50 +03:00
media.go Cleanup, documentation, bikeshedding. 2017-11-19 17:21:25 +02:00
message.go Documentation 2017-11-21 04:49:37 +02:00
options.go Cleanup, documentation, bikeshedding. 2017-11-19 17:21:25 +02:00
poller.go Routing: Handle() and Endpoint introduced. 2017-11-21 03:50:44 +02:00
README.md Re-writing README, stage 1. 2017-11-21 14:55:46 +02:00
sendable.go Cleanup, documentation, bikeshedding. 2017-11-19 17:21:25 +02:00
stickers.go Cleanup, documentation, bikeshedding. 2017-11-19 17:21:25 +02:00
telebot_test.go Fixing go test 2017-11-21 04:28:39 +02:00
telebot.go More documentation, little code changes. 2017-11-21 05:08:06 +02:00
util.go NewBot, Settings, Poller, LongPoller - new bot creation API. 2017-11-21 01:41:39 +02:00

Telebot

"I never knew creating bots in Telegram was so easy!"

GoDoc Travis

go get gopkg.in/tucnak/telebot.v2

Telebot is a bot framework for Telegram Bots API. This package provides a super convenient API for command routing, message and inline query requests, as well as callbacks. Actually, I went a couple steps further and instead of making a 1:1 API wrapper I focused on the beauty of API and bot performance. All the methods of telebot API are extremely easy to remember and later, get used to. Telebot is agnostic to the source of updates as long as it implements the Poller interface. Poller means you can plug your telebot into virtually any bot infrastructure, if you have any. Also, consider Telebot a highload-ready solution. I'll soon benchmark the most popular actions and if necessary, optimize against them without sacrificing API quality.

Take a look at the minimal telebot setup:

import (
    "time"
    tb "gopkg.in/tucnak/telebot.v2"
)

func main() {
    b, err := tb.NewBot(tb.Settings{
        Token: "TOKEN_HERE",
        Poller: &tb.LongPoller{10 * time.Second},
    })

    if err != nil {
        return
    }

    b.Handle("/hello", func(m *tb.Message) {
        b.Send(m.From, "hello world")
    }

    b.Start()
}

Simple, innit? Telebot's routing system takes care of deliviering updates to their "endpoints", so in order to get handle any meaningful event, all you have to do is just plug your handler to one of them endpoints and you're ready to go! You might want to switch-case handle more specific scenarios later.

b, _ := tb.NewBot(settings)

b.Handle("/help", func (m *Message) {
    // help command handler
}

b.Handle(tb.OnChannelPost, func (m *Message) {
    // channel post messages only
})

b.Handle(tb.Callback, func (c *Callback) {
    // incoming bot callbacks
})
}

Moreover, this API is completely extensible, so new handy endpoints might appear in the following minor versions of this package.

Inline mode

Docs TBA.

Files

Telebot allows to both upload (from disk / by URL) and download (from Telegram) and files in bot's scope. Telegram allows files up to 20 MB in size.

a := &tb.Audio{File: tb.FromDisk("file.ogg")}

fmt.Println(a.OnDisk()) // true
fmt.Println(a.InCloud()) // false

// Will upload the file from disk and send it to recipient
bot.Send(recipient, a)

// Next time you'll be sending this very *Audio, Telebot won't
// re-upload the same file but rather utilize its Telegram FileID
bot.Send(otherRecipient, a)

fmt.Println(a.OnDisk()) // true
fmt.Println(a.InCloud()) // true
fmt.Println(a.FileID) // <telegram file id: ABC-DEF1234ghIkl-zyx57W2v1u123ew11>

You might want to save certain files in order to avoid re-upploading. Feel free to marshal them into whatever format, File only contain public fields, so no data will ever be lost.

TBA.