How mattermost-community/mattermost-plugin-welcomebot works
Main components
• Mattermost Server: This is the platform where the plugin is deployed and executes as an integration. Include it as the external system that triggers events (like a new user joining a team) and consumes plugin functionality.
• Plugin Manifest/Configuration: The plugin.json manifest and the configuration in the Mattermost system (via config.json) define versioning, enabled states, and how the plugin integrates with Mattermost.
• Server (Plugin) Component: All the core logic is in the “server” directory. Here, files like main.go, hooks (http_hooks.go, hooks.go), and additional helper files (action_context.go, command.go, configuration.go, message_template.go, welcomebot.go) process events, generate welcome messages from templates, and handle user interactions/commands (e.g. /welcomebot help, preview, etc.).
• Build and Deployment Tools: The “build” directory houses scripts and tools (including a CLI tool “pluginctl”, logs handling, and manifest compilation with build/manifest) that are used in the building, versioning, and deployment of the plugin. This separation indicates an architectural decision to segment CI/CD and build management from the runtime plugin logic.
• External CI/CD and Code Analysis: The presence of directories like .github/workflows and configuration files like .golangci.yml, .nvmrc, and Makefile suggest integration with continuous integration pipelines, code linting, and deployment automation.
Relationships and interactions
• When a new user joins a team on Mattermost, the Mattermost Server sends an event to the plugin.
• The Plugin (server component) intercepts this event via hooks, processes the message template (using the provided MessageTemplate structure), and, depending on configuration, either displays a welcome message automatically or triggers an interactive flow for the user to choose actions (like joining channels).
• The server component may call internal functions (e.g. command.go, welcomebot.go) to decide which actions or messages to send.
• Build tools and manifest management are run during the build/deployment cycle. They don’t interact at runtime with the server logic but are critical in packaging the plugin.
Architectural patterns and design principles
• Separation of Concerns: The plugin is clearly divided into a build process (packaging, manifest generation, and deployment tools) and the runtime server logic (hook processing, command handling, message templating).
• Event-Driven or Hook-Based Architecture: The server module listens for Mattermost events (user joining, bot commands) and reacts accordingly.
• Template-based Messaging: There is the use of Go templates to generate messages, which provides flexibility in message formatting.