0. Install [ngrok](https://ngrok.com/download) (`$ brew cask install ngrok` on a mac), which will expose the local server to the internet so GitHub can send webhooks
0.`ngrok` will use a different URL every time it is restarted, so you will have to go into the [settings for your Integration](https://github.com/settings/installations) and update all the URLs.
[Actions](docs/configuration.md#then) are called when a webhook is delivered and any conditions are met. For example, this configuration in `.probot` calls two actions when a new issue is opened:
Implementing new actions is relatively straight forward. Create a file in `lib/actions/{name}.js`, replacing `name` with the name of the action, and add the new action in [`lib/actions.js`](lib/actions.js). An action is a function that takes two arguments and returns a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise):
- The aptly named [`context`](lib/context.js) argument provides context for the current webhook. There are two properties that will likely be most helpful:
-`context.github` is an authenticated instance of the GitHub API client. See the [node-github documentation](http://mikedeboer.github.io/node-github/) for more information.
-`context.payload` is the webhook payload. Depending on the type of event, the payload will be slightly different. See the [GitHub webhook docs](https://developer.github.com/webhooks/#payloads) for more information.
-`args` is any arguments passed to the action. For the `label` action called in the example above, `args` will be the string `"triage"`.
Actions must return a `Promise` that gets resolved when the action completes. Fortunately, the GitHub API client available in `context.github` returns promises, so you can usually just return the API call. For example, here is the full implementation of the `react` action:
```javascript
module.exports = function (context, react) {
return context.github.reactions.createForIssue(
context.payload.toIssue({content: react})
);
};
```
Note that `context.payload.toIssue()` will extract the `owner`, `repo`, and `number` params from the [`issues`](https://developer.github.com/v3/activity/events/types/#issuesevent) or [`pull_request`](https://developer.github.com/v3/activity/events/types/#pullrequestevent) events.
That's it! You now have everything you need to implement an action. If you're looking for ideas of new actions to add, check out this [tracking issue for unimplemented GitHub actions](https://github.com/bkeepers/PRobot/issues/21).
[Conditions](docs/configuration.md#then) are called when a webhook is delivered and are used to determine if the actions should be called. For example, this configuration in `.probot` checks if an issue or pull request has a label before closing it:
Like [adding an action](#actions), adding a new condition is straight forward. Create a file in `lib/conditions/{name}.js`, replacing `name` with the name of the condition, and add the new condition in [`lib/conditions.js`](lib/conditions.js). A condition is a function that takes two arguments and returns `true` or `false`: