2021-07-18 21:23:12 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2024-10-28 16:57:26 +00:00
|
|
|
func (ses *session) setBot(c *gin.Context) {
|
2021-07-18 21:23:12 +00:00
|
|
|
|
|
|
|
token := c.PostForm("token")
|
|
|
|
text := c.PostForm("text")
|
|
|
|
|
|
|
|
if token == "" || text == "" || c.PostForm("tec") != "yes" {
|
|
|
|
c.JSON(403, gin.H{
|
|
|
|
"ok": false,
|
|
|
|
"message": "Missing fields",
|
|
|
|
"details": "Please fill all the form data.",
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
botUsername, err := ses.setWebhookForBot(token)
|
|
|
|
if err != nil {
|
|
|
|
c.JSON(300, gin.H{
|
|
|
|
"ok": false,
|
|
|
|
"message": "Bad token",
|
|
|
|
"details": err.Error(),
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-10-28 16:57:26 +00:00
|
|
|
err = ses.setMessage(token, text)
|
2021-07-18 21:23:12 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
c.JSON(503, gin.H{
|
|
|
|
"ok": false,
|
|
|
|
"message": "Internal server error, please try again",
|
|
|
|
"details": err.Error(),
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
c.JSON(200, gin.H{
|
|
|
|
"ok": true,
|
|
|
|
"message": "Created successfully!",
|
|
|
|
"details": "Your bot should be working now. You can check it out at <a href='https://t.me/" + botUsername + "'>@" + botUsername + "</a>",
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|