Mattermost, Inc.

[SOLVED] Passing slash command parameters

I have not found any examples of how to pass a parameter to a slash command. Could someone kindly post one?

e.g.
/customcmd key value

http://echo.jsontest.com/key/value/$key/$value
-or-
http://echo.jsontest.com/key/value/$cmd1/$cmd2

Thanks.

Hi @lionelb8,

Per our documentation, when you set up a custom slash command and that command is triggered a HTTP POST will be sent to the URL you provided with a body like so:

Content-Length: 244
User-Agent: Go 1.1 package http
Host: localhost:5000
Accept: application/json
Content-Type: application/x-www-form-urlencoded

channel_id=cniah6qa73bjjjan6mzn11f4ie&
channel_name=town-square&
command=/customcmd&
response_url=not+supported+yet&
team_domain=someteam&
team_id=rdc9bgriktyx9p4kowh3dmgqyc&
text=key+value&
token=xr3j5x3p4pfk7kk6ck7b4e6ghh&
user_id=c3a4cqe3dfy6dgopqt8ai3hydh&
user_name=somename

You can then parse the parameters out of the text field provided above. If text is empty then the user did not supply any parameters.

Thank you that is exactly what I needed to know. Thank you.

It would have been good if the parameters could be parsed through a custom regex with capturing groups, where the assigned group values could be used in the url as variables.

The current implementation means that only custom code at the URL target can be used for slash commands, which is extremely limiting. Turns mattermost into a developer tool rather than an end user product.

1 Like

I basically needed the same thing. A way to pass in args /test branchName and have it append the branch name as a query param: host.com/blah?branch=branchName.