plugin

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderMattermostUserID = "Mattermost-User-ID"
	HeaderServiceNowUserID = "ServiceNow-User-ID"
	// Used for storing the token in the request context to pass from one middleware to another
	// #nosec G101 -- This is a false positive. The below line is not a hardcoded credential
	ContextTokenKey ServiceNowOAuthToken = "ServiceNow-Oauth-Token"

	ConnectSuccessMessage = "Thanks for linking your ServiceNow account!\n" +
		"Your ServiceNow account (*%s*) has been connected to Mattermost."
	WelcomePretextMessage = "Welcome to the Mattermost ServiceNow Virtual Agent.\n" +
		"I'm here to help you. Let's start by linking your ServiceNow account.\n[Link to ServiceNow](%s)"
	GenericErrorMessage = "Something went wrong. Please try again later."

	PathOAuth2Connect              = "/oauth2/connect"
	PathOAuth2Complete             = "/oauth2/complete"
	PathUserDisconnect             = "/user/disconnect"
	PathGetUser                    = "/api/now/table/sys_user"
	PathVirtualAgentWebhook        = "/nowbot/processResponse"
	PathVirtualAgentBotIntegration = "/api/sn_va_as_service/bot/integration"
	PathActionOptions              = "/action_options"

	SysQueryParam = "sysparm_query"

	BotUsername    = "servicenow-virtual-agent"
	BotDisplayName = "ServiceNow Virtual Agent"
	BotDescription = "A bot account created by the plugin ServiceNow Virtual Agent."

	DisconnectKeyword                = "disconnect"
	DisconnectUserContextName        = "Disconnect"
	DisconnectUserConfirmationMessge = "Are you sure you want to disconnect your ServiceNow account?"
	DisconnectUserRejectedMessage    = "You're still connected to your ServiceNow account."
	DisconnectUserSuccessMessage     = "Successfully disconnected your ServiceNow account."
	AlreadyDisconnectedMessage       = "You're already disconnected from your ServiceNow account."

	StartConversationAction         = "START_CONVERSATION"
	OutputTextUIType                = "OutputText"
	InputTextUIType                 = "InputText"
	FileUploadUIType                = "FileUpload"
	TopicPickerControlUIType        = "TopicPickerControl"
	PickerUIType                    = "Picker"
	BooleanUIType                   = "Boolean"
	OutputLinkUIType                = "OutputLink"
	GroupedPartsOutputControlUIType = "GroupedPartsOutputControl"
	OutputCardUIType                = "OutputCard"

	ItemTypeImage = "image"
	ItemTypeFile  = "file"

	UploadImageMessage = "\n(**Note:** Please upload an image using the Mattermost `Upload files` option OR use the shorthand `Ctrl+U`.)"
	UploadFileMessage  = "\n(**Note:** Please upload a file using the Mattermost `Upload files` option OR use the shorthand `Ctrl+U`.)"

	PathParamEncryptedFileInfo = "encryptedFileInfo"

	AttachmentLinkExpiryTimeInMinutes = 15
)
View Source
const (
	EmptyServiceNowURLErrorMessage               = "serviceNow URL should not be empty"
	EmptyServiceNowOAuthClientIDErrorMessage     = "serviceNow OAuth clientID should not be empty"
	EmptyServiceNowOAuthClientSecretErrorMessage = "serviceNow OAuth clientSecret should not be empty"
	EmptyEncryptionSecretErrorMessage            = "encryption secret should not be empty"
	EmptyWebhookSecretErrorMessage               = "webhook secret should not be empty"
)

#nosec G101 -- This is a false positive. The below line is not a hardcoded credential

View Source
const (
	UserKeyPrefix   = "user_"
	OAuth2KeyPrefix = "oauth2_"
)
View Source
const (
	OAuth2KeyExpiration = 15 * time.Minute
)

Variables

View Source
var ErrNotFound = kvstore.ErrNotFound

Functions

func ReturnStatusOK

func ReturnStatusOK(w io.Writer)

Types

type AuthToken

type AuthToken struct {
	Token *oauth2.Token `json:"token,omitempty"`
}

type Client

type Client interface {
	GetMe(mattermostUserID string) (*serializer.ServiceNowUser, error)
	StartConverstaionWithVirtualAgent(userID string) error
	SendMessageToVirtualAgentAPI(userID, messageText string, typed bool, attachment *MessageAttachment) error
}

type Error

type Error struct {
	Detail  string `json:"detail"`
	Message string `json:"message"`
}

type ErrorResponse

type ErrorResponse struct {
	Error Error `json:"error"`
}

type FileStruct added in v1.2.0

type FileStruct struct {
	ID     string
	Expiry time.Time
}

type GroupedPartsOutputControl

type GroupedPartsOutputControl struct {
	UIType string                           `json:"uiType"`
	Group  string                           `json:"group"`
	Header string                           `json:"header"`
	Type   string                           `json:"type"`
	Values []GroupedPartsOutputControlValue `json:"values"`
}

type GroupedPartsOutputControlValue

type GroupedPartsOutputControlValue struct {
	Label       string `json:"label"`
	Action      string `json:"action"`
	Description string `json:"description"`
}

type MessageAttachment added in v1.2.0

type MessageAttachment struct {
	URL         string `json:"url"`
	ContentType string `json:"contentType"`
	FileName    string `json:"fileName"`
}

type MessageBody

type MessageBody struct {
	Attachment *MessageAttachment `json:"attachment"`
	Text       string             `json:"text"`
	Typed      bool               `json:"typed"`
}

type MessageResponseBody

type MessageResponseBody struct {
	Value interface{}
}

func (*MessageResponseBody) UnmarshalJSON

func (m *MessageResponseBody) UnmarshalJSON(data []byte) error

type OAuth2StateStore

type OAuth2StateStore interface {
	VerifyOAuth2State(state string) error
	StoreOAuth2State(state string) error
}

OAuth2StateStore manages OAuth2 state

type Option

type Option struct {
	Label   string `json:"label"`
	Value   string `json:"value"`
	Enabled bool   `json:"enabled"`
}

type OutputCard

type OutputCard struct {
	UIType string `json:"uiType"`
	Group  string `json:"group"`
	Data   string `json:"data"`
}

type OutputCardData

type OutputCardData struct {
	Subtitle string `json:"subtitle"`
	Title    string `json:"title"`
	URL      string `json:"url"`
}
type OutputLink struct {
	UIType        string `json:"uiType"`
	Group         string `json:"group"`
	Label         string `json:"label"`
	Header        string `json:"header"`
	Type          string `json:"type"`
	Value         OutputLinkValue
	PromptMessage string `json:"promptMsg"`
}

type OutputLinkValue

type OutputLinkValue struct {
	Action string `json:"action"`
}

type OutputText

type OutputText struct {
	UIType   string `json:"uiType"`
	Group    string `json:"group"`
	Value    string `json:"value"`
	ItemType string `json:"type"`
	MaskType string `json:"maskType"`
	Label    string `json:"label"`
}

type Picker

type Picker struct {
	UIType         string   `json:"uiType"`
	Group          string   `json:"group"`
	Required       bool     `json:"required"`
	NLUTextEnabled bool     `json:"nluTextEnabled"`
	Label          string   `json:"label"`
	ItemType       string   `json:"itemType"`
	Options        []Option `json:"options"`
	Style          string   `json:"style"`
	MultiSelect    bool     `json:"multiSelect"`
}

type Plugin

type Plugin struct {
	plugin.MattermostPlugin
	// contains filtered or unexported fields
}

Plugin implements the interface expected by the Mattermost server to communicate between the server and plugin processes.

func (*Plugin) CompleteOAuth2

func (p *Plugin) CompleteOAuth2(authedUserID, code, state string) error

func (*Plugin) CreateDisconnectUserAttachment

func (p *Plugin) CreateDisconnectUserAttachment() *model.SlackAttachment

func (*Plugin) CreateGroupedPartsOutputControlAttachment

func (p *Plugin) CreateGroupedPartsOutputControlAttachment(body GroupedPartsOutputControlValue) *model.SlackAttachment

func (*Plugin) CreateOutputCardAttachment

func (p *Plugin) CreateOutputCardAttachment(body *OutputCardData) *model.SlackAttachment

func (*Plugin) CreateOutputLinkAttachment

func (p *Plugin) CreateOutputLinkAttachment(body *OutputLink) *model.SlackAttachment

func (*Plugin) CreatePickerAttachment

