init: Initial commit
This commit is contained in:
32
app/services/webhook_execute.go
Normal file
32
app/services/webhook_execute.go
Normal file
@@ -0,0 +1,32 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user