Custom slash commands in Mattermost

Learn how a custom slash command connects a Mattermost user action to your own service, which request fields and tokens you must verify, and how to let non-admin users run it safely.

On this page

How custom slash commands connect Mattermost to your own service

A team wants to type /deploy or /ticket in a channel and have an internal system do the work, then see the result in the same conversation. The supported way to do this is a custom slash command that sends an HTTP POST or GET request to a URL you control. When a user runs the command, Mattermost builds the request from the command text and context fields, sends it to your endpoint, and posts whatever your service returns back into the channel. Your service is the only component that talks to internal systems, so the credentials, network paths and business logic stay in infrastructure you operate.

Every request carries a token that Mattermost generates for the command, and your service should compare that value against the token you stored when the command was created before it acts on anything. Treat the token as a secret: anyone who holds it can send requests that look like they came from Mattermost. Your service also needs to be reachable from the Mattermost server over the network you have chosen, which means confirming egress rules, DNS and TLS trust in your environment before the first test. Mattermost's own documentation for the current server version should be the reference for the exact field names and the GET versus POST options.

This page covers the command itself: its request contract, token verification, response types and who may use it. Incoming webhooks, outgoing webhooks, bot accounts, plugins and the REST API solve different problems and have sibling pages, so read those when the need is posting from outside, reacting to chat messages, or changing server behavior. Before building, decide which system the command calls, which team may run it, and what your service will do if it receives a malformed or unexpected request.

What you need in place before building a slash command

A slash command is a small contract between Mattermost and a service you run, so the platform, the account and the endpoint all have to be settled before any code is written. The cards below cover what to confirm on each side, including the parts that break in restricted networks.

A chosen Mattermost server version

Pick the server version your team will run before designing the command, because the release cadence decides how often you will need to retest. Mattermost releases a new server version in binary form on the 16th of each month, and Extended Support Releases give a longer support window. Check the support end dates for your chosen line, then confirm in the current docs whether slash command creation depends on plan level or specific server settings in that version.

Server releases page

An administrator who can create integrations

Someone with system administrator rights must enable custom slash commands and, if needed, allow non-admin users to create them. Confirm which role your organization will use for this work and who holds it, because the account that creates the command becomes part of the audit trail. Keep this account separate from personal daily use where your policy requires it.

An HTTPS service endpoint

The command sends its request to a URL you control, so that service must be reachable from the Mattermost server over HTTPS with a certificate the server trusts. A private certificate authority is common in internal networks, so confirm that the Mattermost host trusts that chain before testing. Plan for the endpoint to answer within the time Mattermost waits for a response, and test that path end to end.

Network reachability in restricted networks

In air-gapped or coalition networks, the Mattermost server must be able to open a connection to your service, and your service must accept it. Document the firewall rules, DNS names and proxy settings in both directions before the build starts. If the service sits outside the Mattermost network segment, confirm the route and the allowed ports with the network team, because a command that works in a lab can fail silently in production.

A named owner for the endpoint

Assign one accountable owner for the service behind the command, with a backup. The owner handles token rotation, certificate renewal, changes to the response format and decisions about who may run the command. Without a named owner, a command often outlives the person who wrote it and keeps running with credentials nobody tracks.

Confirmed vendor requirements

Before the build, confirm in the vendor's current documentation whether slash command creation depends on your plan level or on specific server settings in your version. Record the answer with the version number and the date you checked, so the configuration can be reviewed later. Ask your DeployOpen or internal team to verify the same settings in the environment you actually run.

What your service receives and what it can return

Your service receives an HTTP request from Mattermost each time a user runs the slash command, and the request carries the information your code needs to act on it. The most important fields are the command text that follows the trigger word, the identifier and display name of the user who ran the command, the channel and team identifiers where it was typed, and a verification token that Mattermost issues for the command. The verification token is how your service confirms the request really came from your Mattermost server, so compare it with the token configured for the command before doing any work. The exact field names, whether the request arrives as POST or GET, and the content type used must be taken from the Mattermost documentation for the version you run, not from memory or from older examples online. Confirm these against the release you deploy, because field names have changed between versions.

The response your service returns controls what appears in the channel. Mattermost reads a response type from the reply and uses it to decide whether the message is shown only to the user who typed the command, which is the usual choice for errors, help text and confirmations, or posted to the whole channel for results the team should see. Choose the default visibility deliberately, since a command that posts to a busy channel by default can expose internal data to people who never asked for it. Plan the response text for both outcomes, and confirm in the documentation for your version which response fields Mattermost accepts, how it renders formatting, and whether a reply can add a follow-up message later.

Your service must answer within the time Mattermost allows for the request. If the reply arrives late, the user sees a failure even when your code finished its work, and the work may be repeated if the user retries. Keep the synchronous handler short, move slow lookups such as calls to external systems into a queued job, and return an immediate acknowledgement when the result will follow later. Ask your development team to measure response times under realistic load and to confirm the current timeout in the Mattermost documentation for your version. Record the timeout in your runbook, because it is one of the first things to check when a command reports that it did not respond.

Configuring the command, token and endpoint in order

This sequence takes a custom slash command from a disabled server setting to a tested command that calls your service, verifies its token and returns a response in a sandbox channel. Each step ends with a check you can run before moving on.

  1. Enable custom slash commands on the server

    A system administrator turns on custom slash commands in the System Console under the integrations settings, and confirms that the option for members to create them is set the way your governance model requires. Before changing anything, record the current setting so you can explain the change later in an audit or review. The step is done when a test account with the appropriate role can open the integration management page and see the slash command option listed. If the option is missing, confirm the setting is saved and that the account has the permissions your administrators have assigned.

  2. Build and host the command endpoint

    Your development team writes a small HTTP service that accepts the POST or GET request Mattermost sends when a user runs the command, and returns a JSON response. Host it on infrastructure you control, reachable from the Mattermost server over HTTPS, and keep it off any public address it does not need. Confirm the handler parses the form fields Mattermost sends, including the command text and the channel and user identifiers. The step is done when a plain curl request with a sample payload returns a valid JSON body with the status code you expect, using a local or staging endpoint.

  3. Create the command with trigger word, method and URL

    A team administrator opens the integrations area, creates a new slash command, and enters the trigger word, the request method (POST or GET), and the full URL of the endpoint. Choose a trigger word that does not clash with a built-in command or another integration in your environment, and confirm the URL uses the hostname your Mattermost server can resolve. Save the command, and note the token that Mattermost generates for it. The step is done when the command appears in the list of integrations with the correct trigger, method and URL, and no validation errors are shown on save.

  4. Copy the token into the verification logic

    Copy the generated token into your service's configuration store, not into source code or a shared chat message, and add a check that rejects any request whose token field does not match. Treat the token as a credential: restrict who can read the configuration and plan how it is rotated. Confirm the check runs before any business logic. The step is done when a request with the correct token is accepted, and a request with a wrong or missing token is refused and writes a log line stating that verification failed, without logging the token value itself.

  5. Set display name, description and autocomplete text

    Fill in the display name, description and autocomplete hint so that users see what the command does when they type the slash in the message box. Keep the autocomplete text short and avoid putting sensitive parameter names or internal system details in it, since it is visible to everyone who can use the command. Confirm the autocomplete suggestion appears in a test channel after you save. The step is done when the suggestion shows the expected trigger and hint text for the command.

  6. Test from a sandbox channel

    Create a private sandbox channel with a small group of testers and run the command with representative inputs, including a valid case, a malformed case and an empty argument. Confirm that the response type (ephemeral or in channel) matches your design and that the message content renders correctly. Review your service logs to see the request, the token verification result and the response returned. The step is done when the valid case returns the expected message, the malformed case returns a clear error, and the logs show the token was verified on every request.

  7. Confirm who can run the command

    Check the permissions for the command with a non-administrator test account, since your goal is to enable it for regular members without giving them rights to change the integration. Confirm that the non-admin can run the command in a channel they belong to, and that the endpoint still receives the correct user identifier so your service can enforce its own authorization. Record the account and result in your change log. The step is done when the non-admin test account runs the command successfully and cannot open the integration settings to edit the token or URL.

