Mattermost Peer-to-Peer Forum

New command slash


#1

I am a beginner, so please be understanding. I want to create commands in mattermost “ping”, “whois” and “ps”. I have no idea how to adapt my file to work with the mattermost.

I have something like that.

<?php

$json = file_get_contents('php://input');
$update = json_decode($content, true);


//CMD
switch ($text):
	
	case "/whois":
		$status = "$text,0";
		file_put_contents($file, $status);
		$msg = "Enter the domain to search";
	break;	
	case "/ping":
		$status = "$text,0";
		file_put_contents($file, $status);
		$msg = "enter the IP address";
	break;		
	case "/ps":
		$status = "$text,0";
		file_put_contents($file, $status);
		$msg = "enter the text";
	break;	
endswitch;
?>

Can I count on any tips?


#2

Hi @MajorS,

It’s been a long while since I’ve written any PHP but generally what you’ll want to do is, is set up three different slash commands on your Mattermost server. Then point each one at your different URLs (e.g. https://yourdomain.com/whois). Have the user pass in any arguments after the slash command when they type it. Then on your server, parse the HTTP POST and respond appropriately with a message body for what you want to respond with.

See the documentation for more details: https://docs.mattermost.com/developer/slash-commands.html#custom-slash-command