slack_user_center

package module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

README

Slack User Center

Feature

  • User login via slack Account

Config

To use this plugin, you need to create a Slack App first, set the Scope and Redirect URL correctly, and copy the Client ID, Client Secrect, Signing Secret and Webhook URL. To activate the Slash Command function, you also need to set the slash command in your app. Here are default settings you can try:

Scope: chat:write, commands, groups:write, im:write, incoming-webhook, mpim:write, users:read, users:read.email

RedirectURL: https://Your_Site_URL/answer/api/v1/user-center/login/callback

Slash command:

  • Command: /ask
  • Requesti URL: https://Your_Site_URL/answer/api/v1/slack/slash
  • Usage Hint: [Title][Content][Tag1,Tag2...]
  • Client ID: Slack App Client ID

  • Client Secret: Slack App Secret

  • Signing Secret: Slack App Signing Secret

  • Webhook URL: find in the Incoming Webhooks feature, such as https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX

Note: A Redirect URL must also use HTTPS. You can configure a Redirect URL and scope in the App Management page under OAuth & Permissions.

Document

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Info embed.FS

Functions

This section is empty.

Types

type AuthUserResp

type AuthUserResp struct {
	Ok     bool      `json:"ok"`
	Errmsg string    `json:"error"`
	User   *UserInfo `json:"user"`
}

type Importer

type Importer struct{}

type Member

type Member struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	TeamID string `json:"team_id"`
}

type OAuthResponseIncomingWebhook

type OAuthResponseIncomingWebhook struct {
	URL              string `json:"url"`
	Channel          string `json:"channel"`
	ChannelID        string `json:"channel_id,omitempty"`
	ConfigurationURL string `json:"configuration_url"`
}

OAuthResponseIncomingWebhook

type OAuthV2ResponseAuthedUser