Request flow from slash command to your service and back

The flow starts when a user types a slash command in a channel. The Mattermost server sends an HTTP POST or GET request to the HTTPS endpoint of your service, which crosses from the Mattermost side into your network. Your service first checks the token in the request, and nothing runs until that check passes. Only then does the service call the internal system it needs, and the response returns through Mattermost to the channel. Check the token gate and the boundary crossing first when you review the design.

Slash command request path, token gate and return of the response to the channel.

Which user, team and channel details reach your service

This table maps each field a Mattermost slash command sends to your service against the internal use it serves and the matching record in your identity provider. Read it as a checklist for the request handler, then confirm each field name against the Mattermost version you run before writing code. The main takeaway is that the Mattermost user ID is the stable key to join on, while usernames and display names can change.

FieldPrimary useMatching identity in your IdPHandling note
User ID (user_id)Authorization and audit loggingSubject or unique identifier linked to the Mattermost account during SSO or provisioningStable across renames, so use it as the join key rather than the username
Username (user_name)Display in logs and human-readable audit trailsLogin or UPN attribute, if your directory keeps it in syncUsers can change it, so never use it alone for access decisions
Channel ID (channel_id)Routing to the right internal system or channel policyNo direct equivalent; map to a project, cost center or service owner in your own recordsStore the mapping in your service, and confirm whether the field is present for every command context
Channel name (channel_name)Readable context in audit logs and support ticketsNo direct equivalentCan change, so pair it with the channel ID in logs
Team ID (team_id)Scoping which tenant, department or environment a command targetsOrganizational unit or group that owns the teamConfirm the team-level mapping before enabling the command for multiple teams
Command text (text)Parsing arguments and building the action or queryNot applicable; validated against your own allowed actionsTreat as untrusted input and validate every argument on the server
Token (token)Verifying the request came from the configured Mattermost commandNot applicable; a shared secret held by your serviceCompare in constant time and rotate it if it leaks; confirm the field name in your version
Response URL and trigger ID (if sent)Delayed or follow-up replies to the userNot applicableConfirm whether your version sends these fields before relying on them

Choosing between GET and POST and who may create commands

Mattermost sends a slash command to your service as an HTTP request, and you choose whether that request is a GET or a POST when you configure the command. A GET request places the command's parameters in the URL query string. Those values can then appear in web server access logs, reverse proxy records, load balancer logs, browser history if a link is ever opened, and monitoring traces, often without anyone deciding that they should. A POST request carries the same data in the request body, which keeps it out of most of those records by default. Choose POST when the command carries anything sensitive, such as ticket details, customer identifiers, approval reasons or internal hostnames. Choose POST for any command that changes state in another system, because a GET is expected to be safe to repeat and a POST makes that intent clear to your logs and to intermediaries. A GET may be acceptable for a read-only lookup that returns non-sensitive data.

  • Sensitive payloads: Keep anything personal, confidential or credential-like in the POST body, not the query string.
  • State changes: Use POST for commands that create, update, approve or delete records.
  • Read-only lookups: A GET can suit a status query that returns non-sensitive data, but confirm your proxies do not log query strings in detail.
  • Intermediary logging: Check what your ingress, WAF and application logs record for each method before going live.
  • Testing: Send one test command and inspect each log layer to confirm what was stored.

Before approving a command, confirm the method, the fields it sends and where each log layer stores them.

Verifying tokens and limiting what a command can do

A slash command endpoint receives requests from your Mattermost server and acts on your internal systems, so it needs controls at the door and inside the service. The cards below cover request verification, transport, secret handling, permission scope, observability and who is allowed to create commands in the first place.

Verify the token before any work