func (p *Plugin) CreatePickerAttachment(body *Picker) *model.SlackAttachment

func (*Plugin) CreateTopicPickerControlAttachment

func (p *Plugin) CreateTopicPickerControlAttachment(body *TopicPickerControl) *model.SlackAttachment

func (*Plugin) DM

func (p *Plugin) DM(mattermostUserID, format string, args ...interface{}) (string, error)

DM posts a simple Direct Message to the specified user

func (*Plugin) DMWithAttachments

func (p *Plugin) DMWithAttachments(mattermostUserID string, attachments ...*model.SlackAttachment) (string, error)

DMWithAttachments posts a Direct Message that contains Slack attachments. Often used to include post actions.

func (*Plugin) DisconnectUser

func (p *Plugin) DisconnectUser(mattermostUserID string) error

func (*Plugin) Ephemeral

func (p *Plugin) Ephemeral(userID, channelID, format string, args ...interface{})

Ephemeral sends an ephemeral message to a user

func (*Plugin) GetDisconnectUserPost

func (p *Plugin) GetDisconnectUserPost(mattermostUserID, message string) (*model.Post, error)

func (*Plugin) GetPluginURL

func (p *Plugin) GetPluginURL() string

func (*Plugin) GetPluginURLPath

func (p *Plugin) GetPluginURLPath() string

func (*Plugin) GetPostWithSlackAttachment

func (p *Plugin) GetPostWithSlackAttachment(mattermostUserID string, attachments ...*model.SlackAttachment) (*model.Post, error)

func (*Plugin) GetSiteURL

func (p *Plugin) GetSiteURL() string

func (*Plugin) GetUser

func (p *Plugin) GetUser(mattermostUserID string) (*serializer.User, error)

func (*Plugin) InitOAuth2

func (p *Plugin) InitOAuth2(mattermostUserID string) (string, error)

func (*Plugin) MakeClient

func (p *Plugin) MakeClient(ctx context.Context, token *oauth2.Token) Client

func (*Plugin) MessageHasBeenPosted

func (p *Plugin) MessageHasBeenPosted(c *plugin.Context, post *model.Post)

func (*Plugin) NewEncodedAuthToken

func (p *Plugin) NewEncodedAuthToken(token *oauth2.Token) (returnToken string, returnErr error)

func (*Plugin) NewOAuth2Config

func (p *Plugin) NewOAuth2Config() *oauth2.Config

func (*Plugin) NewStore

func (p *Plugin) NewStore(api plugin.API) Store

func (*Plugin) OnActivate

func (p *Plugin) OnActivate() error

func (*Plugin) OnConfigurationChange

func (p *Plugin) OnConfigurationChange() error

OnConfigurationChange is invoked when configuration changes may have been made.

func (*Plugin) ParseAuthToken

func (p *Plugin) ParseAuthToken(encoded string) (*oauth2.Token, error)

func (*Plugin) ProcessResponse

func (p *Plugin) ProcessResponse(data []byte) error

func (*Plugin) ServeHTTP

func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request)

ServeHTTP demonstrates a plugin that handles HTTP requests.

type ServiceNowOAuthToken

type ServiceNowOAuthToken string

type Store

type Store interface {
	UserStore
	OAuth2StateStore
}

type TopicPickerControl

type TopicPickerControl struct {
	UIType         string   `json:"uiType"`
	Group          string   `json:"group"`
	NLUTextEnabled bool     `json:"nluTextEnabled"`
	PromptMessage  string   `json:"promptMsg"`
	Label          string   `json:"label"`
	Options        []Option `json:"options"`
}

type UserStore

type UserStore interface {
	LoadUser(mattermostUserID string) (*serializer.User, error)
	StoreUser(user *serializer.User) error
	DeleteUser(mattermostUserID string) error
	LoadUserWithSysID(mattermostUserID string) (*serializer.User, error)
}

type VirtualAgentRequestBody

type VirtualAgentRequestBody struct {
	Action    string       `json:"action"`
	Message   *MessageBody `json:"message"`
	RequestID string       `json:"requestId"`
	UserID    string       `json:"userId"`
}

type VirtualAgentResponse

type VirtualAgentResponse struct {
	VirtualAgentRequestBody
	Body []MessageResponseBody `json:"body"`
}

Jump to

Keyboard shortcuts

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