Documentation ¶
Overview ¶
Package client provides an HTTP client for using the Playbooks API.
Example ¶
package main import ( "context" "fmt" "log" "github.com/mattermost/mattermost-plugin-playbooks/client" "github.com/mattermost/mattermost-server/v6/model" ) func main() { ctx := context.Background() client4 := model.NewAPIv4Client("http://localhost:8065") _, _, err := client4.Login("test@example.com", "testtest") if err != nil { log.Fatal(err) } c, err := client.New(client4) if err != nil { log.Fatal(err) } playbookRunID := "h4n3h7s1qjf5pkis4dn6cuxgwa" playbookRun, err := c.PlaybookRuns.Get(ctx, playbookRunID) if err != nil { log.Fatal(err) } fmt.Printf("Playbook Run Name: %s\n", playbookRun.Name) }
Output:
Index ¶
- Constants
- type Checklist
- type ChecklistItem
- type Client
- type ErrorResponse
- type GetPlaybookRunsResults
- type GetPlaybooksResults
- type GlobalSettings
- type Playbook
- type PlaybookCreateOptions
- type PlaybookListOptions
- type PlaybookMember
- type PlaybookRun
- type PlaybookRunCreateOptions
- type PlaybookRunList
- type PlaybookRunListOptions
- type PlaybookRunMetadata
- type PlaybookRunService
- func (s *PlaybookRunService) AddChecklistItem(ctx context.Context, playbookRunID string, checklistNumber int, ...) error
- func (s *PlaybookRunService) Create(ctx context.Context, opts PlaybookRunCreateOptions) (*PlaybookRun, error)
- func (s *PlaybookRunService) CreateChecklist(ctx context.Context, playbookRunID string, checklist Checklist) error
- func (s *PlaybookRunService) Finish(ctx context.Context, playbookRunID string) error
- func (s *PlaybookRunService) Get(ctx context.Context, playbookRunID string) (*PlaybookRun, error)
- func (s *PlaybookRunService) GetByChannelID(ctx context.Context, channelID string) (*PlaybookRun, error)
- func (s *PlaybookRunService) GetMetadata(ctx context.Context, playbookRunID string) (*PlaybookRunMetadata, error)
- func (s *PlaybookRunService) List(ctx context.Context, page, perPage int, opts PlaybookRunListOptions) (*GetPlaybookRunsResults, error)
- func (s *PlaybookRunService) MoveChecklist(ctx context.Context, playbookRunID string, ...) error
- func (s *PlaybookRunService) MoveChecklistItem(ctx context.Context, playbookRunID string, ...) error
- func (s *PlaybookRunService) RemoveChecklist(ctx context.Context, playbookRunID string, checklistNumber int) error
- func (s *PlaybookRunService) RenameChecklist(ctx context.Context, playbookRunID string, checklistNumber int, ...) error
- func (s *PlaybookRunService) UpdateStatus(ctx context.Context, playbookRunID string, message string, ...) error
- type PlaybooksService
- func (s *PlaybooksService) Archive(ctx context.Context, playbookID string) error
- func (s *PlaybooksService) Create(ctx context.Context, opts PlaybookCreateOptions) (string, error)
- func (s *PlaybooksService) Get(ctx context.Context, playbookID string) (*Playbook, error)
- func (s *PlaybooksService) List(ctx context.Context, teamId string, page, perPage int, ...) (*GetPlaybooksResults, error)
- func (s *PlaybooksService) Update(ctx context.Context, playbook Playbook) error
- type SettingsService
- type Sort
- type SortDirection
- type Status
- type StatusPost
- type StatusUpdateOptions
- type TimelineEvent
- type TimelineEventType
Examples ¶
Constants ¶
const Me = "me"
Me is a constant that refers to the current user, and can be used in various APIs in place of explicitly specifying the current user's id.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Checklist ¶
type Checklist struct { ID string `json:"id"` Title string `json:"title"` Items []ChecklistItem `json:"items"` }
Checklist represents a checklist in a playbook
type ChecklistItem ¶
type ChecklistItem struct { ID string `json:"id"` Title string `json:"title"` State string `json:"state"` StateModified int64 `json:"state_modified"` AssigneeID string `json:"assignee_id"` AssigneeModified int64 `json:"assignee_modified"` Command string `json:"command"` CommandLastRun int64 `json:"command_last_run"` Description string `json:"description"` }
ChecklistItem represents an item in a checklist
type Client ¶
type Client struct { // BaseURL is the base HTTP endpoint for the Playbooks plugin. BaseURL *url.URL // User agent used when communicating with the Playbooks API. UserAgent string // PlaybookRuns is a collection of methods used to interact with playbook runs. PlaybookRuns *PlaybookRunService // Playbooks is a collection of methods used to interact with playbooks. Playbooks *PlaybooksService // Settings is a collection of methods used to interact with settings. Settings *SettingsService // contains filtered or unexported fields }
Client manages communication with the Playbooks API.
type ErrorResponse ¶
type ErrorResponse struct { // Method is the HTTP verb used in the API request. Method string // URL is the HTTP endpoint used in the API request. URL string // StatusCode is the HTTP status code returned by the API. StatusCode int // Err is the error parsed from the API response. Err error `json:"error"` }
ErrorResponse is an error from an API request.
func (*ErrorResponse) Error ¶
func (r *ErrorResponse) Error() string
Error describes the error from the API request.
func (*ErrorResponse) UnmarshalJSON ¶
func (e *ErrorResponse) UnmarshalJSON(data []byte) error
func (*ErrorResponse) Unwrap ¶
func (r *ErrorResponse) Unwrap() error
Unwrap exposes the underlying error of an ErrorResponse.
type GetPlaybookRunsResults ¶
type GetPlaybookRunsResults struct { TotalCount int `json:"total_count"` PageCount int `json:"page_count"` HasMore bool `json:"has_more"` Items []PlaybookRun `json:"items"` Disabled bool `json:"disabled"` }
type GetPlaybooksResults ¶
type GlobalSettings ¶
type GlobalSettings struct { // EnableExperimentalFeatures is a read-only field set to true when experimental features // are enabled. Changing this field requires access to the system console plugin // configuration. EnableExperimentalFeatures bool `json:"enable_experimental_features"` }
type Playbook ¶
type Playbook struct { ID string `json:"id"` Title string `json:"title"` Description string `json:"description"` Public bool `json:"public"` TeamID string `json:"team_id"` CreatePublicPlaybookRun bool `json:"create_public_playbook_run"` CreateAt int64 `json:"create_at"` DeleteAt int64 `json:"delete_at"` NumStages int64 `json:"num_stages"` NumSteps int64 `json:"num_steps"` Checklists []Checklist `json:"checklists"` Members []PlaybookMember `json:"members"` ReminderMessageTemplate string `json:"reminder_message_template"` ReminderTimerDefaultSeconds int64 `json:"reminder_timer_default_seconds"` InvitedUserIDs []string `json:"invited_user_ids"` InvitedGroupIDs []string `json:"invited_group_ids"` InvitedUsersEnabled bool `json:"invited_users_enabled"` DefaultOwnerID string `json:"default_owner_id"` DefaultOwnerEnabled bool `json:"default_owner_enabled"` BroadcastChannelIDs []string `json:"broadcast_channel_ids"` BroadcastEnabled bool `json:"broadcast_enabled"` }
Playbook represents the planning before a playbook run is initiated.
type PlaybookCreateOptions ¶
type PlaybookCreateOptions struct { Title string `json:"title"` Description string `json:"description"` TeamID string `json:"team_id"` Public bool `json:"public"` CreatePublicPlaybookRun bool `json:"create_public_playbook_run"` Checklists []Checklist `json:"checklists"` Members []PlaybookMember `json:"members"` BroadcastChannelID string `json:"broadcast_channel_id"` ReminderMessageTemplate string `json:"reminder_message_template"` ReminderTimerDefaultSeconds int64 `json:"reminder_timer_default_seconds"` InvitedUserIDs []string `json:"invited_user_ids"` InvitedGroupIDs []string `json:"invited_group_ids"` InviteUsersEnabled bool `json:"invite_users_enabled"` DefaultOwnerID string `json:"default_owner_id"` DefaultOwnerEnabled bool `json:"default_owner_enabled"` BroadcastChannelIDs []string `json:"broadcast_channel_ids"` BroadcastEnabled bool `json:"broadcast_enabled"` }
PlaybookCreateOptions specifies the parameters for PlaybooksService.Create method.
type PlaybookListOptions ¶
type PlaybookListOptions struct { Sort Sort `url:"sort,omitempty"` Direction SortDirection `url:"direction,omitempty"` SearchTeam string `url:"search_term,omitempty"` }
PlaybookListOptions specifies the optional parameters to the PlaybooksService.List method.
type PlaybookMember ¶ added in v0.7.0
type PlaybookRun ¶
type PlaybookRun struct { ID string `json:"id"` Name string `json:"name"` Description string `json:"description"` OwnerUserID string `json:"owner_user_id"` ReporterUserID string `json:"reporter_user_id"` TeamID string `json:"team_id"` ChannelID string `json:"channel_id"` CreateAt int64 `json:"create_at"` EndAt int64 `json:"end_at"` DeleteAt int64 `json:"delete_at"` ActiveStage int `json:"active_stage"` ActiveStageTitle string `json:"active_stage_title"` PostID string `json:"post_id"` PlaybookID string `json:"playbook_id"` Checklists []Checklist `json:"checklists"` StatusPosts []StatusPost `json:"status_posts"` ReminderPostID string `json:"reminder_post_id"` PreviousReminder time.Duration `json:"previous_reminder"` BroadcastChannelID string `json:"broadcast_channel_id"` ReminderMessageTemplate string `json:"reminder_message_template"` InvitedUserIDs []string `json:"invited_user_ids"` InvitedGroupIDs []string `json:"invited_group_ids"` TimelineEvents []TimelineEvent `json:"timeline_events"` CategorizeChannelEnabled bool `json:"categorize_channel_enabled"` }
PlaybookRun represents a playbook run.
type PlaybookRunCreateOptions ¶
type PlaybookRunCreateOptions struct { Name string `json:"name"` OwnerUserID string `json:"owner_user_id"` TeamID string `json:"team_id"` Description string `json:"description"` PostID string `json:"post_id"` PlaybookID string `json:"playbook_id"` }
PlaybookRunCreateOptions specifies the parameters for PlaybookRunService.Create method.
type PlaybookRunList ¶
type PlaybookRunList struct { TotalCount int `json:"total_count"` PageCount int `json:"page_count"` HasMore bool `json:"has_more"` Items []*PlaybookRun }
PlaybookRunList contains the paginated result.
type PlaybookRunListOptions ¶
type PlaybookRunListOptions struct { // TeamID filters playbook runs to those in the given team. TeamID string `url:"team_id,omitempty"` Sort Sort `url:"sort,omitempty"` Direction SortDirection `url:"direction,omitempty"` // Statuses filters by InProgress or Ended; defaults to All when no status specified. Statuses []Status `url:"statuses,omitempty"` // OwnerID filters by owner's Mattermost user ID. Defaults to blank (no filter). Specify "me" for current user. OwnerID string `url:"owner_user_id,omitempty"` // ParticipantID filters playbook runs that have this user as a participant. Defaults to blank (no filter). Specify "me" for current user. ParticipantID string `url:"participant_id,omitempty"` // ParticipantOrFollowerID filters playbook runs that have this user as member or as follower. Defaults to blank (no filter). Specify "me" for current user. ParticipantOrFollowerID string `url:"participant_or_follower,omitempty"` // SearchTerm returns results of the search term and respecting the other header filter options. // The search term acts as a filter and respects the Sort and Direction fields (i.e., results are // not returned in relevance order). SearchTerm string `url:"search_term,omitempty"` // PlaybookID filters playbook runs that are derived from this playbook id. // Defaults to blank (no filter). PlaybookID string `url:"playbook_id,omitempty"` // ActiveGTE filters playbook runs that were active after (or equal) to the unix time given (in millis). // A value of 0 means the filter is ignored (which is the default). ActiveGTE int64 `url:"active_gte,omitempty"` // ActiveLT filters playbook runs that were active before the unix time given (in millis). // A value of 0 means the filter is ignored (which is the default). ActiveLT int64 `url:"active_lt,omitempty"` // StartedGTE filters playbook runs that were started after (or equal) to the unix time given (in millis). // A value of 0 means the filter is ignored (which is the default). StartedGTE int64 `url:"started_gte,omitempty"` // StartedLT filters playbook runs that were started before the unix time given (in millis). // A value of 0 means the filter is ignored (which is the default). StartedLT int64 `url:"started_lt,omitempty"` }
PlaybookRunListOptions specifies the optional parameters to the PlaybookRunService.List method.
type PlaybookRunMetadata ¶
type PlaybookRunMetadata struct { ChannelName string `json:"channel_name"` ChannelDisplayName string `json:"channel_display_name"` TeamName string `json:"team_name"` NumParticipants int64 `json:"num_participants"` TotalPosts int64 `json:"total_posts"` Followers []string `json:"followers"` }
PlaybookRunMetadata tracks ancillary metadata about a playbook run.
type PlaybookRunService ¶
type PlaybookRunService struct {
// contains filtered or unexported fields
}
PlaybookRunService handles communication with the playbook run related methods of the Playbooks API.
func (*PlaybookRunService) AddChecklistItem ¶ added in v0.7.0
func (s *PlaybookRunService) AddChecklistItem(ctx context.Context, playbookRunID string, checklistNumber int, checklistItem ChecklistItem) error
func (*PlaybookRunService) Create ¶
func (s *PlaybookRunService) Create(ctx context.Context, opts PlaybookRunCreateOptions) (*PlaybookRun, error)
Create a playbook run.
func (*PlaybookRunService) CreateChecklist ¶ added in v0.7.0
func (*PlaybookRunService) Finish ¶ added in v0.6.0
func (s *PlaybookRunService) Finish(ctx context.Context, playbookRunID string) error
func (*PlaybookRunService) Get ¶
func (s *PlaybookRunService) Get(ctx context.Context, playbookRunID string) (*PlaybookRun, error)
Get a playbook run.
Example ¶
package main import ( "context" "fmt" "log" "github.com/mattermost/mattermost-plugin-playbooks/client" "github.com/mattermost/mattermost-server/v6/model" ) func main() { ctx := context.Background() client4 := model.NewAPIv4Client("http://localhost:8065") client4.Login("test@example.com", "testtest") c, err := client.New(client4) if err != nil { log.Fatal(err) } playbookRunID := "h4n3h7s1qjf5pkis4dn6cuxgwa" playbookRun, err := c.PlaybookRuns.Get(ctx, playbookRunID) if err != nil { log.Fatal(err) } fmt.Printf("Playbook Run Name: %s\n", playbookRun.Name) }
Output:
func (*PlaybookRunService) GetByChannelID ¶
func (s *PlaybookRunService) GetByChannelID(ctx context.Context, channelID string) (*PlaybookRun, error)
GetByChannelID gets a playbook run by ChannelID.
func (*PlaybookRunService) GetMetadata ¶
func (s *PlaybookRunService) GetMetadata(ctx context.Context, playbookRunID string) (*PlaybookRunMetadata, error)
Get a playbook run's metadata.
func (*PlaybookRunService) List ¶
func (s *PlaybookRunService) List(ctx context.Context, page, perPage int, opts PlaybookRunListOptions) (*GetPlaybookRunsResults, error)
List the playbook runs.
Example ¶
package main import ( "context" "fmt" "log" "github.com/mattermost/mattermost-plugin-playbooks/client" "github.com/mattermost/mattermost-server/v6/model" ) func main() { ctx := context.Background() client4 := model.NewAPIv4Client("http://localhost:8065") _, _, err := client4.Login("test@example.com", "testtest") if err != nil { log.Fatal(err.Error()) } teams, _, err := client4.GetAllTeams("", 0, 1) if err != nil { log.Fatal(err.Error()) } if len(teams) == 0 { log.Fatal("no teams for this user") } c, err := client.New(client4) if err != nil { log.Fatal(err) } var playbookRuns []client.PlaybookRun for page := 0; ; page++ { result, err := c.PlaybookRuns.List(ctx, page, 100, client.PlaybookRunListOptions{ TeamID: teams[0].Id, Sort: client.SortByCreateAt, Direction: client.SortDesc, }) if err != nil { log.Fatal(err) } playbookRuns = append(playbookRuns, result.Items...) if !result.HasMore { break } } for _, playbookRun := range playbookRuns { fmt.Printf("Playbook Run Name: %s\n", playbookRun.Name) } }
Output:
func (*PlaybookRunService) MoveChecklist ¶ added in v0.7.0
func (*PlaybookRunService) MoveChecklistItem ¶ added in v0.7.0
func (*PlaybookRunService) RemoveChecklist ¶ added in v0.7.0
func (*PlaybookRunService) RenameChecklist ¶ added in v0.7.0
func (*PlaybookRunService) UpdateStatus ¶
type PlaybooksService ¶
type PlaybooksService struct {
// contains filtered or unexported fields
}
PlaybooksService handles communication with the playbook related methods of the Playbook API.
func (*PlaybooksService) Archive ¶ added in v0.7.0
func (s *PlaybooksService) Archive(ctx context.Context, playbookID string) error
func (*PlaybooksService) Create ¶
func (s *PlaybooksService) Create(ctx context.Context, opts PlaybookCreateOptions) (string, error)
Create a playbook. Returns the id of the newly created playbook
func (*PlaybooksService) Get ¶
Get a playbook.
Example ¶
package main import ( "context" "fmt" "log" "github.com/mattermost/mattermost-plugin-playbooks/client" "github.com/mattermost/mattermost-server/v6/model" ) func main() { ctx := context.Background() client4 := model.NewAPIv4Client("http://localhost:8065") client4.Login("test@example.com", "testtest") c, err := client.New(client4) if err != nil { log.Fatal(err) } playbookID := "h4n3h7s1qjf5pkis4dn6cuxgwa" playbook, err := c.Playbooks.Get(ctx, playbookID) if err != nil { log.Fatal(err) } fmt.Printf("Playbook Name: %s\n", playbook.Title) }
Output:
func (*PlaybooksService) List ¶
func (s *PlaybooksService) List(ctx context.Context, teamId string, page, perPage int, opts PlaybookListOptions) (*GetPlaybooksResults, error)
List the playbooks.
Example ¶
package main import ( "context" "fmt" "log" "github.com/mattermost/mattermost-plugin-playbooks/client" "github.com/mattermost/mattermost-server/v6/model" ) func main() { ctx := context.Background() client4 := model.NewAPIv4Client("http://localhost:8065") _, _, err := client4.Login("test@example.com", "testtest") if err != nil { log.Fatal(err.Error()) } teams, _, err := client4.GetAllTeams("", 0, 1) if err != nil { log.Fatal(err.Error()) } if len(teams) == 0 { log.Fatal("no teams for this user") } c, err := client.New(client4) if err != nil { log.Fatal(err) } var playbooks []client.Playbook for page := 0; ; page++ { result, err := c.Playbooks.List(ctx, teams[0].Id, page, 100, client.PlaybookListOptions{ Sort: client.SortByCreateAt, Direction: client.SortDesc, }) if err != nil { log.Fatal(err) } playbooks = append(playbooks, result.Items...) if !result.HasMore { break } } for _, playbook := range playbooks { fmt.Printf("Playbook Name: %s\n", playbook.Title) } }
Output:
type SettingsService ¶
type SettingsService struct {
// contains filtered or unexported fields
}
SettingsService handles communication with the settings related methods.
func (*SettingsService) Get ¶
func (s *SettingsService) Get(ctx context.Context) (*GlobalSettings, error)
Get the configured settings.
func (*SettingsService) Update ¶
func (s *SettingsService) Update(ctx context.Context, settings GlobalSettings) error
Update the configured settings.
type Sort ¶
type Sort string
Sort enumerates the available fields we can sort on.
const ( // SortByCreateAt sorts by the "create_at" field. It is the default. SortByCreateAt Sort = "create_at" // SortByID sorts by the "id" field. SortByID Sort = "id" // SortByName sorts by the "name" field. SortByName Sort = "name" // SortByOwnerUserID sorts by the "owner_user_id" field. SortByOwnerUserID Sort = "owner_user_id" // SortByTeamID sorts by the "team_id" field. SortByTeamID Sort = "team_id" // SortByEndAt sorts by the "end_at" field. SortByEndAt Sort = "end_at" // SortBySteps sorts playbooks by the number of steps in the playbook. SortBySteps Sort = "steps" // SortByStages sorts playbooks by the number of stages in the playbook. SortByStages Sort = "stages" // SortByTitle sorts by the "title" field. SortByTitle Sort = "title" // SortByRuns sorts by the number of times a playbook has been run. SortByRuns Sort = "runs" )
type SortDirection ¶
type SortDirection string
SortDirection determines whether results are sorted ascending or descending.
const ( // Desc sorts the results in descending order. SortDesc SortDirection = "desc" // Asc sorts the results in ascending order. SortAsc SortDirection = "asc" )
type Status ¶
type Status string
Status is the type used to specify the activity status of the playbook run.
type StatusPost ¶
type StatusPost struct { ID string `json:"id"` CreateAt int64 `json:"create_at"` DeleteAt int64 `json:"delete_at"` }
StatusPost is information added to the playbook run when selecting from the db and sent to the client; it is not saved to the db.
type StatusUpdateOptions ¶
type StatusUpdateOptions struct { Message string `json:"message"` ReminderInSeconds int64 `json:"reminder"` }
StatusUpdateOptions are the fields required to update a playbook run's status
type TimelineEvent ¶
type TimelineEvent struct { ID string `json:"id"` PlaybookRunID string `json:"playbook_run"` CreateAt int64 `json:"create_at"` DeleteAt int64 `json:"delete_at"` EventAt int64 `json:"event_at"` EventType TimelineEventType `json:"event_type"` Summary string `json:"summary"` Details string `json:"details"` PostID string `json:"post_id"` SubjectUserID string `json:"subject_user_id"` CreatorUserID string `json:"creator_user_id"` }
TimelineEvent represents an event recorded to a playbook run's timeline.
type TimelineEventType ¶
type TimelineEventType string
TimelineEventType describes a type of timeline event.
const ( PlaybookRunCreated TimelineEventType = "incident_created" TaskStateModified TimelineEventType = "task_state_modified" StatusUpdated TimelineEventType = "status_updated" OwnerChanged TimelineEventType = "owner_changed" AssigneeChanged TimelineEventType = "assignee_changed" RanSlashCommand TimelineEventType = "ran_slash_command" )