Implement create and get incoming webhook endpoints for APIv4 (#5407)
* Implement POST /hooks/incoming endpoint for APIv4 * Implement GET /hooks/incoming endpoint for APIv4 * Updates per feedback
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b61115df55
Коммит
69cac604e0
@@ -133,6 +133,10 @@ func (c *Client4) GetSystemRoute() string {
|
||||
return fmt.Sprintf("/system")
|
||||
}
|
||||
|
||||
func (c *Client4) GetIncomingWebhooksRoute() string {
|
||||
return fmt.Sprintf("/hooks/incoming")
|
||||
}
|
||||
|
||||
func (c *Client4) DoApiGet(url string, etag string) (*http.Response, *AppError) {
|
||||
return c.DoApiRequest(http.MethodGet, url, "", etag)
|
||||
}
|
||||
@@ -775,3 +779,37 @@ func (c *Client4) GetPing() (bool, *Response) {
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
}
|
||||
|
||||
// Webhooks Section
|
||||
|
||||
// CreateIncomingWebhook creates an incoming webhook for a channel.
|
||||
func (c *Client4) CreateIncomingWebhook(hook *IncomingWebhook) (*IncomingWebhook, *Response) {
|
||||
if r, err := c.DoApiPost(c.GetIncomingWebhooksRoute(), hook.ToJson()); err != nil {
|
||||
return nil, &Response{StatusCode: r.StatusCode, Error: err}
|
||||
} else {
|
||||
defer closeBody(r)
|
||||
return IncomingWebhookFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
}
|
||||
|
||||
// GetIncomingWebhooks returns a page of incoming webhooks on the system. Page counting starts at 0.
|
||||
func (c *Client4) GetIncomingWebhooks(page int, perPage int, etag string) ([]*IncomingWebhook, *Response) {
|
||||
query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage)
|
||||
if r, err := c.DoApiGet(c.GetIncomingWebhooksRoute()+query, etag); err != nil {
|
||||
return nil, &Response{StatusCode: r.StatusCode, Error: err}
|
||||
} else {
|
||||
defer closeBody(r)
|
||||
return IncomingWebhookListFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
}
|
||||
|
||||
// GetIncomingWebhooksForTeam returns a page of incoming webhooks for a team. Page counting starts at 0.
|
||||
func (c *Client4) GetIncomingWebhooksForTeam(teamId string, page int, perPage int, etag string) ([]*IncomingWebhook, *Response) {
|
||||
query := fmt.Sprintf("?page=%v&per_page=%v&team_id=%v", page, perPage, teamId)
|
||||
if r, err := c.DoApiGet(c.GetIncomingWebhooksRoute()+query, etag); err != nil {
|
||||
return nil, &Response{StatusCode: r.StatusCode, Error: err}
|
||||
} else {
|
||||
defer closeBody(r)
|
||||
return IncomingWebhookListFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user