Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the MS Teams Tab App #1942

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defaults:

env:
TERM: xterm
GO_VERSION: 1.19.5
GO_VERSION: 1.22.6

jobs:
lint:
Expand Down
27 changes: 27 additions & 0 deletions assets/msteams_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions client/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type ActionsService struct {
// Create an action. Returns the id of the newly created action.
func (s *ActionsService) Create(ctx context.Context, channelID string, opts ChannelActionCreateOptions) (string, error) {
actionURL := fmt.Sprintf("actions/channels/%s", channelID)
req, err := s.client.newRequest(http.MethodPost, actionURL, opts)
req, err := s.client.newAPIRequest(http.MethodPost, actionURL, opts)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the first in a series of s/newRequest/newAPIRequest/ to allow the client package to be used with non-/api endpoints.

if err != nil {
return "", err
}
Expand Down Expand Up @@ -46,7 +46,7 @@ func (s *ActionsService) List(ctx context.Context, channelID string, opts Channe
return nil, fmt.Errorf("failed to build options: %w", err)
}

req, err := s.client.newRequest(http.MethodGet, actionURL, nil)
req, err := s.client.newAPIRequest(http.MethodGet, actionURL, nil)
if err != nil {
return nil, fmt.Errorf("failed to build request: %w", err)
}
Expand All @@ -64,7 +64,7 @@ func (s *ActionsService) List(ctx context.Context, channelID string, opts Channe
// Update an existing action.
func (s *ActionsService) Update(ctx context.Context, action GenericChannelAction) error {
updateURL := fmt.Sprintf("actions/channels/%s/%s", action.ChannelID, action.ID)
req, err := s.client.newRequest(http.MethodPut, updateURL, action)
req, err := s.client.newAPIRequest(http.MethodPut, updateURL, action)
if err != nil {
return err
}
Expand Down
12 changes: 10 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type Client struct {
Reminders *RemindersService
// Telemetry is a collection of methods used to interact with telemetry.
Telemetry *TelemetryService
// TabApp is a collection of methods used to interact with playbooks from the tabapp.
TabApp *TabAppService
}

// New creates a new instance of Client using the configuration from the given Mattermost Client.
Expand Down Expand Up @@ -77,12 +79,13 @@ func newClient(mattermostSiteURL string, httpClient *http.Client) (*Client, erro
c.Stats = &StatsService{c}
c.Reminders = &RemindersService{c}
c.Telemetry = &TelemetryService{c}
c.TabApp = &TabAppService{c}
return c, nil
}

// newRequest creates an API request, JSON-encoding any given body parameter.
func (c *Client) newRequest(method, endpoint string, body interface{}) (*http.Request, error) {
u, err := c.BaseURL.Parse(buildAPIURL(endpoint))
u, err := c.BaseURL.Parse(endpoint)
if err != nil {
return nil, errors.Wrapf(err, "invalid endpoint %s", endpoint)
}
Expand Down Expand Up @@ -112,6 +115,11 @@ func (c *Client) newRequest(method, endpoint string, body interface{}) (*http.Re
return req, nil
}

// newAPIRequest creates an API request, JSON-encoding any given body parameter.
func (c *Client) newAPIRequest(method, endpoint string, body interface{}) (*http.Request, error) {
return c.newRequest(method, buildAPIURL(endpoint), body)
}

// buildAPIURL constructs the path to the given endpoint.
func buildAPIURL(endpoint string) string {
return fmt.Sprintf("plugins/%s/api/%s/%s", manifestID, apiVersion, endpoint)
Expand Down Expand Up @@ -176,7 +184,7 @@ type GraphQLInput struct {

func (c *Client) DoGraphql(ctx context.Context, input *GraphQLInput, v interface{}) error {
url := "query"
req, err := c.newRequest(http.MethodPost, url, input)
req, err := c.newAPIRequest(http.MethodPost, url, input)
if err != nil {
return err
}
Expand Down
44 changes: 22 additions & 22 deletions client/playbook_runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type PlaybookRunService struct {
// Get a playbook run.
func (s *PlaybookRunService) Get(ctx context.Context, playbookRunID string) (*PlaybookRun, error) {
playbookRunURL := fmt.Sprintf("runs/%s", playbookRunID)
req, err := s.client.newRequest(http.MethodGet, playbookRunURL, nil)
req, err := s.client.newAPIRequest(http.MethodGet, playbookRunURL, nil)
if err != nil {
return nil, err
}
Expand All @@ -37,7 +37,7 @@ func (s *PlaybookRunService) Get(ctx context.Context, playbookRunID string) (*Pl
// GetByChannelID gets a playbook run by ChannelID.
func (s *PlaybookRunService) GetByChannelID(ctx context.Context, channelID string) (*PlaybookRun, error) {
channelURL := fmt.Sprintf("runs/channel/%s", channelID)
req, err := s.client.newRequest(http.MethodGet, channelURL, nil)
req, err := s.client.newAPIRequest(http.MethodGet, channelURL, nil)
if err != nil {
return nil, err
}
Expand All @@ -55,7 +55,7 @@ func (s *PlaybookRunService) GetByChannelID(ctx context.Context, channelID strin
// Get a playbook run's metadata.
func (s *PlaybookRunService) GetMetadata(ctx context.Context, playbookRunID string) (*Metadata, error) {
playbookRunURL := fmt.Sprintf("runs/%s/metadata", playbookRunID)
req, err := s.client.newRequest(http.MethodGet, playbookRunURL, nil)
req, err := s.client.newAPIRequest(http.MethodGet, playbookRunURL, nil)
if err != nil {
return nil, err
}
Expand All @@ -73,7 +73,7 @@ func (s *PlaybookRunService) GetMetadata(ctx context.Context, playbookRunID stri
// Get all playbook status updates.
func (s *PlaybookRunService) GetStatusUpdates(ctx context.Context, playbookRunID string) ([]StatusPostComplete, error) {
playbookRunURL := fmt.Sprintf("runs/%s/status-updates", playbookRunID)
req, err := s.client.newRequest(http.MethodGet, playbookRunURL, nil)
req, err := s.client.newAPIRequest(http.MethodGet, playbookRunURL, nil)
if err != nil {
return nil, err
}
Expand All @@ -100,7 +100,7 @@ func (s *PlaybookRunService) List(ctx context.Context, page, perPage int, opts P
return nil, fmt.Errorf("failed to build pagination options: %w", err)
}

req, err := s.client.newRequest(http.MethodGet, playbookRunURL, nil)
req, err := s.client.newAPIRequest(http.MethodGet, playbookRunURL, nil)
if err != nil {
return nil, fmt.Errorf("failed to build request: %w", err)
}
Expand All @@ -118,7 +118,7 @@ func (s *PlaybookRunService) List(ctx context.Context, page, perPage int, opts P
// Create a playbook run.
func (s *PlaybookRunService) Create(ctx context.Context, opts PlaybookRunCreateOptions) (*PlaybookRun, error) {
playbookRunURL := "runs"
req, err := s.client.newRequest(http.MethodPost, playbookRunURL, opts)
req, err := s.client.newAPIRequest(http.MethodPost, playbookRunURL, opts)
if err != nil {
return nil, err
}
Expand All @@ -143,7 +143,7 @@ func (s *PlaybookRunService) UpdateStatus(ctx context.Context, playbookRunID str
Message: message,
Reminder: time.Duration(reminderInSeconds),
}
req, err := s.client.newRequest(http.MethodPost, updateURL, opts)
req, err := s.client.newAPIRequest(http.MethodPost, updateURL, opts)
if err != nil {
return err
}
Expand All @@ -162,7 +162,7 @@ func (s *PlaybookRunService) UpdateStatus(ctx context.Context, playbookRunID str

func (s *PlaybookRunService) RequestUpdate(ctx context.Context, playbookRunID, userID string) error {
requestURL := fmt.Sprintf("runs/%s/request-update", playbookRunID)
req, err := s.client.newRequest(http.MethodPost, requestURL, nil)
req, err := s.client.newAPIRequest(http.MethodPost, requestURL, nil)
if err != nil {
return err
}
Expand All @@ -177,7 +177,7 @@ func (s *PlaybookRunService) RequestUpdate(ctx context.Context, playbookRunID, u

func (s *PlaybookRunService) Finish(ctx context.Context, playbookRunID string) error {
finishURL := fmt.Sprintf("runs/%s/finish", playbookRunID)
req, err := s.client.newRequest(http.MethodPut, finishURL, nil)
req, err := s.client.newAPIRequest(http.MethodPut, finishURL, nil)
if err != nil {
return err
}
Expand All @@ -192,7 +192,7 @@ func (s *PlaybookRunService) Finish(ctx context.Context, playbookRunID string) e

func (s *PlaybookRunService) CreateChecklist(ctx context.Context, playbookRunID string, checklist Checklist) error {
createURL := fmt.Sprintf("runs/%s/checklists", playbookRunID)
req, err := s.client.newRequest(http.MethodPost, createURL, checklist)
req, err := s.client.newAPIRequest(http.MethodPost, createURL, checklist)
if err != nil {
return err
}
Expand All @@ -203,7 +203,7 @@ func (s *PlaybookRunService) CreateChecklist(ctx context.Context, playbookRunID

func (s *PlaybookRunService) RemoveChecklist(ctx context.Context, playbookRunID string, checklistNumber int) error {
createURL := fmt.Sprintf("runs/%s/checklists/%d", playbookRunID, checklistNumber)
req, err := s.client.newRequest(http.MethodDelete, createURL, nil)
req, err := s.client.newAPIRequest(http.MethodDelete, createURL, nil)
if err != nil {
return err
}
Expand All @@ -214,7 +214,7 @@ func (s *PlaybookRunService) RemoveChecklist(ctx context.Context, playbookRunID

func (s *PlaybookRunService) RenameChecklist(ctx context.Context, playbookRunID string, checklistNumber int, newTitle string) error {
createURL := fmt.Sprintf("runs/%s/checklists/%d/rename", playbookRunID, checklistNumber)
req, err := s.client.newRequest(http.MethodPut, createURL, struct{ Title string }{newTitle})
req, err := s.client.newAPIRequest(http.MethodPut, createURL, struct{ Title string }{newTitle})
if err != nil {
return err
}
Expand All @@ -225,7 +225,7 @@ func (s *PlaybookRunService) RenameChecklist(ctx context.Context, playbookRunID

func (s *PlaybookRunService) AddChecklistItem(ctx context.Context, playbookRunID string, checklistNumber int, checklistItem ChecklistItem) error {
addURL := fmt.Sprintf("runs/%s/checklists/%d/add", playbookRunID, checklistNumber)
req, err := s.client.newRequest(http.MethodPost, addURL, checklistItem)
req, err := s.client.newAPIRequest(http.MethodPost, addURL, checklistItem)
if err != nil {
return err
}
Expand All @@ -241,7 +241,7 @@ func (s *PlaybookRunService) MoveChecklist(ctx context.Context, playbookRunID st
DestChecklistIdx int `json:"dest_checklist_idx"`
}{sourceChecklistIdx, destChecklistIdx}

req, err := s.client.newRequest(http.MethodPost, createURL, body)
req, err := s.client.newAPIRequest(http.MethodPost, createURL, body)
if err != nil {
return err
}
Expand All @@ -259,7 +259,7 @@ func (s *PlaybookRunService) MoveChecklistItem(ctx context.Context, playbookRunI
DestItemIdx int `json:"dest_item_idx"`
}{sourceChecklistIdx, sourceItemIdx, destChecklistIdx, destItemIdx}

req, err := s.client.newRequest(http.MethodPost, createURL, body)
req, err := s.client.newAPIRequest(http.MethodPost, createURL, body)
if err != nil {
return err
}
Expand All @@ -271,7 +271,7 @@ func (s *PlaybookRunService) MoveChecklistItem(ctx context.Context, playbookRunI
// UpdateRetrospective updates the run's retrospective info
func (s *PlaybookRunService) UpdateRetrospective(ctx context.Context, playbookRunID, userID string, retroUpdate RetrospectiveUpdate) error {
createURL := fmt.Sprintf("runs/%s/retrospective", playbookRunID)
req, err := s.client.newRequest(http.MethodPost, createURL, retroUpdate)
req, err := s.client.newAPIRequest(http.MethodPost, createURL, retroUpdate)
if err != nil {
return err
}
Expand All @@ -287,7 +287,7 @@ func (s *PlaybookRunService) UpdateRetrospective(ctx context.Context, playbookRu
// PublishRetrospective publishes the run's retrospective
func (s *PlaybookRunService) PublishRetrospective(ctx context.Context, playbookRunID, userID string, retroUpdate RetrospectiveUpdate) error {
createURL := fmt.Sprintf("runs/%s/retrospective/publish", playbookRunID)
req, err := s.client.newRequest(http.MethodPost, createURL, retroUpdate)
req, err := s.client.newAPIRequest(http.MethodPost, createURL, retroUpdate)
if err != nil {
return err
}
Expand All @@ -306,7 +306,7 @@ func (s *PlaybookRunService) SetItemAssignee(ctx context.Context, playbookRunID
AssigneeID string `json:"assignee_id"`
}{assigneeID}

req, err := s.client.newRequest(http.MethodPut, createURL, body)
req, err := s.client.newAPIRequest(http.MethodPut, createURL, body)
if err != nil {
return err
}
Expand All @@ -321,7 +321,7 @@ func (s *PlaybookRunService) SetItemCommand(ctx context.Context, playbookRunID s
Command string `json:"command"`
}{newCommand}

req, err := s.client.newRequest(http.MethodPut, createURL, body)
req, err := s.client.newAPIRequest(http.MethodPut, createURL, body)
if err != nil {
return err
}
Expand All @@ -333,7 +333,7 @@ func (s *PlaybookRunService) SetItemCommand(ctx context.Context, playbookRunID s
func (s *PlaybookRunService) RunItemCommand(ctx context.Context, playbookRunID string, checklistIdx int, itemIdx int) error {
createURL := fmt.Sprintf("runs/%s/checklists/%d/item/%d/run", playbookRunID, checklistIdx, itemIdx)

req, err := s.client.newRequest(http.MethodPost, createURL, nil)
req, err := s.client.newAPIRequest(http.MethodPost, createURL, nil)
if err != nil {
return err
}
Expand All @@ -348,7 +348,7 @@ func (s *PlaybookRunService) SetItemDueDate(ctx context.Context, playbookRunID s
DueDate int64 `json:"due_date"`
}{duedate}

req, err := s.client.newRequest(http.MethodPut, createURL, body)
req, err := s.client.newAPIRequest(http.MethodPut, createURL, body)
if err != nil {
return err
}
Expand All @@ -359,7 +359,7 @@ func (s *PlaybookRunService) SetItemDueDate(ctx context.Context, playbookRunID s

// Get a playbook run.
func (s *PlaybookRunService) GetOwners(ctx context.Context) ([]OwnerInfo, error) {
req, err := s.client.newRequest(http.MethodGet, "runs/owners", nil)
req, err := s.client.newAPIRequest(http.MethodGet, "runs/owners", nil)
if err != nil {
return nil, err
}
Expand Down
Loading
Loading