all repos — telegram-bot-api @ 5a72ea681439dd22b56ea4c29bd8c58ef52dd751

Golang bindings for the Telegram Bot API

README.md (view raw)

 1# Golang bindings for the Telegram Bot API
 2
 3[![GoDoc](https://godoc.org/github.com/Syfaro/telegram-bot-api?status.svg)](http://godoc.org/github.com/Syfaro/telegram-bot-api)
 4
 5All methods have been added, and all features should be available.
 6If you want a feature that hasn't been added yet or something is broken, open an issue and I'll see what I can do.
 7
 8All methods are fairly self explanatory, and reading the godoc page should explain everything. If something isn't clear, open an issue or submit a pull request.
 9
10The scope of this project is just to provide a wrapper around the API without any additional features. There are other projects for creating something with plugins and command handlers without having to design all that yourself.
11
12## Example
13
14This is a very simple bot that just displays any gotten updates, then replies it to that chat.
15
16```go
17package main
18
19import (
20	"log"
21	"github.com/Syfaro/telegram-bot-api"
22)
23
24func main() {
25	bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken")
26	if err != nil {
27		log.Panic(err)
28	}
29
30	bot.Debug = true
31
32	log.Printf("Authorized on account %s", bot.Self.UserName)
33
34	u := tgbotapi.NewUpdate(0)
35	u.Timeout = 60
36
37	err = bot.UpdatesChan(u)
38	if err != nil {
39		log.Panic(err)
40	}
41
42	for update := range bot.Updates {
43		log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
44
45		msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text)
46		msg.ReplyToMessageID = update.Message.MessageID
47
48		bot.SendMessage(msg)
49	}
50}
51```