.circleci | ||
assets | ||
build | ||
public | ||
server | ||
webapp | ||
.editorconfig | ||
.gitattributes | ||
.gitignore | ||
.golangci.yml | ||
go.mod | ||
go.sum | ||
LICENSE | ||
Makefile | ||
plugin.json | ||
README.md |
Plugin Starter Template 
This plugin serves as a starting point for writing a Mattermost plugin. Feel free to base your own plugin off this repository.
To learn more about plugins, see our plugin documentation.
Getting Started
Use GitHub's template feature to make a copy of this repository by clicking the "Use this template" button.
Alternatively shallow clone the repository matching your plugin name:
git clone --depth 1 https://github.com/mattermost/mattermost-plugin-starter-template com.example.my-plugin
Note that this project uses Go modules. Be sure to locate the project outside of $GOPATH
.
Edit plugin.json
with your id
, name
, and description
:
{
"id": "com.example.my-plugin",
"name": "My Plugin",
"description": "A plugin to enhance Mattermost."
}
Build your plugin:
make
This will produce a single plugin file (with support for multiple architectures) for upload to your Mattermost server:
dist/com.example.my-plugin.tar.gz
Development
To avoid having to manually install your plugin, build and deploy your plugin with login credentials:
export MM_SERVICESETTINGS_SITEURL=http://localhost:8065
export MM_ADMIN_USERNAME=admin
export MM_ADMIN_PASSWORD=password
make deploy
or with a personal access token:
export MM_SERVICESETTINGS_SITEURL=http://localhost:8065
export MM_ADMIN_TOKEN=j44acwd8obn78cdcx7koid4jkr
make deploy
If developing a plugin with a webapp, watch for changes and deploy those automatically:
export MM_SERVICESETTINGS_SITEURL=http://localhost:8065
export MM_ADMIN_TOKEN=j44acwd8obn78cdcx7koid4jkr
make watch
Q&A
How do I make a server-only or web app-only plugin?
Simply delete the server
or webapp
folders and remove the corresponding sections from plugin.json
. The build scripts will skip the missing portions automatically.
How do I include assets in the plugin bundle?
Place them into the assets
directory. To use an asset at runtime, build the path to your asset and open as a regular file:
bundlePath, err := p.API.GetBundlePath()
if err != nil {
return errors.Wrap(err, "failed to get bundle path")
}
profileImage, err := ioutil.ReadFile(filepath.Join(bundlePath, "assets", "profile_image.png"))
if err != nil {
return errors.Wrap(err, "failed to read profile image")
}
if appErr := p.API.SetProfileImage(userID, profileImage); appErr != nil {
return errors.Wrap(err, "failed to set profile image")
}
How do I build the plugin with unminified JavaScript?
Use make dist-debug
and make deploy-debug
in place of make dist
and make deploy
to configure webpack to generate unminified Javascript.