This is a maintained fork of go-telegram-bot-api that preserves the original design while staying current with the latest Telegram Bot API specifications. It continues the development of the original github.com/go-telegram-bot-api package.
- Complete coverage of the Telegram Bot API
- Simple and intuitive interface
- Minimal dependencies
- Production-ready and actively maintained
- Preserves original API structure for easy migration
Install the latest version:
go get -u github.com/OvyFlash/telegram-bot-api
❗ Tag versioning is discouraged due to the unstable nature of the Telegram Bot API, and it might break at any time after the API changes.
go get -u github.com/OvyFlash/telegram-bot-api/v7
Here's a simple echo bot using polling:
package main
import (
"log"
"time"
api "github.com/OvyFlash/telegram-bot-api"
)
func main() {
bot, err := api.NewBotAPI("BOT_TOKEN")
if err != nil {
panic(err)
}
log.Printf("Authorized on account %s", bot.Self.UserName)
updateConfig := api.NewUpdate(0)
updateConfig.Timeout = 60
updatesChannel := bot.GetUpdatesChan(updateConfig)
// Optional: Clear initial updates
time.Sleep(time.Millisecond * 500)
updatesChannel.Clear()
for update := range updatesChannel {
if update.Message == nil {
continue
}
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
msg := api.NewMessage(update.Message.Chat.ID, update.Message.Text)
msg.ReplyParameters.MessageID = update.Message.MessageID
bot.Send(msg)
}
}
For webhook implementation:
- Check the examples folder for examples of webhook implementations
- Use HTTPS (required by Telegram)
- Generate SSL certificate:
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 3560 -subj "//O=Org\CN=Test" -nodes
- Bring your own SSL certificate. Let's Encrypt is recommended for free TLS certificates in production.
- Issues and feature requests are welcome
- Pull requests should maintain the existing design philosophy
- The focus is on providing a clean API wrapper without additional features
The MIT License
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.