### Show Server Install Help Handler Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/command-handler.md Initiates the interactive setup wizard for Confluence Server/Data Center configuration. It directs the user to a direct message with the bot to continue setup. ```go func showInstallServerHelp(p *Plugin, context *model.CommandArgs, _ ...string) *model.CommandResponse ``` -------------------------------- ### Show Cloud Install Help Handler Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/command-handler.md Displays installation instructions for Confluence Cloud setup. This handler is intended for system administrators. ```go func showInstallCloudHelp(_ *Plugin, context *model.CommandArgs, _ ...string) *model.CommandResponse ``` -------------------------------- ### Confluence Cloud Webhook Setup Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/webhooks.md Instructions for setting up a Confluence Cloud webhook by installing a private app in the Atlassian Admin console. This involves enabling development mode and providing the Mattermost plugin's App Descriptor URL. ```text 1. Open Atlassian Admin at https://admin.atlassian.com/ 2. Navigate to Apps > Sites > Your Site > Connected Apps 3. Enable Development Mode in Settings 4. Click "Install a private app" 5. Select Confluence as the product 6. Enter App Descriptor URL: ``` https://your-mattermost.com/plugins/confluence/api/v1/atlassian-connect.json ``` 7. Click Install ``` -------------------------------- ### Save Space Subscription Example Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/endpoints.md Example of saving a new space subscription for a Mattermost channel. Requires Mattermost-User-Id header for authentication and a JSON body specifying subscription details. ```bash curl -X POST "http://mattermost.local/plugins/confluence/api/v1/abc123/subscription/space_subscription" \ -H "Mattermost-User-Id: user_id_here" \ -H "Content-Type: application/json" \ -d '{ "alias": "Platform Project", "baseURL": "https://confluence.example.com", "spaceKey": "PROJ", "events": ["page_created", "comment_updated"], "channelID": "abc123", "subscriptionType": "space_subscription" }' ``` -------------------------------- ### GetCommand Example Usage Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/command-handler.md Demonstrates how to use the GetCommand function to obtain the command definition and register it with the Mattermost API. ```go cmd, err := GetCommand(p.API) if err != nil { return err } p.API.RegisterCommand(cmd) ``` -------------------------------- ### Plugin Main Entry Point Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/plugin.md The main entry point for the plugin, starting the Mattermost plugin framework. ```go func main() ``` ```go plugin.ClientMain(&Plugin{}) ``` -------------------------------- ### Confluence Cloud Webhook Example Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/endpoints.md Example of sending a POST request to the Confluence Cloud webhook endpoint to notify about a page creation event. Requires a secret for verification. ```bash curl -X POST "http://mattermost.local/plugins/confluence/api/v1/cloud/page_created?secret=XXXX" \ -H "Content-Type: application/json" \ -d '{ "type": "page.created", "page": { "id": "123456", "title": "My Page", "space": {"key": "PROJ"} } }' ``` -------------------------------- ### Create Space Subscription Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/subscriptions.md Example demonstrating how to create and save a new subscription for a Confluence space. ```APIDOC ## Create Space Subscription ### Description Example demonstrating how to create and save a new subscription for a Confluence space. ### Example ```go spaceSub := serializer.SpaceSubscription{ Alias: "Documentation Space", BaseURL: "https://confluence.example.com", SpaceKey: "DOCS", Events: []string{ serializer.PageCreatedEvent, serializer.PageUpdatedEvent, serializer.CommentCreatedEvent, }, ChannelID: "channel_abc123", Type: serializer.SubscriptionTypeSpace, } statusCode, err := service.SaveSubscription(spaceSub) if err != nil { log.Printf("Save failed: %v", err) } ``` ``` -------------------------------- ### Example Command Usage for Deleting Subscription Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/command-handler.md Illustrates how to use the delete subscription command with a subscription name argument. ```bash /confluence unsubscribe "Subscription Name" ``` -------------------------------- ### Command Handler Routing Logic Example Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/command-handler.md Illustrates how the Handle method routes different command inputs to specific handlers or the default handler. ```go // "/confluence install cloud" routes to "install/cloud" handler // "/confluence list" routes to "list" handler // "/confluence unknown" routes to default handler ``` -------------------------------- ### Space Subscription JSON Example Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/subscriptions.md An example JSON payload for creating or representing a space subscription. It specifies the alias, Confluence base URL, space key, desired events, Mattermost channel ID, and subscription type. ```json { "alias": "Platform Project", "baseURL": "https://confluence.example.com", "spaceKey": "PROJ", "events": ["page_created", "page_updated", "comment_created"], "channelID": "abc123", "subscriptionType": "space_subscription" } ``` -------------------------------- ### Handle Successful Save Operation Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/controller.md Example of how to call ReturnStatusOK after processing a request to save subscription data. ```go func handleSaveSubscription(w http.ResponseWriter, r *http.Request, p *Plugin) { // ... process request ... ReturnStatusOK(w) } ``` -------------------------------- ### Create Space Subscription Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/subscriptions.md Example of creating a new space subscription. This involves defining the subscription details like alias, base URL, space key, events, channel ID, and type, then saving it. ```go spaceSub := serializer.SpaceSubscription{ Alias: "Documentation Space", BaseURL: "https://confluence.example.com", SpaceKey: "DOCS", Events: []string{ serializer.PageCreatedEvent, serializer.PageUpdatedEvent, serializer.CommentCreatedEvent, }, ChannelID: "channel_abc123", Type: serializer.SubscriptionTypeSpace, } statusCode, err := service.SaveSubscription(spaceSub) if err != nil { log.Printf("Save failed: %v", err) } ``` -------------------------------- ### Page Subscription JSON Example Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/subscriptions.md An example JSON payload for creating or representing a page subscription. It includes the alias, Confluence base URL, specific page ID, events to monitor, Mattermost channel ID, and subscription type. ```json { "alias": "Release Planning Page", "baseURL": "https://confluence.example.com", "pageID": "123456", "events": ["page_updated", "comment_created"], "channelID": "abc123", "subscriptionType": "page_subscription" } ``` -------------------------------- ### Gorilla Mux Route Path Patterns Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/controller.md Illustrates common patterns used with Gorilla Mux for defining routes, including variable capture, pattern matching, and literal paths. Examples show how to match channel IDs, subscription types, event types, and aliases. ```go {channelID:[A-Za-z0-9]+} - Channel ID (alphanumeric) {type:[A-Za-z_]+} - Subscription type (letters and underscores) {event:[A-Za-z0-9_]+} - Event type (alphanumeric and underscores) {alias} - Subscription alias (any characters) ``` -------------------------------- ### Example of HTTP Secret Verification Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/controller.md Demonstrates how to use verifyHTTPSecret to check the 'secret' form value against the configured secret. If verification fails, it sends an HTTP error response. ```go if status, err := verifyHTTPSecret(config.GetConfig().Secret, r.FormValue("secret")); err != nil { http.Error(w, "Failed to verify the secret", status) return } // Secret verified, proceed with processing ``` -------------------------------- ### Get Current Plugin Configuration Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/configuration.md Retrieves the currently active configuration settings for the Confluence plugin. ```go config.GetConfig() *Configuration ``` -------------------------------- ### System Administrator Slash Command Help Text Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/command-handler.md Defines the help text for system administrator-specific slash commands, including setup instructions for connecting Mattermost to Confluence instances. This text is typically shown to administrators. ```go const sysAdminHelpText = "\n###### For System Administrators:\n" + "Setup Instructions:\n" + "* /confluence install cloud - Connect Mattermost to a Confluence Cloud instance.\n" + "* /confluence install server - Connect Mattermost to a Confluence Server or Data Center instance.\n" ``` -------------------------------- ### HTTP Error Response Example Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/errors.md Standard way to return HTTP errors from an endpoint. Use appropriate HTTP status codes. ```go http.Error(w, "error message", http.StatusBadRequest) ``` -------------------------------- ### Command Response Error Example Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/errors.md Handles errors for slash commands by returning an ephemeral post to the user. Ensure a CommandResponse is returned. ```go postCommandResponse(context, "Error message") return &model.CommandResponse{} ``` -------------------------------- ### Get Plugin Configuration Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/endpoints.md Retrieves the plugin configuration visible to the current user. Requires system admin authentication. ```APIDOC ## GET /api/v1/config ### Description Retrieves the plugin configuration visible to the current user. ### Method GET ### Endpoint /api/v1/config ### Parameters #### Request Headers - **Mattermost-User-Id** (string) - Required - ID of the authenticated user ### Response #### Success Response (200 OK) - Returns the plugin configuration JSON. #### Response Body ```json { "events": { "space_subscription": [ "page_created", "page_updated", "page_trashed", "page_restored", "page_removed", "comment_created", "comment_updated", "comment_removed" ], "page_subscription": [ "page_created", "page_updated", "page_trashed", "page_restored", "page_removed", "comment_created", "comment_updated" ] } } ``` #### Error Response - Status: 403 Forbidden if user is not a system admin - Status: 500 Internal Server Error on failure ``` -------------------------------- ### Edit Subscription Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/subscriptions.md Provides an example of how to load an existing subscription, modify its properties (like alias or events), and then save the changes. ```APIDOC ## Edit Subscription ### Description Provides an example of how to load an existing subscription, modify its properties (like alias or events), and then save the changes. ### Example ```go // Load existing subscription sub, statusCode, err := service.GetChannelSubscription("channel_abc123", "Documentation Space") if err != nil { log.Printf("Not found") return } // Cast to SpaceSubscription to modify spaceSub := sub.(serializer.SpaceSubscription) spaceSub.OldAlias = spaceSub.Alias spaceSub.Alias = "Docs Space" // New alias spaceSub.Events = []string{serializer.PageUpdatedEvent} // New events err = service.EditSubscription(spaceSub) ``` ``` -------------------------------- ### Get Confluence Base URL Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/configuration.md Retrieves the configured base URL for the Confluence instance. ```go (c *Configuration) GetConfluenceBaseURL() string ``` -------------------------------- ### Asynchronous Webhook Processing Example Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/webhooks.md This Go code snippet demonstrates how webhook handlers process requests synchronously by immediately returning a 200 OK response and then sending notifications asynchronously using a goroutine. This prevents timeouts and keeps Confluence unblocked. ```go // Returns 200 OK immediately go service.SendConfluenceNotifications(event, eventType) w.Header().Set("Content-Type", "application/json") ReturnStatusOK(w) ``` -------------------------------- ### Get Subscription Alias Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/subscriptions.md Retrieves the user-friendly alias assigned to the subscription. This is used for display and identification purposes. ```go func (s SpaceSubscription) GetAlias() string func (p PageSubscription) GetAlias() string ``` -------------------------------- ### Delete Subscription Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/subscriptions.md Example of deleting a subscription using its channel ID and alias. This operation removes the subscription from the system. ```go err := service.DeleteSubscription("channel_abc123", "Documentation Space") if err != nil { log.Printf("Delete failed: %v", err) } ``` -------------------------------- ### Get All Subscriptions Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/service.md Retrieves all subscriptions stored within the system. It returns a structured object containing subscriptions organized by channel ID, page ID, and space key, or an error if the retrieval fails. ```go func GetSubscriptions() (serializer.Subscriptions, error) ``` ```go Subscriptions{ ByChannelID: map[string]StringSubscription, ByURLPageID: map[string]StringArrayMap, ByURLSpaceKey: map[string]StringArrayMap, } ``` -------------------------------- ### Get Supported Events Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/subscriptions.md Retrieves a list of events supported by the Confluence server version. Use this to determine which events can be subscribed to. ```go func GetSupportedEvents(isV9OrAbove bool) []string ``` ```go events := serializer.GetSupportedEvents(true) // Returns: [comment_created, comment_updated, page_created, page_updated, page_trashed, page_restored, page_removed] ``` -------------------------------- ### Confluence Cloud Webhook cURL Example Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/webhooks.md Demonstrates how to send a POST request to the Confluence Cloud webhook handler using cURL, including event type, secret, and a sample JSON payload. ```bash curl -X POST "http://mattermost.local/plugins/confluence/api/v1/cloud/page.created?secret=YOUR_SECRET" \ -H "Content-Type: application/json" \ -d '{ "type": "page.created", "page": { "id": "123456", "title": "New Page", "space": {"key": "PROJ"} }, "createdBy": { "account_id": "user123", "display_name": "John Doe" } }' ``` -------------------------------- ### Get Plugin Configuration Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/endpoints.md Retrieves the plugin configuration visible to the current user. This endpoint is restricted to system administrators and requires Mattermost User ID in headers. ```json { "events": { "space_subscription": [ "page_created", "page_updated", "page_trashed", "page_restored", "page_removed", "comment_created", "comment_updated", "comment_removed" ], "page_subscription": [ "page_created", "page_updated", "page_trashed", "page_restored", "page_removed", "comment_created", "comment_updated" ] } } ``` -------------------------------- ### ExecuteCommand Handler Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/plugin.md Processes slash commands starting with '/confluence'. It parses command arguments and routes them to the appropriate handler for execution, returning a response or an error. ```go // User types: /confluence list // commandArgs.Command = "/confluence list" // Returns list of subscriptions in the channel // User types: /confluence connect // commandArgs.Command = "/confluence connect" // Returns OAuth connection link ``` -------------------------------- ### Define FlowManager Struct Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/types.md Represents a manager for handling interactive OAuth flows and setup wizards. It contains unexported fields for internal management. ```go type FlowManager struct { // contains unexported fields } ``` -------------------------------- ### Get All Subscriptions in a Channel Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/service.md Retrieves all subscriptions associated with a given Mattermost channel ID. Returns a map of subscription aliases to subscription details, or an error if the retrieval fails. ```go func GetSubscriptionsByChannelID(channelID string) (serializer.StringSubscription, error) ``` ```go subs, err := service.GetSubscriptionsByChannelID("channel_id") if err != nil { log.Printf("Error: %v", err) return } for alias, sub := range subs { log.Printf("Subscription: %s (type: %s)", alias, sub.Name()) } ``` -------------------------------- ### Get Subscriptions by Confluence Space Key Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/service.md Retrieves all Mattermost channels that are subscribed to a specific Confluence space. Returns a map where keys are channel IDs and values are arrays of event types, or an error. ```go func GetSubscriptionsByURLSpaceKey(url, spaceKey string) (serializer.StringArrayMap, error) ``` -------------------------------- ### Get Subscription Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/INDEX.md Retrieves details of a specific subscription by its alias. ```APIDOC ## GET /api/v1/{channelID}/subscription/{alias} ### Description Retrieves the details of a specific subscription identified by its alias within a given channel. ### Method GET ### Endpoint /api/v1/{channelID}/subscription/{alias} ### Parameters #### Path Parameters - **channelID** (string) - Required - The ID of the channel. - **alias** (string) - Required - The alias of the subscription to retrieve. ### Response #### Success Response (200) - **id** (string) - The unique identifier of the subscription. - **alias** (string) - The alias of the subscription. - **type** (string) - The type of the subscription. - **url** (string) - The URL for the subscription. - **spaceKey** (string) - The space key, if applicable. - **pageId** (string) - The page ID, if applicable. ``` -------------------------------- ### Get Subscription Alias Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/subscriptions.md Retrieves the user-friendly alias assigned to the subscription. ```APIDOC ## Get Subscription Alias ### Description Returns the user-friendly name (alias) of the subscription. ### Method Not applicable (SDK method) ### Parameters None ### Request Example ```go // Example for SpaceSubscription spaceSub := SpaceSubscription{Alias: "My Space Sub", ...} alias := spaceSub.GetAlias() // alias will be "My Space Sub" // Example for PageSubscription pageSub := PageSubscription{Alias: "My Page Sub", ...} alias := pageSub.GetAlias() // alias will be "My Page Sub" ``` ### Response #### Success Response * **string** - The user-friendly alias of the subscription #### Response Example ``` "My Space Sub" ``` ``` -------------------------------- ### Help Command Handler Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/command-handler.md Displays available commands and their usage. Permissions vary based on Confluence Server version. ```go func confluenceHelpCommand(_ *Plugin, context *model.CommandArgs, args ...string) *model.CommandResponse ``` -------------------------------- ### Get Subscription Name Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/subscriptions.md Retrieves the type name of the subscription (e.g., 'space_subscription' or 'page_subscription'). ```APIDOC ## Get Subscription Name ### Description Returns the type name of the subscription. ### Method Not applicable (SDK method) ### Parameters None ### Request Example ```go // Example for SpaceSubscription spaceSub := SpaceSubscription{...} name := spaceSub.Name() // name will be "space_subscription" // Example for PageSubscription pageSub := PageSubscription{...} name := pageSub.Name() // name will be "page_subscription" ``` ### Response #### Success Response * **string** - The subscription type name ('space_subscription' or 'page_subscription') #### Response Example ``` "space_subscription" ``` ``` -------------------------------- ### Save Subscription with Injected Dependencies Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/service.md Creates a subscription using provided repository and store dependencies, primarily for testing purposes. This allows for mocking external services during unit tests. ```go func SaveSubscriptionWithDeps(subscription serializer.Subscription, repo SubscriptionRepository, storeService Store) (int, error) ``` -------------------------------- ### Initialize HTTP Router and Register Endpoints Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/controller.md Initializes the Gorilla mux router and registers all plugin endpoints, including static file handlers and API routes. This function is called during plugin activation. ```go func (p *Plugin) InitAPI() *mux.Router ``` ```go // Called during plugin activation router := p.InitAPI() // Now ready to handle requests ``` -------------------------------- ### Get Channel Subscription Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/endpoints.md Retrieves a specific subscription by channel and alias name. Requires user authentication. ```APIDOC ## GET /api/v1/{channelID}/subscription/{alias} ### Description Retrieves a specific subscription by channel and alias name. ### Method GET ### Endpoint /api/v1/{channelID}/subscription/{alias} ### Parameters #### Path Parameters - **channelID** (string) - Required - Mattermost channel ID - **alias** (string) - Required - Subscription name #### Request Headers - **Mattermost-User-Id** (string) - Required - ID of the authenticated user ### Response #### Success Response (200 OK) - Returns the matching subscription object (SpaceSubscription or PageSubscription) #### Error Response - Status: 400 Bad Request if subscription not found - Status: 403 Forbidden if user lacks access - Status: 500 Internal Server Error on failure ### Request Example ```bash curl -X GET "http://mattermost.local/plugins/confluence/api/v1/abc123/subscription/Platform%20Project" \ -H "Mattermost-User-Id: user_id_here" ``` ``` -------------------------------- ### Convert Configuration to Map Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/configuration.md Serializes the plugin configuration struct into a map, which can be useful for storage or transmission. ```go (c *Configuration) ToMap() (map[string]interface{}, error) ``` -------------------------------- ### Plugin.responsef for Formatted Responses Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/command-handler.md Sends a formatted response to a command using printf-style formatting. It internally calls postCommandResponse and returns an empty CommandResponse. ```go func (p *Plugin) responsef(commandArgs *model.CommandArgs, format string, args ...interface{}) *model.CommandResponse ``` -------------------------------- ### ServeHTTP Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/plugin.md Handles all HTTP requests to plugin endpoints at `/plugins/confluence/`. It checks if the plugin is configured and routes requests through the mux Router. Returns 501 Not Implemented if the plugin is not configured. ```APIDOC ## ServeHTTP ### Description Handles all HTTP requests to plugin endpoints at `/plugins/confluence/`. ### Method POST, GET, PUT, DELETE, etc. (handled by mux Router) ### Endpoint `/plugins/confluence/*` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (handled by mux Router) ### Request Example ``` // GET /plugins/confluence/api/v1/abc123/subscription/Sub%20Name // Handled by subscriptions route // POST /plugins/confluence/api/v1/cloud/page_created?secret=XXXX // Handled by cloud webhook route ``` ### Response #### Success Response (200) Depends on the specific route handled by the mux Router. #### Response Example None provided. ``` -------------------------------- ### Subscription Management Interface Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/types.md Interface for managing space and page subscriptions, defining operations for adding, removing, editing, and validating subscriptions. ```go type Subscription interface { Add(*Subscriptions) error Remove(*Subscriptions) error Edit(*Subscriptions) error Name() string GetAlias() string GetFormattedSubscription() string IsValid() error ValidateSubscription(*Subscriptions) error } ``` -------------------------------- ### Get Subscription Type Name Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/subscriptions.md Returns the string identifier for the subscription type. This method differentiates between 'space_subscription' and 'page_subscription'. ```go func (s SpaceSubscription) Name() string func (p PageSubscription) Name() string ``` -------------------------------- ### Add Subscription Method Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/subscriptions.md Implements the addition of a subscription to all relevant indices within the subscriptions container. It handles indexing by channel ID and by space/page identifier. ```go func (s SpaceSubscription) Add(subscriptions *Subscriptions) error func (p PageSubscription) Add(subscriptions *Subscriptions) error ``` -------------------------------- ### Get User Connection Info Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/endpoints.md Retrieves information about the current user's Confluence connection. Requires user authentication. ```APIDOC ## GET /api/v1/user-connection-info ### Description Retrieves information about the current user's Confluence connection. ### Method GET ### Endpoint /api/v1/user-connection-info ### Parameters #### Request Headers - **Mattermost-User-Id** (string) - Required - ID of the authenticated user ### Response #### Success Response (200 OK) - Returns user connection information including Confluence account details. #### Error Response - Status: 404 Not Found if user not connected - Status: 500 Internal Server Error on failure ``` -------------------------------- ### Format Subscription for Display Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/subscriptions.md Returns a formatted markdown row for displaying subscription details in tables. Use this to present subscription information clearly. ```go func (s SpaceSubscription) GetFormattedSubscription() string func (p PageSubscription) GetFormattedSubscription() string ``` ```text |[Alias]|[BaseURL]|[SpaceKey/PageID]|[Events]| |Platform Project|https://confluence.example.com|PROJ|Page Create, Comment Update| ``` -------------------------------- ### Plugin Configuration Structure Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/types.md Stores all plugin configuration settings, including secrets, API tokens, and OAuth credentials for Confluence integration. ```go type Configuration struct { Secret string `json:"secret"` EncryptionKey string `json:"encryptionkey"` AdminAPIToken string `json:"adminapitoken"` ConfluenceOAuthClientID string `json:"confluenceoauthclientid"` ConfluenceOAuthClientSecret string `json:"confluenceoauthclientsecret"` ConfluenceURL string `json:"confluenceurl"` ServerVersionGreaterthan9 bool `json:"serverversiongreaterthan9"` } ``` -------------------------------- ### Get Event Display Name Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/subscriptions.md Converts an event constant string into a human-readable display name. Useful for presenting events to users. ```go func EventDisplayName(event string) string ``` ```text comment_created → "Comment Create" comment_updated → "Comment Update" comment_removed → "Comment Remove" page_created → "Page Create" page_updated → "Page Update" page_trashed → "Page Trash" page_restored → "Page Restore" page_removed → "Page Remove" ``` -------------------------------- ### ServeHTTP Handler Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/plugin.md Handles all incoming HTTP requests to the plugin's endpoints. It checks configuration and routes requests via the mux Router. ```go func (p *Plugin) ServeHTTP(_ *plugin.Context, w http.ResponseWriter, r *http.Request) *model.AppError ``` ```go // GET /plugins/confluence/api/v1/abc123/subscription/Sub%20Name // Handled by subscriptions route ``` ```go // POST /plugins/confluence/api/v1/cloud/page_created?secret=XXXX // Handled by cloud webhook route ``` -------------------------------- ### Example Error Response Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/endpoints.md Error responses from the Confluence plugin follow standard HTTP status codes and include a descriptive message in the body. ```http HTTP/1.1 400 Bad Request Content-Type: text/plain error message describing what went wrong ``` -------------------------------- ### Set Plugin Configuration Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/configuration.md Updates the global plugin configuration with new settings. Use this to persist changes to the plugin's configuration. ```go config.SetConfig(c *Configuration) ``` -------------------------------- ### Get Specific Channel Subscription Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/endpoints.md Retrieves a specific subscription by its channel ID and alias name. Requires Mattermost User ID in headers. ```bash curl -X GET "http://mattermost.local/plugins/confluence/api/v1/abc123/subscription/Platform%20Project" \ -H "Mattermost-User-Id: user_id_here" ``` -------------------------------- ### Edit Subscription Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/subscriptions.md Demonstrates how to edit an existing subscription. It involves loading the subscription, casting it to the correct type, modifying its properties (like alias or events), and then saving the changes. ```go // Load existing subscription sub, statusCode, err := service.GetChannelSubscription("channel_abc123", "Documentation Space") if err != nil { log.Printf("Not found") return } // Cast to SpaceSubscription to modify spaceSub := sub.(serializer.SpaceSubscription) spaceSub.OldAlias = spaceSub.Alias spaceSub.Alias = "Docs Space" // New alias spaceSub.Events = []string{serializer.PageUpdatedEvent} // New events err = service.EditSubscription(spaceSub) ``` -------------------------------- ### Process Plugin Configuration Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/configuration.md Performs necessary processing on the configuration, such as trimming whitespace from sensitive fields like the Secret. ```go (c *Configuration) ProcessConfiguration() error ``` -------------------------------- ### setUpBotUser Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/plugin.md Creates or ensures the Confluence bot user exists and sets its profile picture. This function is used internally to manage the bot user for the plugin. ```APIDOC ## setUpBotUser ### Description Creates or ensures the Confluence bot user exists and sets its profile picture. ### Method Internal ### Endpoint None ### Parameters None ### Request Example ``` // Creates bot if doesn't exist, does nothing if already exists // Profile image set from bundled assets/icon.png ``` ### Response #### Success Response (nil) Returns nil on success. #### Response Example None provided. ``` -------------------------------- ### Plugin Activation Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/plugin.md The OnActivate method is called by the Mattermost plugin framework to initialize the plugin, set up components like the API client, bot user, router, and load templates. ```go // Plugin activation is automatic when Mattermost loads the plugin // Called internally by Mattermost plugin framework ``` -------------------------------- ### List Channel Subscriptions Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/subscriptions.md Shows how to retrieve all subscriptions configured for a given channel ID, listing their aliases and names. ```APIDOC ## List Channel Subscriptions ### Description Shows how to retrieve all subscriptions configured for a given channel ID, listing their aliases and names. ### Example ```go subs, err := service.GetSubscriptionsByChannelID("channel_abc123") if err != nil { log.Printf("Error: %v", err) return } for alias, sub := range subs { fmt.Printf("- %s (%s)\n", alias, sub.Name()) } ``` ``` -------------------------------- ### Default Handler for Unknown Commands Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/command-handler.md Handles commands that are not recognized or are malformed. It returns an error message along with help text. ```go func executeConfluenceDefault(_ *Plugin, context *model.CommandArgs, args ...string) *model.CommandResponse ``` -------------------------------- ### Define HandlerFunc for Slash Commands Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/types.md Defines the function signature for handling slash commands. It takes plugin context, command arguments, and optional string arguments, returning a command response. ```go type HandlerFunc func(p *Plugin, context *model.CommandArgs, args ...string) *model.CommandResponse ``` -------------------------------- ### Get Subscriptions by Confluence Page ID Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/service.md Retrieves all Mattermost channels that are subscribed to a specific Confluence page. Returns a map where keys are channel IDs and values are arrays of event types, or an error. ```go func GetSubscriptionsByURLPageID(url, pageID string) (serializer.StringArrayMap, error) ``` -------------------------------- ### SubscriptionRepository Interface Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/service.md Defines methods for retrieving subscription data based on various criteria. The default implementation uses the Mattermost plugin API KV store. ```go type SubscriptionRepository interface { GetSubscriptions() (serializer.Subscriptions, error) GetSubscriptionsByURLSpaceKey(url, spaceKey string) (serializer.StringArrayMap, error) GetSubscriptionsByURLPageID(url, pageID string) (serializer.StringArrayMap, error) } ``` -------------------------------- ### Get Single Channel Subscription Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/service.md Retrieves a specific subscription within a Mattermost channel using its channel ID and alias. Returns the subscription details, an HTTP status code, and an error if not found or if a server error occurs. ```go func GetChannelSubscription(channelID, alias string) (serializer.Subscription, int, error) ``` ```go sub, statusCode, err := service.GetChannelSubscription("channel_id", "Sub Name") if err != nil { switch statusCode { case 400: log.Println("Subscription not found") case 500: log.Println("Server error:", err) } } ``` -------------------------------- ### Initiate Confluence OAuth Connection Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/endpoints.md Redirects the user to the Confluence OAuth authorization page to connect their Confluence account. Requires Mattermost User ID in headers. ```bash curl -X GET "http://mattermost.local/plugins/confluence/api/v1/oauth2/connect" \ -H "Mattermost-User-Id: user_id_here" \ -L ``` -------------------------------- ### Subscription Container Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/types.md Holds all subscriptions, organized by channel ID and URL-based identifiers for efficient lookup. ```go type Subscriptions struct { ByChannelID map[string]StringSubscription ByURLPageID map[string]StringArrayMap ByURLSpaceKey map[string]StringArrayMap } ``` -------------------------------- ### handleStaticFiles Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/controller.md Registers a handler for serving static files from the `/static/` path. It maps requests to files within the `assets` directory. ```APIDOC ## handleStaticFiles ### Description Registers a handler for static files in the `/static/` path. ### Method Not applicable (function signature provided) ### Endpoint `/static/*` ### Parameters #### Path Parameters - None explicitly defined in the function signature, but the router handles path registration. #### Query Parameters - None #### Request Body - None ### Response - None (registers a handler) ### Files Served: - `/static/icon.svg` → `assets/icon.svg` - `/static/icon.png` → `assets/icon.png` - Other assets in the bundle ``` -------------------------------- ### User and Configuration Endpoints Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/README.md Endpoints for retrieving user connection status and plugin configuration. ```APIDOC ## GET /user-connection-info ### Description Retrieves the connection status of the current user with Confluence. ### Method GET ### Endpoint `/user-connection-info` ### Response #### Success Response (200) - **connectionStatus** (object) - Information about the user's connection to Confluence. ## GET /config ### Description Retrieves the current configuration of the Confluence plugin. ### Method GET ### Endpoint `/config` ### Response #### Success Response (200) - **configuration** (object) - The plugin's configuration settings. ``` -------------------------------- ### Global Registry of Plugin Endpoints Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/controller.md A map that serves as the global registry for all available plugin endpoints. Each endpoint is uniquely identified by a hash of its path and method. ```go var Endpoints = map[string]*Endpoint{ getEndpointKey(atlassianConnectJSON): atlassianConnectJSON, getEndpointKey(confluenceCloudWebhook): confluenceCloudWebhook, getEndpointKey(saveChannelSubscription): saveChannelSubscription, getEndpointKey(editChannelSubscription): editChannelSubscription, getEndpointKey(confluenceServerWebhook): confluenceServerWebhook, getEndpointKey(getChannelSubscription): getChannelSubscription, getEndpointKey(autocompleteGetChannelSubscriptions): autocompleteGetChannelSubscriptions, getEndpointKey(userConnect): userConnect, getEndpointKey(userConnectComplete): userConnectComplete, getEndpointKey(userConnectionInfo): userConnectionInfo, getEndpointKey(getPluginConfig): getPluginConfig, } ``` -------------------------------- ### Post Command Response Utility Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/command-handler.md Sends an ephemeral post to the user with the provided response message. This is used to display messages only to the command user. ```go func postCommandResponse(context *model.CommandArgs, text string) ``` -------------------------------- ### Creating a Subscription Request Flow Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/README.md Details the sequence of events and function calls involved when a user creates a new Confluence subscription via a slash command. ```text User Command: /confluence subscribe ↓ ExecuteCommand (plugin.md) ↓ ConfluenceCommandHandler routes to handler ↓ POST /api/v1/{channelID}/subscription/{type} (endpoints.md) ↓ handleSaveSubscription (controller.md) ↓ SaveSubscription service (service.md) ↓ Validate and store subscription (subscriptions.md) ``` -------------------------------- ### List Channel Subscriptions (Autocomplete) Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/endpoints.md Returns a list of all subscription names in a channel for autocomplete functionality. Requires user authentication. ```APIDOC ## GET /api/v1/autocomplete/GetChannelSubscriptions ### Description Returns a list of all subscription names in a channel for autocomplete functionality. ### Method GET ### Endpoint /api/v1/autocomplete/GetChannelSubscriptions ### Parameters #### Query Parameters - **channel_id** (string) - Required - Mattermost channel ID #### Request Headers - **Mattermost-User-Id** (string) - Required - ID of the authenticated user ### Response #### Success Response (200 OK) - Returns a JSON array of suggestion objects. #### Response Body ```json [ { "item": "Platform Project", "display_name": "Platform Project" }, { "item": "Docs Space", "display_name": "Docs Space" } ] ``` #### Error Response - Status: 403 Forbidden if user lacks access - Status: 500 Internal Server Error on failure ``` -------------------------------- ### List Channel Subscriptions Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/subscriptions.md Retrieves all subscriptions associated with a specific channel ID. The output lists the alias and name of each subscription. ```go subs, err := service.GetSubscriptionsByChannelID("channel_abc123") if err != nil { log.Printf("Error: %v", err) return } for alias, sub := range subs { fmt.Printf("- %s (%s)\n", alias, sub.Name()) } ``` -------------------------------- ### Create Subscription Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/INDEX.md Creates a new subscription for a channel to receive Confluence events. ```APIDOC ## POST /api/v1/{channelID}/subscription/{type} ### Description Creates a new subscription for a channel to receive specific types of Confluence events. ### Method POST ### Endpoint /api/v1/{channelID}/subscription/{type} ### Parameters #### Path Parameters - **channelID** (string) - Required - The ID of the channel to associate the subscription with. - **type** (string) - Required - The type of subscription (e.g., space, page). #### Request Body - **alias** (string) - Required - A unique alias for the subscription. - **url** (string) - Required - The URL to send notifications to. - **spaceKey** (string) - Optional - The Confluence space key for space-level subscriptions. - **pageId** (string) - Optional - The Confluence page ID for page-level subscriptions. ### Request Example ```json { "alias": "my-space-updates", "url": "http://example.com/webhook", "spaceKey": "MYSPACE" } ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier of the created subscription. - **alias** (string) - The alias of the subscription. - **type** (string) - The type of the subscription. - **url** (string) - The URL for the subscription. - **spaceKey** (string) - The space key, if applicable. - **pageId** (string) - The page ID, if applicable. ``` -------------------------------- ### Wrap Handler with Plugin Instance Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/controller.md Middleware that injects the Plugin instance into handler functions. It converts a handler function requiring the plugin into a standard http.HandlerFunc by capturing the plugin instance. ```go func (p *Plugin) wrapHandler(handler func(http.ResponseWriter, *http.Request, *Plugin)) http.HandlerFunc ``` ```go // Before wrapping: func(w, r, p *Plugin) // After wrapping: func(w, r) (p is captured) wrapped := p.wrapHandler(handler) ``` -------------------------------- ### Sanitize Plugin Configuration Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/configuration.md Cleans up configuration values, including removing trailing slashes from URLs and trimming whitespace from credentials. ```go (c *Configuration) Sanitize() ``` -------------------------------- ### Save Plugin Configuration Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/plugin.md Saves the provided plugin configuration to Mattermost. Converts the configuration struct to a map before saving. ```go func (p *Plugin) savePluginConfig(configuration *config.Configuration) error ``` ```go config := &config.Configuration{ Secret: "...", EncryptionKey: "...", } err := p.savePluginConfig(config) ``` -------------------------------- ### Plugin Lifecycle Methods Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/plugin.md Documentation for the core lifecycle methods of the Confluence plugin, including activation and configuration changes. ```APIDOC ## OnActivate ### Description Called when the plugin is activated. Initializes the plugin and sets up all required components. ### Signature ```go func (p *Plugin) OnActivate() error ``` ### Returns - `error` - nil on success, error if any initialization step fails ### Implementation Details 1. Initializes the pluginapi client 2. Creates the Confluence bot user via `setUpBotUser()` 3. Initializes the HTTP router via `InitAPI()` 4. Processes configuration via `OnConfigurationChange()` 5. Loads HTML templates from the bundle 6. Creates the FlowManager for OAuth flows 7. Registers the `/confluence` slash command ### Source `server/plugin.go:45-87` ## OnConfigurationChange ### Description Called when plugin configuration is updated. Reloads and validates the configuration. ### Signature ```go func (p *Plugin) OnConfigurationChange() error ``` ### Returns - `error` - nil on success, error if validation fails ### Configuration Validation - Secret must be exactly 32 characters - EncryptionKey must be exactly 32 characters - AdminAPIToken (if provided) must be at least 32 characters ### Auto-generation - Encryption key is automatically generated if missing or invalid - The generated key is saved back to plugin configuration ### Source `server/plugin.go:89-128` ``` -------------------------------- ### Implement Authentication Middleware Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/controller.md A middleware function that verifies user authentication using the Mattermost-User-Id header. It protects handlers by returning a 401 Unauthorized error if the header is missing. ```go func (p *Plugin) checkAuth(handler http.HandlerFunc) http.HandlerFunc ``` ```go // Handler with authentication required s.HandleFunc(endpoint.Path, p.checkAuth(p.wrapHandler(handler))).Methods(endpoint.Method) ``` -------------------------------- ### Validate Plugin Configuration Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/configuration.md Checks if the current configuration meets the required criteria, such as specific field lengths. Returns an error if validation fails. ```go (c *Configuration) IsValid() error ``` -------------------------------- ### Confluence Server Webhook Configuration Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/webhooks.md Provides the URL and event selection details for configuring a webhook in Confluence Server or Data Center instances. ```text URL: https://your-mattermost.com/plugins/confluence/api/v1/server/webhook?secret=YOUR_SECRET Events: Select desired events (page_created, comment_created, etc.) ``` -------------------------------- ### Validate Plugin Configuration Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/README.md Checks if the current plugin configuration is valid. Logs an error message if the configuration is invalid. ```go if err := config.IsValid(); err != nil { log.Printf("Invalid config: %v", err) } ``` -------------------------------- ### Construct Confluence API Endpoint URL Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/service.md Constructs a full Confluence API endpoint URL by combining the instance URL and the API path. Handles potential URL construction errors. ```go func GetEndpointURL(instanceURL, path string) (string, error) ``` ```go url, err := service.GetEndpointURL("https://confluence.example.com", "/rest/api/content/123") // Returns: "https://confluence.example.com/rest/api/content/123" ``` -------------------------------- ### Confluence Server/Data Center Webhook Configuration Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/webhooks.md Steps to configure a webhook in Confluence Administration for Server or Data Center instances. This includes setting the webhook name, URL, and selecting the desired events. ```text 1. Go to Confluence Administration > Webhooks 2. Click Create a Webhook 3. Configure: - **Name:** Mattermost - **URL:** `https://your-mattermost.com/plugins/confluence/api/v1/server/webhook?secret=YOUR_SECRET` - **Events:** Select desired events - **Exclude:** Leave unchecked ``` -------------------------------- ### List Channel Subscriptions for Autocomplete Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/endpoints.md Returns a list of all subscription names within a specified Mattermost channel, intended for autocomplete functionality. Requires Mattermost User ID in headers. ```json [ { "item": "Platform Project", "display_name": "Platform Project" }, { "item": "Docs Space", "display_name": "Docs Space" } ] ``` -------------------------------- ### Atlassian Connect Descriptor Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/INDEX.md Provides the Atlassian Connect descriptor for the plugin. ```APIDOC ## GET /api/v1/atlassian-connect.json ### Description Provides the Atlassian Connect descriptor file (atlassian-connect.json) for the plugin, which is required for app installation in Confluence. ### Method GET ### Endpoint /api/v1/atlassian-connect.json ### Response #### Success Response (200) - **descriptor** (object) - The JSON content of the Atlassian Connect descriptor. ``` -------------------------------- ### Plugin Configuration Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/INDEX.md Retrieves the current configuration of the Confluence plugin. ```APIDOC ## GET /api/v1/config ### Description Retrieves the current configuration settings for the Confluence plugin. ### Method GET ### Endpoint /api/v1/config ### Response #### Success Response (200) - **Secret** (string) - The webhook secret. - **EncryptionKey** (string) - The at-rest encryption key. - **AdminAPIToken** (string) - The Confluence admin API token. - **ConfluenceOAuthClientID** (string) - The OAuth client ID. - **ConfluenceOAuthClientSecret** (string) - The OAuth client secret. - **ConfluenceURL** (string) - The Confluence instance URL. - **ServerVersionGreaterthan9** (boolean) - Flag indicating if the Confluence server version is greater than 9. ``` -------------------------------- ### Delete Subscription with Dependencies Source: https://github.com/mattermost/mattermost-plugin-confluence/blob/master/_autodocs/api-reference/service.md Deletes a subscription using injected dependencies, primarily for testing purposes. It requires the channel ID, alias, a subscription repository, and a store service. ```go func DeleteSubscriptionWithDeps(channelID, alias string, repo SubscriptionRepository, storeService Store) error ```