mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-17 21:53:42 +08:00
✨ feat: add telegram bot (#71)
This commit is contained in:
22
middleware/telegram.go
Normal file
22
middleware/telegram.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"one-api/common/telegram"
|
||||
"os"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Telegram() func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
token := c.Param("token")
|
||||
|
||||
if !telegram.TGEnabled || telegram.TGWebHookSecret == "" || token == "" || token != os.Getenv("TG_BOT_API_KEY") {
|
||||
c.String(404, "Page not found")
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user