type OAuthV2ResponseAuthedUser struct {
	ID           string `json:"id"`
	Scope        string `json:"scope"`
	AccessToken  string `json:"access_token"`
	ExpiresIn    int    `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
	TokenType    string `json:"token_type"`
}

OAuthV2ResponseAuthedUser

type OAuthV2ResponseEnterprise

type OAuthV2ResponseEnterprise struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

OAuthV2ResponseEnterprise

type OAuthV2ResponseTeam

type OAuthV2ResponseTeam struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

OAuthV2ResponseTeam

type RespBody

type RespBody struct {
	// http code
	Code int `json:"code"`
	// reason key
	Reason string `json:"reason"`
	// response message
	Message string `json:"msg"`
	// response data
	Data interface{} `json:"data"`
}

RespBody response body.

func NewRespBodyData

func NewRespBodyData(code int, reason string, data interface{}) *RespBody

NewRespBodyData new response body with data

type SlackClient

type SlackClient struct {
	AccessToken  string
	ClientID     string
	ClientSecret string
	RedirectURI  string
	AuthedUserID string

	UserInfoMapping map[string]*UserInfo
	ChannelMapping  string
}

func NewSlackClient

func NewSlackClient(clientID, clientSecret string) *SlackClient

func NewSlackClientWithConfig

func NewSlackClientWithConfig(clientID, clientSecret, redirectURI string) *SlackClient

func (*SlackClient) AuthUser

func (sc *SlackClient) AuthUser(code string) (info *UserInfo, err error)

ExchangeCodeForUser through OAuthToken

func (*SlackClient) GetUserDetailInfo

func (sc *SlackClient) GetUserDetailInfo(userid string) (info *UserInfo, err error)

func (*SlackClient) UpdateUserInfo

func (sc *SlackClient) UpdateUserInfo() (err error)

type SlackUserResponse

type SlackUserResponse struct {
	Ok   bool `json:"ok"`
	User struct {
		Profile struct {
			Email string `json:"email"`
		} `json:"profile"`
	} `json:"user"`
}

type TokenResponse

type TokenResponse struct {
	AccessToken         string                       `json:"access_token"`
	TokenType           string                       `json:"token_type"`
	Scope               string                       `json:"scope"`
	BotUserID           string                       `json:"bot_user_id"`
	AppID               string                       `json:"app_id"`
	Team                OAuthV2ResponseTeam          `json:"team"`
	IncomingWebhook     OAuthResponseIncomingWebhook `json:"incoming_webhook"`
	Enterprise          OAuthV2ResponseEnterprise    `json:"enterprise"`
	IsEnterpriseInstall bool                         `json:"is_enterprise_install"`
	AuthedUser          OAuthV2ResponseAuthedUser    `json:"authed_user"`
	RefreshToken        string                       `json:"refresh_token"`
	ExpiresIn           int                          `json:"expires_in"`
	Error               string                       `json:"error,omitempty"`
}

type UserCenter

type UserCenter struct {
	Config          *UserCenterConfig
	SlackClient     *SlackClient
	UserConfigCache *UserConfigCache
	Cache           *cache.Cache
	// contains filtered or unexported fields
}

func (*UserCenter) AfterLogin

func (uc *UserCenter) AfterLogin(externalID, accessToken string)

func (*UserCenter) BuildSlackBaseRedirectURL

func (uc *UserCenter) BuildSlackBaseRedirectURL() string

func (*UserCenter) ConfigFields

func (uc *UserCenter) ConfigFields() []plugin.ConfigField

func (*UserCenter) ConfigReceiver

func (uc *UserCenter) ConfigReceiver(config []byte) error

func (*UserCenter) ControlCenterItems

func (uc *UserCenter) ControlCenterItems() []plugin.ControlCenter

func (*UserCenter) CronSyncData

func (uc *UserCenter) CronSyncData()

func (*UserCenter) Description

func (uc *UserCenter) Description() plugin.UserCenterDesc

func (*UserCenter) GetNewQuestionSubscribers

func (uc *UserCenter) GetNewQuestionSubscribers() (userIDs []string)

GetNewQuestionSubscribers returns the subscribers of the new question notification

func (*UserCenter) GetQuestion

func (uc *UserCenter) GetQuestion(ctx *gin.Context) (questionInfo plugin.QuestionImporterInfo, err error)

func (*UserCenter) GetSlackRedirectURL

func (uc *UserCenter) GetSlackRedirectURL(ctx *gin.Context)

func (*UserCenter) Info

func (uc *UserCenter) Info() plugin.Info

func (*UserCenter) LoginCallback

func (uc *UserCenter) LoginCallback(ctx *plugin.GinContext) (userInfo *plugin.UserCenterBasicUserInfo, err error)

func (*UserCenter) Notify

func (uc *UserCenter) Notify(msg plugin.NotificationMessage)

Notify sends a notification to the user

func (*UserCenter) PersonalBranding

func (uc *UserCenter) PersonalBranding(externalID string) (branding []*plugin.PersonalBranding)

func (*UserCenter) RegisterAuthAdminRouter

func (uc *UserCenter) RegisterAuthAdminRouter(r *gin.RouterGroup)

func (*UserCenter) RegisterAuthUserRouter

func (uc *UserCenter) RegisterAuthUserRouter(r *gin.RouterGroup)

func (*UserCenter) RegisterImporterFunc

func (uc *UserCenter) RegisterImporterFunc(ctx context.Context, importerFunc plugin.ImporterFunc)

func (*UserCenter) RegisterUnAuthRouter

func (uc *UserCenter) RegisterUnAuthRouter(r *gin.RouterGroup)

func (*UserCenter) SignUpCallback

func (uc *UserCenter) SignUpCallback(ctx *plugin.GinContext) (userInfo *plugin.UserCenterBasicUserInfo, err error)

func (*UserCenter) SlashCommand

func (uc *UserCenter) SlashCommand(ctx *gin.Context)

func (*UserCenter) Sync

func (uc *UserCenter) Sync(ctx *gin.Context)

func (*UserCenter) UserConfigFields

func (uc *UserCenter) UserConfigFields() []plugin.ConfigField

func (*UserCenter) UserConfigReceiver

func (uc *UserCenter) UserConfigReceiver(userID string, config []byte) error

func (*UserCenter) UserInfo

func (uc *UserCenter) UserInfo(externalID string) (userInfo *plugin.UserCenterBasicUserInfo, err error)

func (*UserCenter) UserList

func (uc *UserCenter) UserList(externalIDs []string) (userList []*plugin.UserCenterBasicUserInfo, err error)

func (*UserCenter) UserSettings

func (uc *UserCenter) UserSettings(externalID string) (userSettings *plugin.SettingInfo, err error)

func (*UserCenter) UserStatus

func (uc *UserCenter) UserStatus(externalID string) (userStatus plugin.UserStatus)

type UserCenterConfig

type UserCenterConfig struct {
	ClientID      string `json:"client_id"`      // Slack Client ID
	ClientSecret  string `json:"client_secret"`  // Slack Client Secret
	RedirectURI   string `json:"redirect_uri"`   // OAuth Redirect URI
	SigningSecret string `json:"signing_secret"` // Slack Signing Secret
	AutoSync      bool   `json:"auto_sync"`      // Auto sync
	Notification  bool   `json:"notification"`   // Notification
}

type UserConfig

type UserConfig struct {
	WebhookURL                   string `json:"webhook_url"`
	InboxNotifications           bool   `json:"inbox_notifications"`
	AllNewQuestions              bool   `json:"all_new_questions"`
	NewQuestionsForFollowingTags bool   `json:"new_questions_for_following_tags"`
	UpvotedAnswers               bool   `json:"upvoted_answers"`
	DownvotedAnswers             bool   `json:"downvoted_answers"`
	UpdatedQuestions             bool   `json:"updated_questions"`
	UpdatedAnswers               bool   `json:"updated_answers"`
}

type UserConfigCache

type UserConfigCache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewUserConfigCache

func NewUserConfigCache() *UserConfigCache

func (*UserConfigCache) SetUserConfig

func (ucc *UserConfigCache) SetUserConfig(userID string, config *UserConfig)

type UserInfo

type UserInfo struct {
	ID                string      `json:"id"`
	TeamID            string      `json:"team_id"`
	Name              string      `json:"name"`
	RealName          string      `json:"real_name"`
	Deleted           bool        `json:"deleted"`
	TimeZone          string      `json:"tz"`
	TimeZoneLabel     string      `json:"tz_label"`
	TimeZoneOffset    int         `json:"tz_offset"`
	Profile           UserProfile `json:"profile"`
	IsAdmin           bool        `json:"is_admin"`
	IsOwner           bool        `json:"is_owner"`
	IsPrimaryOwner    bool        `json:"is_primary_owner"`
	IsRestricted      bool        `json:"is_restricted"`
	IsUltraRestricted bool        `json:"is_ultra_restricted"`
	IsBot             bool        `json:"is_bot"`
	Updated           int64       `json:"updated"`
	IsAppUser         bool        `json:"is_app_user"`
	Has2FA            bool        `json:"has_2fa"`

	LastLogin   int64 `json:"last_login,omitempty"`
	IsAvailable bool  `json:"is_available"`
	Enable      bool  `json:"true"`
	Status      int   `json:"status"`
}

type UserProfile

type UserProfile struct {
	AvatarHash    string `json:"avatar_hash"`
	StatusText    string `json:"status_text"`
	StatusEmoji   string `json:"status_emoji"`
	RealName      string `json:"real_name"`
	DisplayName   string `json:"display_name"`
	Email         string `json:"email"`
	ImageOriginal string `json:"image_original"`
	Image24       string `json:"image_24"`
	Image32       string `json:"image_32"`
	Image48       string `json:"image_48"`
	Image72       string `json:"image_72"`
	Image192      string `json:"image_192"`
	Image512      string `json:"image_512"`
}

type WebhookReq

type WebhookReq struct {
	Blocks []struct {
		Type string `json:"type"`
		Text struct {
			Type string `json:"type"`
			Text string `json:"text"`
		} `json:"text"`
	} `json:"blocks"`
}

func NewWebhookReq

func NewWebhookReq(content string) *WebhookReq

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL