apps

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2021 License: Apache-2.0 Imports: 7 Imported by: 36

Documentation

Index

Constants

View Source
const (
	DefaultInstallCallPath  = "/install"
	DefaultBindingsCallPath = "/bindings"
)

Conventions for Apps paths, and field names

View Source
const (
	// CallTypeSubmit (default) indicates the intent to take action.
	CallTypeSubmit = CallType("")
	// CallTypeForm retrieves the form definition for the current set of values,
	// and the context.
	CallTypeForm = CallType("form")
	// CallTypeCancel is used for for the (rare?) case of when the form with
	// SubmitOnCancel set is dismissed by the user.
	CallTypeCancel = CallType("cancel")
	// CallTypeLookup is used to fetch items for dynamic select elements
	CallTypeLookup = CallType("lookup")
)
View Source
const (
	// CallResponseTypeOK indicates that the call succeeded, and returns
	// Markdown and Data.
	// TODO update OK to be ["ok", "" default], update redux, webapp?
	CallResponseTypeOK = CallResponseType("")

	// CallResponseTypeOK indicates an error, returns Error.
	CallResponseTypeError = CallResponseType("error")

	// CallResponseTypeForm returns the definition of the form to display for
	// the inputs.
	CallResponseTypeForm = CallResponseType("form")

	// CallResponseTypeCall indicates that another Call that should be executed
	// (from the user-agent?). Call field is returned.
	CallResponseTypeCall = CallResponseType("call")

	// CallResponseTypeNavigate indicates that the user should be forcefully
	// navigated to a URL, which may be a channel in Mattermost. NavigateToURL
	// and UseExternalBrowser are expected to be returned.
	// TODO should CallResponseTypeNavigate be a variation of CallResponseTypeOK?
	CallResponseTypeNavigate = CallResponseType("navigate")
)
View Source
const (
	PropOAuth2ClientSecret = "oauth2_client_secret" // nolint:gosec
	PropAppBindings        = "app_bindings"
)
View Source
const (
	ExpandDefault = ExpandLevel("")
	ExpandNone    = ExpandLevel("none")
	ExpandAll     = ExpandLevel("all")
	ExpandSummary = ExpandLevel("summary")
)
View Source
const (
	FieldTypeText          = FieldType("text")
	FieldTypeStaticSelect  = FieldType("static_select")
	FieldTypeDynamicSelect = FieldType("dynamic_select")
	FieldTypeBool          = FieldType("bool")
	FieldTypeUser          = FieldType("user")
	FieldTypeChannel       = FieldType("channel")
)
View Source
const (
	PermissionUserJoinedChannelNotification = PermissionType("user_joined_channel_notification")
	PermissionAddGrants                     = PermissionType("add_grants")
	PermissionActAsUser                     = PermissionType("act_as_user")
	PermissionActAsBot                      = PermissionType("act_as_bot")
)
View Source
const (
	SubjectUserCreated       = Subject("user_created")
	SubjectUserJoinedChannel = Subject("user_joined_channel")
	SubjectUserLeftChannel   = Subject("user_left_channel")
	SubjectUserJoinedTeam    = Subject("user_joined_team")
	SubjectUserLeftTeam      = Subject("user_left_team")
	SubjectUserUpdated       = Subject("user_updated")
	SubjectChannelCreated    = Subject("channel_created")
	SubjectPostCreated       = Subject("post_created")
)

Variables

View Source
var DefaultBindingsCall = &Call{
	Path: DefaultBindingsCallPath,
}
View Source
var DefaultInstallCall = &Call{
	Path: DefaultInstallCallPath,
	Expand: &Expand{
		App:              ExpandAll,
		AdminAccessToken: ExpandAll,
	},
}

Functions

This section is empty.

Types

type App

type App struct {
	AppID    AppID     `json:"app_id"`
	Manifest *Manifest `json:"manifest"`
	Status   AppStatus `json:"app_status"`

	// Secret is used to issue JWT
	Secret string `json:"secret,omitempty"`

	OAuth2ClientID     string `json:"oauth2_client_id,omitempty"`
	OAuth2ClientSecret string `json:"oauth2_client_secret,omitempty"`
	OAuth2TrustedApp   bool   `json:"oauth2_trusted_app,omitempty"`

	BotUserID      string `json:"bot_user_id,omitempty"`
	BotUsername    string `json:"bot_username,omitempty"`
	BotAccessToken string `json:"bot_access_token,omitempty"`

	// Grants should be scopable in the future, per team, channel, post with
	// regexp.
	GrantedPermissions Permissions `json:"granted_permissions,omitempty"`

	// GrantedLocations contains the list of top locations that the
	// application is allowed to bind to.
	GrantedLocations Locations `json:"granted_locations,omitempty"`
}

func AppFromConfigMap

func AppFromConfigMap(in interface{}) *App

func (*App) ConfigMap

func (a *App) ConfigMap() map[string]interface{}

type AppID

type AppID string

AppID is a globally unique identifier that represents a Mattermost App. Allowed characters are letters, numbers, underscores and hyphens.

func (AppID) IsValid

func (id AppID) IsValid() error

type AppStatus

type AppStatus string

AppStatus describes status of the app

const (
	AppStatusRegistered AppStatus = "registered"
	AppStatusInstalled  AppStatus = "installed"
)

type AppType

type AppType string
const (
	AppTypeHTTP      AppType = "http"
	AppTypeAWSLambda AppType = "aws_lambda"
	AppTypeBuiltin   AppType = "builtin"
)

default is HTTP

func (AppType) IsValid

func (at AppType) IsValid() bool

type AppVersion

type AppVersion string

AppVersion is the version of a Mattermost App. Allowed characters are letters, numbers, underscores and hyphens.

func (AppVersion) IsValid

func (v AppVersion) IsValid() error

type AppVersionMap

type AppVersionMap map[AppID]AppVersion

type Binding

type Binding struct {
	// For internal use by Mattermost, Apps do not need to set.
	AppID AppID `json:"app_id,omitempty"`

	// Location allows the App to identify where in the UX the Call request
	// comes from. It is optional. For /command bindings, Location is
	// defaulted to Label.
	Location Location `json:"location,omitempty"`

	// For PostMenu, ChannelHeader locations specifies the icon.
	Icon string `json:"icon,omitempty"`

	// Label is the (usually short) primary text to display at the location.
	// - For LocationPostMenu is the menu item text.
	// - For LocationChannelHeader is the dropdown text.
	// - For LocationCommand is the name of the command
	// - For InPost is the title
	Label string `json:"label,omitempty"`

	// Hint is the secondary text to display
	// - LocationPostMenu: not used
	// - LocationChannelHeader: tooltip
	// - LocationCommand: the "Hint" line
	Hint string `json:"hint,omitempty"`

	// Description is the (optional) extended help text, used in modals and autocomplete
	// - For InPost is the text of the embed
	Description string `json:"description,omitempty"`

	RoleID           string `json:"role_id,omitempty"`
	DependsOnTeam    bool   `json:"depends_on_team,omitempty"`
	DependsOnChannel bool   `json:"depends_on_channel,omitempty"`
	DependsOnUser    bool   `json:"depends_on_user,omitempty"`
	DependsOnPost    bool   `json:"depends_on_post,omitempty"`

	// A Binding is either to a Call, or is a "container" for other locations -
	// i.e. menu sub-items or subcommands. An app-defined Modal can be displayed
	// by setting AsModal.
	Call     *Call      `json:"call,omitempty"`
	Bindings []*Binding `json:"bindings,omitempty"`

	// Form allows to embed a form into a binding, and avoid the need to
	// Call(type=Form). At the moment, the sole use case is in-post forms, but
	// this may prove useful in other contexts.
	// TODO: Can embedded forms be mutable, and what does it mean?
	Form *Form `json:"form,omitempty"`
}

type Call

type Call struct {
	Path       string                 `json:"path,omitempty"`
	Type       CallType               `json:"type"`
	Values     map[string]interface{} `json:"values,omitempty"`
	Context    *Context               `json:"context,omitempty"`
	RawCommand string                 `json:"raw_command,omitempty"`
	Expand     *Expand                `json:"expand,omitempty"`
}

A Call invocation is supplied a BotAccessToken as part of the context. If a call needs acting user's or admin tokens, it should be specified in the Expand section.

If a user or admin token are required and are not available from previous consent, the appropriate OAuth flow is launched, and the Call is executed upon its success.

TODO: what if a call needs a token and it was not provided? Return a call to itself with Expand.

func MakeCall

func MakeCall(url string, namevalues ...string) *Call

func UnmarshalCallFromData

func UnmarshalCallFromData(data []byte) (*Call, error)

func UnmarshalCallFromReader

func UnmarshalCallFromReader(in io.Reader) (*Call, error)

func (*Call) GetValue

func (c *Call) GetValue(name, defaultValue string) string

type CallResponse

type CallResponse struct {
	Type CallResponseType `json:"type"`

	// Used in CallResponseTypeOK to return the displayble, and JSON results
	Markdown md.MD       `json:"markdown,omitempty"`
	Data     interface{} `json:"data,omitempty"`

	// Used in CallResponseTypeError
	ErrorText string `json:"error,omitempty"`

	// Used in CallResponseTypeNavigate
	NavigateToURL      string `json:"navigate_to_url,omitempty"`
	UseExternalBrowser bool   `json:"use_external_browser,omitempty"`

	// Used in CallResponseTypeCall
	Call *Call `json:"call,omitempty"`

	// Used in CallResponseTypeForm
	Form *Form `json:"form,omitempty"`
}

func NewErrorCallResponse

func NewErrorCallResponse(err error) *CallResponse

func (*CallResponse) Error

func (cr *CallResponse) Error() string

Error() makes CallResponse a valid error, for convenience

type CallResponseType

type CallResponseType string

type CallType

type CallType string

type Context

type Context struct {
	AppID             AppID             `json:"app_id"`
	Location          Location          `json:"location,omitempty"`
	Subject           Subject           `json:"subject,omitempty"`
	BotUserID         string            `json:"bot_user_id,omitempty"`
	ActingUserID      string            `json:"acting_user_id,omitempty"`
	UserID            string            `json:"user_id,omitempty"`
	TeamID            string            `json:"team_id"`
	ChannelID         string            `json:"channel_id,omitempty"`
	PostID            string            `json:"post_id,omitempty"`
	RootPostID        string            `json:"root_post_id,omitempty"`
	Props             map[string]string `json:"props,omitempty"`
	MattermostSiteURL string            `json:"mattermost_site_url"`
	ExpandedContext
}

func NewChannelContext

func NewChannelContext(ch *model.Channel) *Context

func NewChannelMemberContext

func NewChannelMemberContext(cm *model.ChannelMember, actingUser *model.User) *Context

func NewCommandContext

func NewCommandContext(commandArgs *model.CommandArgs) *Context

func NewPostContext

func NewPostContext(p *model.Post) *Context

func NewTeamMemberContext

func NewTeamMemberContext(tm *model.TeamMember, actingUser *model.User) *Context

func NewUserContext

func NewUserContext(user *model.User) *Context

func (*Context) GetProp

func (cc *Context) GetProp(n string) string

func (*Context) SetProp

func (cc *Context) SetProp(n, v string)

type Expand

type Expand struct {
	App        ExpandLevel `json:"app,omitempty"`
	ActingUser ExpandLevel `json:"acting_user,omitempty"`

	// ActingUserAccessToken instruct the proxy to include OAuth2 access token
	// in the request. If the token is not available or is invalid, the user is
	// directed to the OAuth2 flow, and the Call is executed upon completion.
	ActingUserAccessToken ExpandLevel `json:"acting_user_access_token,omitempty"`

	// AdminAccessToken instructs the proxy to include an admin access token.
	AdminAccessToken ExpandLevel `json:"admin_access_token,omitempty"`

	Channel    ExpandLevel `json:"channel,omitempty"`
	Mentioned  ExpandLevel `json:"mentioned,omitempty"`
	ParentPost ExpandLevel `json:"parent_post,omitempty"`
	Post       ExpandLevel `json:"post,omitempty"`
	RootPost   ExpandLevel `json:"root_post,omitempty"`
	Team       ExpandLevel `json:"team,omitempty"`
	User       ExpandLevel `json:"user,omitempty"`
}

type ExpandLevel

type ExpandLevel string

type ExpandedContext

type ExpandedContext struct {
	//  BotAccessToken is always provided in expanded context
	BotAccessToken string `json:"bot_access_token,omitempty"`

	ActingUser            *model.User    `json:"acting_user,omitempty"`
	ActingUserAccessToken string         `json:"acting_user_access_token,omitempty"`
	AdminAccessToken      string         `json:"admin_access_token,omitempty"`
	App                   *App           `json:"app,omitempty"`
	Channel               *model.Channel `json:"channel,omitempty"`
	Mentioned             []*model.User  `json:"mentioned,omitempty"`
	Post                  *model.Post    `json:"post,omitempty"`
	RootPost              *model.Post    `json:"root_post,omitempty"`
	Team                  *model.Team    `json:"team,omitempty"`

	// TODO replace User with mentions
	User *model.User `json:"user,omitempty"`
}

type Field

type Field struct {
	// Name is the name of the JSON field to use.
	Name       string    `json:"name"`
	Type       FieldType `json:"type"`
	IsRequired bool      `json:"is_required,omitempty"`

	// Present (default) value of the field
	Value interface{} `json:"value,omitempty"`

	Description string `json:"description,omitempty"`

	Label                string `json:"label,omitempty"`
	AutocompleteHint     string `json:"hint,omitempty"`
	AutocompletePosition int    `json:"position,omitempty"`

	ModalLabel string `json:"modal_label"`

	// Select props
	SelectRefresh       bool           `json:"refresh,omitempty"`
	SelectStaticOptions []SelectOption `json:"options,omitempty"`

	// Text props
	TextSubtype   string `json:"subtype,omitempty"`
	TextMinLength int    `json:"min_length,omitempty"`
	TextMaxLength int    `json:"max_length,omitempty"`
}

type FieldType

type FieldType string

type Form

type Form struct {
	Title  string `json:"title,omitempty"`
	Header string `json:"header,omitempty"`
	Footer string `json:"footer,omitempty"`
	Icon   string `json:"icon,omitempty"`

	Call *Call `json:"call,omitempty"`

	// SubmitButtons refers to a field name that must be a FieldTypeStaticSelect
	// or FieldTypeDynamicSelect.
	//
	// In Modal view, the field will be rendered as a list of buttons at the
	// bottom. Clicking one of them submits the Call, providing the button
	// reference as the corresponding Field's value. Leaving this property
	// blank, displays the default "OK" button.
	//
	// In Autocomplete, it is ignored.
	SubmitButtons string `json:"submit_buttons,omitempty"`

	// Adds a default "Cancel" button in the modal view
	CancelButton  bool `json:"cancel_button,omitempty"`
	SubmitOnCanel bool `json:"submit_on_cancel,omitempty"`

	// DependsOn is the list of field names that when changed force reloading
	// the form. Values of the fields with values that are not included in the
	// refreshed form are lost.
	DependsOn []string `json:"depends_on,omitempty"`

	Fields []*Field `json:"fields,omitempty"`
}

type Function

type Function struct {
	Name    string `json:"name"`
	Handler string `json:"handler"`
	Runtime string `json:"runtime"`
}

Function describes app's function mapping For now Function can be either AWS Lambda or HTTP function

type InInstallApp

type InInstallApp struct {
	GrantedPermissions Permissions `json:"granted_permissions,omitempty"`
	GrantedLocations   Locations   `json:"granted_locations,omitempty"`
	AppSecret          string      `json:"app_secret,omitempty"`
	OAuth2TrustedApp   bool        `json:"oauth2_trusted_app,omitempty"`
}

type InProvisionApp

type InProvisionApp struct {
	Manifest  *Manifest `json:"manifest"`
	AppSecret string    `json:"app_secret,omitempty"`
	Force     bool      `json:"force,omitempty"`
}

type Location

type Location string
const (
	LocationPostMenu      Location = "/post_menu"
	LocationChannelHeader Location = "/channel_header"
	LocationCommand       Location = "/command"
	LocationInPost        Location = "/in_post"
)

func (Location) In

func (l Location) In(other Location) bool

func (Location) IsTop

func (l Location) IsTop() bool

func (Location) Make

func (l Location) Make(sub Location) Location

func (Location) Markdown

func (l Location) Markdown() md.MD

type Locations

type Locations []Location

type Manifest

type Manifest struct {
	AppID       AppID      `json:"app_id"`
	Type        AppType    `json:"app_type"`
	Version     AppVersion `json:"version"`
	DisplayName string     `json:"display_name,omitempty"`
	Description string     `json:"description,omitempty"`

	HomepageURL string `json:"homepage_url,omitempty"`

	// HTTPRootURL applicable For AppTypeHTTP.
	//
	// TODO: check if it is used in the // user-agent, consider naming
	// consistently.
	HTTPRootURL string `json:"root_url,omitempty"`

	RequestedPermissions Permissions `json:"requested_permissions,omitempty"`

	// RequestedLocations is the list of top-level locations that the
	// application intends to bind to, e.g. `{"/post_menu", "/channel_header",
	// "/command/apptrigger"}“.
	RequestedLocations Locations `json:"requested_locations,omitempty"`

	// By default invoke "/install", expanding App, AdminAccessToken, and
	// Config.
	OnInstall   *Call `json:"on_install,omitempty"`
	OnUninstall *Call `json:"on_uninstall,omitempty"`
	OnStartup   *Call `json:"on_startup,omitempty"`

	// By default invoke "/bindings".
	Bindings *Call `json:"bindings,omitempty"`

	// Deployment manifest for hostable apps will include path->invoke mappings
	Functions []Function
}

type PermissionType

type PermissionType string

func (PermissionType) Markdown

func (p PermissionType) Markdown() md.MD

type Permissions

type Permissions []PermissionType

func (Permissions) Contains

func (p Permissions) Contains(permission PermissionType) bool

type SelectOption

type SelectOption struct {
	Label    string `json:"label"`
	Value    string `json:"value"`
	IconData string `json:"icon_data"`
}

type SessionToken

type SessionToken string

type Subject

type Subject string

type Subscription

type Subscription struct {
	AppID   AppID   `json:"app_id"`
	Subject Subject `json:"subject"`

	// Scope
	ChannelID string `json:"channel_id,omitempty"`
	TeamID    string `json:"team_id,omitempty"`

	Call *Call
}

func (*Subscription) EqualScope

func (sub *Subscription) EqualScope(other *Subscription) bool

func (*Subscription) ToJSON

func (sub *Subscription) ToJSON() string

type SubscriptionResponse

type SubscriptionResponse struct {
	Error  string            `json:"error,omitempty"`
	Errors map[string]string `json:"errors,omitempty"`
}

func SubscriptionResponseFromJSON

func SubscriptionResponseFromJSON(data io.Reader) *SubscriptionResponse

func (*SubscriptionResponse) ToJSON

func (r *SubscriptionResponse) ToJSON() []byte

type Thread

type Thread struct {
	ChannelID  string `json:"channel_id"`
	RootPostID string `json:"root_post_id"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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