Every slash command request carries the token configured for that command. Your service should compare it against the expected value on every call and reject mismatches with an error before it parses the text, queries a database or calls another system. Confirm the exact token field and header behavior for your Mattermost version in the integration docs, and test a request with a wrong token to prove the rejection happens early. Treat a missing token the same as a wrong one.

Require HTTPS with a trusted certificate

The command URL carries the token and the user's text in every request, so it should use HTTPS only. Confirm that your Mattermost server can validate the certificate chain of your endpoint, including any internal certificate authority your organization uses. Do not disable verification to get a working test, because that leaves the token readable by anyone on the path. Check certificate expiry as part of the service's routine monitoring.

Store the token outside source code

The verification token is a shared secret between Mattermost and your service. Keep it in your secrets manager or environment configuration, never in a repository, a sample config or a chat message. Plan a rotation procedure that updates the command configuration in Mattermost and your service together, so a rotation does not leave the command failing or the old token valid longer than intended. Restrict who can read the stored value on both sides.

Scope actions to the caller's permissions

A slash command runs with the identity of the user who typed it, but your service may act with its own service account in the internal system. Map the Mattermost user ID to an identity in your system and check that user's rights before each action, so a command cannot do what the user could not do directly. Ask the service owner to list every operation the command can trigger and remove any that the typical caller should not reach.

Log and rate limit the endpoint

Log each request with the command name, Mattermost user ID, team and channel, the outcome and the time, but avoid logging the token or sensitive text in full. Apply rate limits per user and per command so a loop or a misbehaving script cannot flood your internal system. Review these logs alongside your Mattermost audit records when you investigate an incident, and confirm that retention meets your own policy.

Review who can create commands

Confirm which roles can add custom slash commands in your Mattermost configuration before you enable the feature for non-admin users. Each command is a route from chat into a system you control, so a new command should go through the same review as a new API integration, with a named owner, a documented purpose and a test of the verification and permission checks. Remove commands whose owners leave or whose services are retired.

Why a slash command returns no reply or an error

This table pairs each common symptom of a failing custom slash command with its likely cause and a check you can run. Work down the rows in order, since the first symptom you see usually points to the first layer to inspect. Most failures come from a mismatched token, a slow endpoint or an audience setting, not from the command logic itself.

SymptomLikely causeFix
Command is not recognizedThe trigger word is misspelled, the command is disabled, or it was created in a different team than the one where you typed itConfirm the trigger word in the command settings, check that the command is enabled, and retype it in the same team where it was created
Token check fails after setupThe verification token was truncated or picked up extra spaces when copied into your serviceCompare the token in your service configuration with the value shown in Mattermost character by character, and remove leading or trailing whitespace
Command times out with no replyYour service takes longer to respond than Mattermost waits, or the request is blocked by a firewall or proxyTime the endpoint with a test POST from the Mattermost server itself, move slow work to a later asynchronous response, and check egress rules between the server and your service
Reply is malformed or ignoredThe response is not valid JSON, uses the wrong content type, or sets a response type the command does not expectCapture the raw response body from your service, validate the JSON, and confirm the response type and text fields match the documented format
Reply appears to the wrong audienceThe response type is set to in-channel when you meant ephemeral, or the reply is posted in a channel the user did not expectCheck the response type in your service output, then post a test command in a private test channel to confirm who sees the message
Non-admin cannot see or run the commandThe command is restricted to system admins, or the user lacks access to the team or channel where it is usedReview the command permissions in the System Console, then test with a non-admin test account in the target team and channel
Certificate error from a private certificate authorityThe Mattermost server does not trust the internal certificate authority that signed your service endpoint's certificateConfirm the endpoint certificate chain with an openssl check from the Mattermost host, then add the internal root to the operating system trust store used by the server and restart it

Questions teams ask before building slash commands

What drives the cost and effort of a custom slash command?

The main drivers are how many commands you need, how many internal systems each command calls, how access is authorized, and how much testing and operating work follows. A single command that reads one read-only API is a small job. Ten commands that write to a ticketing system, a directory and a billing tool need design for error handling, permission checks and audit trails on each path. Ask any quote to break the work down by command, by backend system and by testing and handover, so you can see which items you could take in-house.

