|
1 | 1 | # Golang bindings for the Telegram Bot API |
2 | 2 |
|
3 | 3 | [](http://godoc.org/github.com/Syfaro/telegram-bot-api) |
| 4 | +[](https://travis-ci.org/Syfaro/telegram-bot-api) |
4 | 5 |
|
5 | 6 | All methods have been added, and all features should be available. |
6 | 7 | If 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. |
@@ -34,18 +35,15 @@ func main() { |
34 | 35 | u := tgbotapi.NewUpdate(0) |
35 | 36 | u.Timeout = 60 |
36 | 37 |
|
37 | | - err = bot.UpdatesChan(u) |
38 | | - if err != nil { |
39 | | - log.Panic(err) |
40 | | - } |
| 38 | + updates, err := bot.GetUpdatesChan(u) |
41 | 39 |
|
42 | | - for update := range bot.Updates { |
| 40 | + for update := range updates { |
43 | 41 | log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text) |
44 | 42 |
|
45 | 43 | msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text) |
46 | 44 | msg.ReplyToMessageID = update.Message.MessageID |
47 | 45 |
|
48 | | - bot.SendMessage(msg) |
| 46 | + bot.Send(msg) |
49 | 47 | } |
50 | 48 | } |
51 | 49 | ``` |
@@ -76,15 +74,15 @@ func main() { |
76 | 74 | log.Fatal(err) |
77 | 75 | } |
78 | 76 |
|
79 | | - bot.ListenForWebhook("/"+bot.Token) |
| 77 | + updates, _ := bot.ListenForWebhook("/" + bot.Token) |
80 | 78 | go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil) |
81 | 79 |
|
82 | | - for update := range bot.Updates { |
| 80 | + for update := range updates { |
83 | 81 | log.Printf("%+v\n", update) |
84 | 82 | } |
85 | 83 | } |
86 | 84 | ``` |
87 | 85 |
|
88 | 86 | If you need, you may generate a self signed certficate, as this requires HTTPS / TLS. The above example tells Telegram that this is your certificate and that it should be trusted, even though it is not properly signed. |
89 | 87 |
|
90 | | - openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 3560 -subj -nodes |
| 88 | + openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 3560 -subj "//O=Org\CN=Test" -nodes |
0 commit comments