all repos — telegram-bot-api @ 1b2d9a5c42d5e37b9a38181fd5f273c6bda528d8

Golang bindings for the Telegram Bot API

README.md (view raw)

 1# Golang Telegram bindings for the 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 (including one I am developing myself) 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	updates, err := bot.UpdatesChan(u)
38
39	for update := range updates {
40		log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
41
42		msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text)
43		msg.ReplyToMessageID = update.Message.MessageID
44
45		bot.SendMessage(msg)
46	}
47}
48```