telegram api manager request

main
alex 2023-10-21 09:11:46 +02:00
parent d59e51f923
commit 227d9e6b56
5 changed files with 68 additions and 13 deletions

View File

@ -49,6 +49,8 @@ HOST=127.0.0.1
PORT=8080 PORT=8080
LOG_MANAGER_SERVER_URL=http://localhost:50110 LOG_MANAGER_SERVER_URL=http://localhost:50110
TELEGRAM_BOT_MANAGER_ENABLED=true
TELEGRAM_BOT_MANAGER_SERVER_URL=http://localhost:50056
# Folder paths # Folder paths
FOLDER_GROUPTASKS_GROUPS=./groupTasks/groups/ FOLDER_GROUPTASKS_GROUPS=./groupTasks/groups/

View File

@ -10,14 +10,16 @@ import (
var Cfg Config var Cfg Config
type Config struct { type Config struct {
Debug bool Debug bool
ColorizedOutput bool ColorizedOutput bool
Host string Host string
Port string Port string
LogManagerServerUrl string LogManagerServerUrl string
FolderPaths FolderPaths TelegramBotManagerEnabled bool
MariaDB MariaDB TelegramBotManagerServerUrl string
InvexAPI InvexAPI FolderPaths FolderPaths
MariaDB MariaDB
InvexAPI InvexAPI
} }
type FolderPaths struct { type FolderPaths struct {
@ -49,11 +51,13 @@ func LoadConfig() {
} }
Cfg = Config{ Cfg = Config{
Debug: os.Getenv("DEBUG") == "true", Debug: os.Getenv("DEBUG") == "true",
ColorizedOutput: os.Getenv("COLORIZED_OUTPUT") == "true", ColorizedOutput: os.Getenv("COLORIZED_OUTPUT") == "true",
Host: os.Getenv("HOST"), Host: os.Getenv("HOST"),
Port: os.Getenv("PORT"), Port: os.Getenv("PORT"),
LogManagerServerUrl: os.Getenv("LOG_MANAGER_SERVER_URL"), 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{ FolderPaths: FolderPaths{
GroupTasksGroups: os.Getenv("FOLDER_GROUPTASKS_GROUPS"), GroupTasksGroups: os.Getenv("FOLDER_GROUPTASKS_GROUPS"),
GroupTasksRunningTasks: os.Getenv("FOLDER_GROUPTASKS_RUNNINGTASKS"), GroupTasksRunningTasks: os.Getenv("FOLDER_GROUPTASKS_RUNNINGTASKS"),

View File

@ -1,7 +1,9 @@
package notification package notification
import ( import (
"jannex/admin-dashboard-backend/modules/config"
"jannex/admin-dashboard-backend/modules/database" "jannex/admin-dashboard-backend/modules/database"
"jannex/admin-dashboard-backend/modules/requestclient"
"jannex/admin-dashboard-backend/modules/structs" "jannex/admin-dashboard-backend/modules/structs"
"jannex/admin-dashboard-backend/modules/utils" "jannex/admin-dashboard-backend/modules/utils"
"jannex/admin-dashboard-backend/socketclients" "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) return c.SendStatus(fiber.StatusOK)
} }

View File

@ -1,8 +1,10 @@
package requestclient package requestclient
import ( import (
"encoding/json"
"jannex/admin-dashboard-backend/modules/config" "jannex/admin-dashboard-backend/modules/config"
"jannex/admin-dashboard-backend/modules/logger" "jannex/admin-dashboard-backend/modules/logger"
"jannex/admin-dashboard-backend/modules/structs"
"strconv" "strconv"
"git.ex.umbach.dev/Alex/roese-utils/rslogger" "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 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))
}
}

View File

@ -28,3 +28,9 @@ type NotificationsResponse struct {
Notifications []Notification Notifications []Notification
TotalPages int TotalPages int
} }
type TelegramBotManagerRequestBody struct {
UserIds []string
Type uint8
Title string
}