-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
add slack notification route on broadcast channel messages and fix au…
- Loading branch information
Showing
11 changed files
with
130 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/natron-io/tenant-api/util" | ||
"github.com/slack-go/slack" | ||
) | ||
|
||
// GetNotifications returns all slack notifications of a broadcast channel by authenticated users tenants | ||
func GetNotifications(c *fiber.Ctx) error { | ||
|
||
util.InfoLogger.Printf("%s %s %s", c.IP(), c.Method(), c.Path()) | ||
|
||
tenants := CheckAuth(c) | ||
if len(tenants) == 0 { | ||
return c.Status(401).JSON(fiber.Map{ | ||
"message": "Unauthorized", | ||
}) | ||
} | ||
|
||
// set authorization header Bearer token as util.SLACK_TOKEN | ||
if util.SLACK_TOKEN == "" { | ||
return c.Status(500).JSON(fiber.Map{ | ||
"message": "Internal Server Error", | ||
}) | ||
} | ||
|
||
historyParams := slack.GetConversationHistoryParameters{ | ||
ChannelID: util.BroadCastChannelID, | ||
Limit: 10, | ||
} | ||
|
||
// make slack api call to get all notifications of the BroadCast channel | ||
resp, err := util.SlackClient.GetConversationHistory(&historyParams) | ||
|
||
// parse messages to string slice | ||
var notifications []string | ||
for _, message := range resp.Messages { | ||
if message.Blocks.BlockSet != nil { | ||
notifications = append(notifications, message.Text) | ||
} | ||
} | ||
|
||
if err != nil { | ||
util.ErrorLogger.Printf("Error getting slack messages: %v", err) | ||
return c.Status(500).JSON(fiber.Map{ | ||
"message": "Internal Server Error", | ||
}) | ||
} | ||
|
||
return c.JSON(notifications) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package util | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/slack-go/slack" | ||
) | ||
|
||
var ( | ||
SLACK_TOKEN = os.Getenv("SLACK_TOKEN") | ||
SlackClient *slack.Client | ||
BroadCastChannelID string | ||
) |