# Robot

The `robot` parameter available to apps

## Constructor

#### new Robot()

##### Properties:

Name | Type | Description
--- | --- | ---
`log` | `logger` | A logger

Source:
  - robot.js, line 12

### Methods

#### on(event, callback)

Listen for GitHub webhooks, which are fired for almost every significant action that users take on GitHub.

Source:
  - robot.js, line 86

##### Parameters:

Name | Type | Description
--- | --- | ---

`event`

`string`

the name of the GitHub webhook event. Most events also include an "action". For example, the * `issues` event has actions of `assigned`, `unassigned`, `labeled`, `unlabeled`, `opened`, `edited`, `milestoned`, `demilestoned`, `closed`, and `reopened`. Often, your bot will only care about one type of action, so you can append it to the event name with a `.`, like `issues.closed`.

`callback` | `Robot~webhookCallback` | a function to call when the webhook is received.

##### Example

    robot.on('push', context => {
      // Code was just pushed.
    });

    robot.on('issues.opened', context => {
      // An issue was just opened.
    });

#### route(path)

Get an express router that can be used to expose HTTP endpoints

Source:
  - robot.js, line 49

##### Parameters:

Name | Type | Description
--- | --- | ---
`path` | `string` | the prefix for the routes

##### Returns:

express.Router

##### Example

    module.exports = robot => {
      // Get an express router to expose new HTTP endpoints
      const app = robot.route('/my-app');

      // Use any middleware
      app.use(require('express').static(__dirname + '/public'));

      // Add a new route
      app.get('/hello-world', (req, res) => {
        res.end('Hello World');
      });
    };

### Type Definitions

#### webhookCallback(context)

Do the thing

Source:
  - robot.js, line 193

##### Parameters:

Name | Type | Description
--- | --- | ---

`context`

`Context`

the context of the event that was triggered, including `context.payload`, and helpers for extracting information from the payload, which can be passed to GitHub API calls.

     module.exports = robot => {
       robot.on('push', context => {
         // Code was pushed to the repo, what should we do with it?
         robot.log(context);
       });
     };