Writing your own commands
This page shows how to add commands to Prosody’s built-in console.
This method of adding commands is deprecated since Prosody 13.0. It can still be used (for now) if you need to remain compatible with Prosody 0.12, but newer modules should refer to the new shell command documentation instead.
An example module that adds a command to the telnet console:
:set_global();
module
local env = module:shared("/*/admin_telnet/env");
.mycommands = {} -- a table to keep your commands in
env
function env.mycommands:hello()
return "Hello, World!";
end
With this saved in a mod_my_telnet_command.lua
and loaded you should be able to call this
command like so:
mycommands:hello()
| OK: Hello, World!
It is also possible to output additional data and indicate success or failure:
function env.mycommands:sayhi(name)
if name then
.session.print("Hi, " .. name);
selfreturn true, "Said hi"; -- Boolean true for success, and a status
else
return false, "You didn't tell me your name :("
end
end