![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
github.com/raminsa/telegram_api
The Telegram Bot API provides an HTTP API for creating Telegram Bots.
If you've got any questions about bots or would like to report an issue with your bot, kindly contact us at @BotSupport in Telegram.
Please note that only global Bot API issues that affect all bots are suitable for this repository.
To learn how to use it, please see our examples.
Bot API 7.7 recent changes July 7, 2024.
go get github.com/raminsa/telegram-bot-api
.
See Bots: An introduction for developers for a brief description of Telegram Bots and their features.
See the Telegram Bot API documentation for a description of the Bot API interface and a complete list of available classes, methods and updates.
See the Telegram Bot API server build instruction generator for detailed instructions on how to build the Telegram Bot API server.
Subscribe to @BotNews to be the first to know about the latest updates and join the discussion in @BotTalk.
use get update method (simple):
package main
import (
"fmt"
"log"
"github.com/raminsa/telegram-bot-api/telegram"
)
func main() {
tg, err := telegram.New("BotToken")
if err != nil {
log.Fatal(err)
}
getUpdates := tg.NewGetUpdates()
getUpdates.Offset = 1
getUpdates.Timeout = 60
getUpdates.Limit = 100
updates := tg.GetUpdatesChan(getUpdates)
for update := range updates {
fmt.Println(update.UpdateID, getUpdates.Offset)
if update.UpdateID >= getUpdates.Offset {
getUpdates.Offset = update.UpdateID + 1
}
if update.Message != nil {
fmt.Println(update.Message.Text)
}
}
}
use webhook method (http):
package main
import (
"fmt"
"log"
"net/http"
"github.com/raminsa/telegram-bot-api/telegram"
)
func main() {
fmt.Println("start at port:", "BotPortNumber")
err := http.ListenAndServe("BotPortNumber", http.HandlerFunc(handleWebhook))
if err != nil {
log.Fatal(err)
}
}
func handleWebhook(w http.ResponseWriter, r *http.Request) {
update, err := telegram.HandleUpdate(r)
if err != nil {
err = telegram.HandleUpdateError(w, err)
if err != nil {
//handle err
}
return
}
if update.Message != nil {
fmt.Println(update.Message.Text)
}
}
use webhook method (https):
package main
import (
"fmt"
"log"
"net/http"
"github.com/raminsa/telegram-bot-api/telegram"
)
func main() {
fmt.Println("start at port:", "BotPortNumber")
err := http.ListenAndServeTLS("BotPortNumber", "BotCertFile", "BotKeyFile", http.HandlerFunc(handleWebhook))
if err != nil {
log.Fatal(err)
}
}
func handleWebhook(w http.ResponseWriter, r *http.Request) {
update, err := telegram.HandleUpdate(r)
if err != nil {
err := telegram.HandleUpdateError(w, err)
if err != nil {
//handle err
}
return
}
if update.Message != nil {
fmt.Println(update.Message.Text)
}
}
to generate your cert file use this. See self-signed guide for details.:
openssl req -newkey rsa:2048 -sha256 -nodes -keyout <file.key> -x509 -days 36500 -out <file.pem> -subj "/C=US/ST=New York/L=Brooklyn/O=Example Brooklyn Company/CN=<server_address>"
use a channel to handle all requests (Avoid ReadTimeoutExpired error), http.ListenAndServe() supports concurrency:
package main
import (
"fmt"
"net/http"
"github.com/raminsa/telegram-bot-api/telegram"
"github.com/raminsa/telegram-bot-api/types"
)
func main() {
fmt.Println("start at port:", "BotPortNumber")
updates := listenForWebhook(100)
go http.ListenAndServeTLS("BotPortNumber", "BotCertFile", "BotKeyFile", nil)
for update := range updates {
if update.Message != nil {
fmt.Println(update.Message.Text)
}
}
}
func listenForWebhook(maxWebhookConnections int) types.UpdatesChannel {
ch := make(chan types.Update, maxWebhookConnections)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if update, err := telegram.HandleUpdate(r); err != nil {
return
} else {
ch <- *update
}
})
return ch
}
use client with custom options:
package main
import (
"fmt"
"log"
"github.com/raminsa/telegram-bot-api/telegram"
)
func main() {
client := telegram.Client()
client.BaseUrl = "baseUrl"
client.Proxy = "proxy"
client.ForceV4 = true
client.DisableSSLVerify = true
client.ForceAttemptHTTP2 = true
tg, err := telegram.NewWithCustomClient("BotToken", client)
if err != nil {
log.Fatal(err)
}
me, err := tg.GetMe()
if err != nil {
log.Fatal(err)
}
fmt.Println("botID:", me.ID, "botUsername:", me.UserName)
}
use debug option and write to local file:
package main
import (
"fmt"
"log"
"github.com/raminsa/telegram-bot-api/telegram"
)
func main() {
tg, err := telegram.NewWithBaseUrl("BotToken", "baseUrl")
if err != nil {
log.Fatal(err)
}
//active debug mode
tg.Bot.Debug = true
me, err := tg.GetMe()
if err != nil {
log.Fatal(err)
}
fmt.Println("botID:", me.ID, "botUsername:", me.UserName)
//access debug log
//method 1: write to console
fmt.Println(tg.GetLoggerFile())
//method 2: write to file
err = tg.WriteLoggerFile("fileName")
if err != nil {
log.Fatal(err)
}
}
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.