This quick start guide will walk you through the basics of creating a hello world Mattermost App in Python. In this guide you will review an App that:
manifest.json
, declares itself an HTTP application that uses a bot account and attaches to locations in the user interface.form
with a submit
function that can launch a modal (if applicable) and send an interpolated message back to the user./first-command
and /second-command
slash commands to provide functionality.Before you can start with your App, you should first set up your environment by following the developer setup guide.
You also need Python version 3 installed.
In the same mattermost-app-examples repository you cloned via the developer setup guide above, navigate to the `python/hello-world` directory and start the Docker container:
cd python/hello-world
docker compose up
You’ll see Docker install the Python modules and then the App will come online and print the following message:
Running on http://mattermost-apps-python-hello-world:8090
Next, access your development Mattermost Server at http://localhost:8065 and use the /apps install http http://mattermost-apps-python-hello-world:8090/manifest.json
slash command to install the hello world App. Select Agree to grant the app access to APIs and Locations
and click Submit
to finish the installation.
Select the “Hello World” channel header button in Mattermost, which brings up a modal:
Type testing
and select Submit, you should see:
You can use /second-command send testing
to achieve the same result.
You can also use the /first-command
to see a standalone command:
To understand the App, examine the following elements:
The App has to provide a manifest, which declares the App’s metadata required for installation. In this example, the following permissions and locations are requested:
act_as_bot
)/channel_header
)/command
)Bindings specify how an App’s calls should be displayed and invoked from these locations. This App adds a channel header button and slash commands. In order to register these locations, there is a POST
handler for the /bindings
endpoint in your App’s API.
Call handlers are functions that respond to user interactions and webhook events. Forms handle user events on the bindings. This App provides a form
before POST
ing to the /submit
function. In the case of a channel header, the form will launch a modal to collect its fields. In the case of a slash command, the form’s fields will be collected as arguments from the user’s command.
Apps may include static assets (e.g., icon.png
). Static assets must be served under the static
path. For example, there is a icon.png
file in the src/static
directory that this App serves.
Once you’re done with the App, you can uninstall it via the /apps uninstall hello-world
slash command. Alternatively, you can use /apps debug clean
to remove all data for all installed Apps.
To stop and clean up the App from Docker after you’re done, use the following command in the python/hello-world
directory:
docker compose down
You now know how to create a Mattermost App in Python. If you have questions about building Apps or want to show off what you’re building, join us on the Mattermost Apps channel in the Mattermost Community server!