telegram api manager request
parent
d59e51f923
commit
227d9e6b56
2
main.go
2
main.go
|
@ -49,6 +49,8 @@ HOST=127.0.0.1
|
|||
PORT=8080
|
||||
|
||||
LOG_MANAGER_SERVER_URL=http://localhost:50110
|
||||
TELEGRAM_BOT_MANAGER_ENABLED=true
|
||||
TELEGRAM_BOT_MANAGER_SERVER_URL=http://localhost:50056
|
||||
|
||||
# Folder paths
|
||||
FOLDER_GROUPTASKS_GROUPS=./groupTasks/groups/
|
||||
|
|
|
@ -10,14 +10,16 @@ import (
|
|||
var Cfg Config
|
||||
|
||||
type Config struct {
|
||||
Debug bool
|
||||
ColorizedOutput bool
|
||||
Host string
|
||||
Port string
|
||||
LogManagerServerUrl string
|
||||
FolderPaths FolderPaths
|
||||
MariaDB MariaDB
|
||||
InvexAPI InvexAPI
|
||||
Debug bool
|
||||
ColorizedOutput bool
|
||||
Host string
|
||||
Port string
|
||||
LogManagerServerUrl string
|
||||
TelegramBotManagerEnabled bool
|
||||
TelegramBotManagerServerUrl string
|
||||
FolderPaths FolderPaths
|
||||
MariaDB MariaDB
|
||||
InvexAPI InvexAPI
|
||||
}
|
||||
|
||||
type FolderPaths struct {
|
||||
|
@ -49,11 +51,13 @@ func LoadConfig() {
|
|||
}
|
||||
|
||||
Cfg = Config{
|
||||
Debug: os.Getenv("DEBUG") == "true",
|
||||
ColorizedOutput: os.Getenv("COLORIZED_OUTPUT") == "true",
|
||||
Host: os.Getenv("HOST"),
|
||||
Port: os.Getenv("PORT"),
|
||||
LogManagerServerUrl: os.Getenv("LOG_MANAGER_SERVER_URL"),
|
||||
Debug: os.Getenv("DEBUG") == "true",
|
||||
ColorizedOutput: os.Getenv("COLORIZED_OUTPUT") == "true",
|
||||
Host: os.Getenv("HOST"),
|
||||
Port: os.Getenv("PORT"),
|
||||
LogManagerServerUrl: os.Getenv("LOG_MANAGER_SERVER_URL"),
|
||||
TelegramBotManagerEnabled: os.Getenv("TELEGRAM_BOT_MANAGER_ENABLED") == "true",
|
||||
TelegramBotManagerServerUrl: os.Getenv("TELEGRAM_BOT_MANAGER_SERVER_URL"),
|
||||
FolderPaths: FolderPaths{
|
||||
GroupTasksGroups: os.Getenv("FOLDER_GROUPTASKS_GROUPS"),
|
||||
GroupTasksRunningTasks: os.Getenv("FOLDER_GROUPTASKS_RUNNINGTASKS"),
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package notification
|
||||
|
||||
import (
|
||||
"jannex/admin-dashboard-backend/modules/config"
|
||||
"jannex/admin-dashboard-backend/modules/database"
|
||||
"jannex/admin-dashboard-backend/modules/requestclient"
|
||||
"jannex/admin-dashboard-backend/modules/structs"
|
||||
"jannex/admin-dashboard-backend/modules/utils"
|
||||
"jannex/admin-dashboard-backend/socketclients"
|
||||
|
@ -102,6 +104,14 @@ func AddNotification(c *fiber.Ctx, body structs.AddNotificationRequest) error {
|
|||
})
|
||||
}
|
||||
|
||||
if config.Cfg.TelegramBotManagerEnabled {
|
||||
requestclient.TelegramBotManagerRequestClient(structs.TelegramBotManagerRequestBody{
|
||||
UserIds: userIds,
|
||||
Title: body.Title,
|
||||
Type: body.Type,
|
||||
})
|
||||
}
|
||||
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package requestclient
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"jannex/admin-dashboard-backend/modules/config"
|
||||
"jannex/admin-dashboard-backend/modules/logger"
|
||||
"jannex/admin-dashboard-backend/modules/structs"
|
||||
"strconv"
|
||||
|
||||
"git.ex.umbach.dev/Alex/roese-utils/rslogger"
|
||||
|
@ -46,3 +48,34 @@ func InvexApiRequestClient(requestMethod string, url string) (statusCode int, bo
|
|||
|
||||
return code, body, nil
|
||||
}
|
||||
|
||||
func TelegramBotManagerRequestClient(telegramBotManagerRequestBody structs.TelegramBotManagerRequestBody) {
|
||||
a := fiber.AcquireAgent()
|
||||
|
||||
req := a.Request()
|
||||
req.Header.SetMethod(fiber.MethodPost)
|
||||
req.SetRequestURI(config.Cfg.TelegramBotManagerServerUrl + "/v1/notification")
|
||||
req.Header.SetContentType("application/json")
|
||||
|
||||
reqestBodyBytes, err := json.Marshal(telegramBotManagerRequestBody)
|
||||
|
||||
if err != nil {
|
||||
log.Error().Msgf("Failed to marshal request body, err: %s", err)
|
||||
logger.AddSystemLog(rslogger.LogTypeError, "TelegramBotManagerRequestClient failed to marshal request body, err: %s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
req.SetBody(reqestBodyBytes)
|
||||
|
||||
if err = a.Parse(); err != nil {
|
||||
log.Error().Msgf("Failed to parse request, err: %s", err)
|
||||
logger.AddSystemLog(rslogger.LogTypeError, "TelegramBotManagerRequestClient failed to parse request, err: %s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
code, _, _ := a.Bytes()
|
||||
|
||||
if code != 200 {
|
||||
logger.AddSystemLog(rslogger.LogTypeError, "TelegramBotManagerRequestClient err: %s statusCode: %s", "failed to send notification", strconv.Itoa(code))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,3 +28,9 @@ type NotificationsResponse struct {
|
|||
Notifications []Notification
|
||||
TotalPages int
|
||||
}
|
||||
|
||||
type TelegramBotManagerRequestBody struct {
|
||||
UserIds []string
|
||||
Type uint8
|
||||
Title string
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue