commit
44e25815ef
|
@ -0,0 +1,21 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2015 Syfaro
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
|
@ -1,10 +1,14 @@
|
||||||
# Golang Telegram bindings for the Bot API
|
# Golang Telegram bindings for the Bot API
|
||||||
|
|
||||||
[![GoDoc](https://godoc.org/src.foxpaw.in/Syfaro/telegram-bot-api?status.svg)](https://godoc.org/src.foxpaw.in/Syfaro/telegram-bot-api)
|
[![GoDoc](https://godoc.org/github.com/Syfaro/telegram-bot-api?status.svg)](http://godoc.org/github.com/Syfaro/telegram-bot-api)
|
||||||
|
|
||||||
All methods have been added, and all features should be available.
|
All methods have been added, and all features should be available.
|
||||||
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.
|
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.
|
||||||
|
|
||||||
|
All 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.
|
||||||
|
|
||||||
|
The 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.
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
This is a very simple bot that just displays any gotten updates, then replies it to that chat.
|
This is a very simple bot that just displays any gotten updates, then replies it to that chat.
|
||||||
|
@ -14,7 +18,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"src.foxpaw.in/Syfaro/telegram-bot-api"
|
"github.com/Syfaro/telegram-bot-api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
13
updates.go
13
updates.go
|
@ -1,5 +1,10 @@
|
||||||
package tgbotapi
|
package tgbotapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// UpdatesChan returns a chan that is called whenever a new message is gotten.
|
// UpdatesChan returns a chan that is called whenever a new message is gotten.
|
||||||
func (bot *BotAPI) UpdatesChan(config UpdateConfig) (chan Update, error) {
|
func (bot *BotAPI) UpdatesChan(config UpdateConfig) (chan Update, error) {
|
||||||
bot.Updates = make(chan Update, 100)
|
bot.Updates = make(chan Update, 100)
|
||||||
|
@ -8,7 +13,15 @@ func (bot *BotAPI) UpdatesChan(config UpdateConfig) (chan Update, error) {
|
||||||
for {
|
for {
|
||||||
updates, err := bot.GetUpdates(config)
|
updates, err := bot.GetUpdates(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if bot.Debug {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
} else {
|
||||||
|
log.Println(err)
|
||||||
|
log.Println("Failed to get updates, retrying in 3 seconds...")
|
||||||
|
time.Sleep(time.Second * 3)
|
||||||
|
}
|
||||||
|
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, update := range updates {
|
for _, update := range updates {
|
||||||
|
|
Loading…
Reference in New Issue