all repos — telegram-bot-api @ 92ad19733ba69ebe635916af04cf51ea6fd4a71b

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/src.foxpaw.in/Syfaro/telegram-bot-api?status.svg)](https://godoc.org/src.foxpaw.in/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
 8## Example
 9
10This is a very simple bot that just displays any gotten updates, then replies it to that chat.
11
12```go
13package main
14
15import (
16	"log"
17	"github.com/Syfaro/telegram-bot-api"
18)
19
20func main() {
21	bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken")
22	if err != nil {
23		log.Panic(err)
24	}
25
26	bot.Debug = true
27
28	log.Printf("Authorized on account %s", bot.Self.UserName)
29
30	u := tgbotapi.NewUpdate(0)
31	u.Timeout = 60
32
33	updates, err := bot.UpdatesChan(u)
34
35	for update := range updates {
36		log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
37
38		msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text)
39		msg.ReplyToMessageID = update.Message.MessageID
40
41		bot.SendMessage(msg)
42	}
43}
44```