33 lines
1.1 KiB
Go
33 lines
1.1 KiB
Go
package services
|
|
|
|
import (
|
|
"git.secnex.io/secnex/masterlog"
|
|
"git.secnex.io/secnex/taro-bot/bot"
|
|
"git.secnex.io/secnex/taro-bot/repositories"
|
|
"git.secnex.io/secnex/taro-bot/utils"
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func ExecuteWebhook(channelId uuid.UUID, body utils.HTTPBody) *utils.HTTPResponse {
|
|
channel, err := repositories.GetChannelByID(channelId.String())
|
|
if err != nil {
|
|
return utils.NewHTTPResponse(fiber.StatusInternalServerError, &fiber.Map{
|
|
"message": "Failed to get channel",
|
|
}, "", nil, nil)
|
|
}
|
|
|
|
text := "New webhook received!"
|
|
conversation := bot.NewConversation(*bot.AUTH)
|
|
err = conversation.SendMessage(bot.NewTextPost(channel.ExternalID, text))
|
|
if err != nil {
|
|
return utils.NewHTTPResponse(fiber.StatusInternalServerError, &fiber.Map{
|
|
"message": "Failed to send message",
|
|
}, "", nil, nil)
|
|
}
|
|
masterlog.Info("Webhook executed successfully", map[string]interface{}{"channelId": channelId, "text": text})
|
|
return utils.NewHTTPResponse(fiber.StatusOK, &fiber.Map{
|
|
"message": "Webhook executed successfully",
|
|
}, "", nil, nil)
|
|
}
|