github.com/olli-ai/jx/v2@v2.0.400-0.20210921045218-14731b4dd448/pkg/chats/provider.go (about) 1 package chats 2 3 import ( 4 "fmt" 5 6 "github.com/olli-ai/jx/v2/pkg/auth" 7 "github.com/olli-ai/jx/v2/pkg/util" 8 ) 9 10 // ChatProvider represents an integration interface to chat 11 type ChatProvider interface { 12 GetChannelMetrics(name string) (*ChannelMetrics, error) 13 } 14 15 // ChannelMetrics metrics for a channel 16 type ChannelMetrics struct { 17 ID string 18 Name string 19 URL string 20 MemberCount int 21 Members []string 22 } 23 24 func (m *ChannelMetrics) ToMarkdown() string { 25 return util.MarkdownLink(m.Name, m.URL) 26 } 27 28 // CreateChatProvider creates a new chat provider if one is available for the given kind 29 func CreateChatProvider(kind string, server *auth.AuthServer, userAuth *auth.UserAuth, batchMode bool) (ChatProvider, error) { 30 switch kind { 31 case Slack: 32 return CreateSlackChatProvider(server, userAuth, batchMode) 33 default: 34 return nil, fmt.Errorf("Unsupported chat provider kind: %s", kind) 35 } 36 } 37 38 func ProviderAccessTokenURL(kind string, url string) string { 39 switch kind { 40 case Slack: 41 return "https://my.slack.com/services/new/bot" 42 default: 43 return "" 44 } 45 }