This repository was archived by the owner on Nov 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
HTTP API Command Handlers
sharedferret edited this page Apr 10, 2012
·
1 revision
HTTP API command handlers are JavaScript files contained in the api/ folder of the project. These handlers are loaded each time the bot is started. These handlers are executed when an HTTP API call is made to the bot.
Each handler follows this format:
exports.name = 'nowplaying';
exports.hidden = false;
exports.enabled = true;
exports.handler = function(queryArray, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Sample text\n');
}
- The name field gives the name of the command that will trigger this command.
- The hidden field tells the bot whether to display the command name in any call that would show a list of commands (not implemented yet).
- The enabled field toggles the command on/off (if enabled is false, the command will not be run).
- The handler function is where the implementation of the command goes.
- queryArray: The query section of the URL the user entered. Typically, this will consist of a "command" parameter, an optional "format" parameter, and any needed value parameters. The "command" parameter is matched to exports.name when a query is made.
- response: This is the object you use to respond to the HTTP query. To write a response, call writeHead() and end([data]).