Files
houston-be/pkg/slackbot/channel.go
Shubham Kirve b135eade9c Revert "Revert "TP-0000 | restricting incident creation from private channels"" (#63)
* Revert "Revert "TP-0000 | restricting incident creation from private channels (#60)" (#62)"

This reverts commit b3eed5dd63.

* TP-0000 | allow incident creation from channels where houston is invited

* TP-0000 | renaming functions

* TP-0000 | making desc mandatory
2023-05-11 17:56:34 +05:30

72 lines
2.3 KiB
Go

package slackbot
import (
"fmt"
"github.com/slack-go/slack"
"go.uber.org/zap"
)
func (c *Client) FindParticipants(channelId string) ([]string, error) {
request := &slack.GetUsersInConversationParameters{
ChannelID: channelId,
Limit: 1000,
}
channelInfo, _, err := c.socketModeClient.GetUsersInConversation(request)
if err != nil {
c.logger.Error("find participants failed", zap.String("channel_id", channelId), zap.Error(err))
return nil, fmt.Errorf("fetch channel conversationInfo failed. err: %v", err)
}
return channelInfo, nil
}
func (c *Client) CreateChannel(channelName string) (string, error) {
request := slack.CreateConversationParams{
ChannelName: channelName,
IsPrivate: false,
}
channel, err := c.socketModeClient.CreateConversation(request)
if err != nil {
c.logger.Error("create slackbot channel failed", zap.String("channel_name", channelName), zap.Error(err))
return "", err
}
c.logger.Info("created slackbot channel successfully", zap.String("channel_name", channelName), zap.String("channel_id", channel.ID))
return channel.ID, nil
}
func (c *Client) SetChannelTopic(channelId, topic string) (string, error) {
channel, err := c.socketModeClient.SetTopicOfConversation(channelId, topic)
if err != nil {
c.logger.Error("set topic on slack channel failed", zap.String("channel_id", channelId), zap.Error(err))
return "", err
}
c.logger.Info("set topic on slack channel successful", zap.String("channel_id", channelId), zap.String("channel_id", channel.ID))
return "", nil
}
func (c *Client) InviteUsersToConversation(channelId string, userId ...string) {
_, err := c.socketModeClient.InviteUsersToConversation(channelId, userId...)
if err != nil {
c.logger.Error("invite users to conversation failed",
zap.String("channel_id", channelId), zap.Any("user_ids", userId), zap.Error(err))
return
}
c.logger.Info("successfully invite users to conversation", zap.String("channel_id", channelId), zap.Any("user_ids", userId))
}
func (c *Client) GetConversationInfo(channelId string) (*slack.Channel, error) {
channel, err := c.socketModeClient.GetConversationInfo(&slack.GetConversationInfoInput{
ChannelID: channelId,
})
if err != nil {
c.logger.Info("failed while fetching conversation info", zap.Error(err))
return nil, err
}
return channel, nil
}