What keeps needing attention after a slash command launches?

Several items recur. Verification tokens for each command should be rotated on a schedule your security team sets, and every rotation needs a matching change in Mattermost. The service behind each command must be patched like any other internet-facing or internal application, and its dependencies need updates. Mattermost releases a new server version in binary form on the 16th of each month, so each command should be retested against the versions you run. Confirm with your team who owns each of these tasks before launch, not after the first incident.

Can our internal team build a slash command without outside help?

Yes, if your team has an engineer who can write a web service, handle HTTP requests and manage secrets, and someone who administers the Mattermost server. The Mattermost side is configuration plus a service that accepts the POST or GET request and returns a valid response. The harder parts are usually authorization decisions, safe handling of user input and getting sign-off from security and the owners of the systems being called. An outside partner is most useful when several commands must share a design or when the team lacks capacity to test and operate them.

What does the work need from our side?

You need a named endpoint owner who will run the service that receives the command requests, and test accounts with the same roles your real users hold so authorization can be checked. A sandbox channel or team on a non-production Mattermost lets people try commands without posting to live channels. Security sign-off should cover how tokens are stored, what each command can read or change, and how requests are logged. Finally, name a Mattermost administrator who will enable the feature and decide which users or roles may run each command.

How long does a simple slash command take to build and test?

A single command that calls one internal API with read-only access is usually the shortest path, and most of the time goes to the endpoint, testing and sign-off rather than the Mattermost configuration itself. Duration depends on how quickly your service owner can expose an endpoint, how many permission cases need tests, and how long your security review takes. We do not publish a timeline for this work. Ask for a schedule tied to a written scope that lists the commands, the backend systems and the test environments.

When is a plugin or an outgoing webhook a better fit than a slash command?

A slash command fits when a user types a deliberate request, such as looking up a record or starting a process, and receives a reply. An outgoing webhook fits when Mattermost should send messages matching a trigger word to an external service automatically. A plugin fits when you need deeper behavior inside Mattermost, such as custom UI, background jobs or server-side logic, and it carries more build, testing and upgrade work across monthly releases. Choose the simplest mechanism that meets the requirement, and confirm the trade-offs with your Mattermost administrator before committing.

Who should approve the security design before commands go live?

Your security team or information security function should approve the design before production use. Their review should cover how each command verifies that a request came from Mattermost, where the verification token is stored, which permissions the backend service uses and what data is written to logs. Ask them to confirm that commands enabled for non-admin users are limited to actions those users are already allowed to take in the source systems. Record the approval with the command list so future changes go through the same check.

How DeployOpen scopes, builds and supports your slash commands

DeployOpen plans, builds, tests and documents custom Mattermost slash commands backed by your own service, inside infrastructure you control. Engagements are fixed-scope, so the endpoint, token handling, response behavior and access model are agreed in writing before any code is written.

How we scope

  • Written scope names each slash command, its trigger word, and the internal service it calls.
  • Scope records whether the command uses HTTP POST or GET and which response types it returns.
  • Scope states which teams may run each command and whether non-admin users need enabling.
  • Confirm with your team which Mattermost plan and server version your deployment runs.

How we build

  • Build the receiving service with token verification so only your Mattermost server can call it.
  • Store command tokens in your secrets manager, never in the command definition or source control.
  • Test ephemeral, in-channel and error responses against the Mattermost server you operate.
  • Check that non-admin roles can run only the commands the written scope allows.

How we hand over

  • Deliver the source code, configuration steps and a record of each command's endpoint and permissions.
  • Document token rotation, the callback URL and how to disable a command during an incident.
  • Walk your administrators through enabling commands and reviewing who can use them.

How we support

  • Ongoing support is available as a retainer for changes to commands and their backing services.
  • Retainers can cover retesting commands after each Mattermost upgrade you schedule.
  • Support can include reviewing command logs and access changes as your teams and roles change.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.