<commit_before>## Creating a module

Creating a module for botpress is extremely easy and straightforward. You may choose to create local modules or to publish them back to the community (please!). In either way, the process is exactly the same; so you may choose to create a module for yourself and later publish it.

### Anatomy of a module

To create a module, simply run the following command in an empty directory:

```
botpress create
```

Botpress will ask you a couple of questions and bootstrap the module for you. At this point you should have a new folder with some files in it. All you need to do now is `cd` in the directory and install the local dependencies:

```
npm install
```

**Note: modules are required to start by `botpress-`, otherwise they are ignored and won't be loaded by your bot.** The CLI tool enforces this rule and it should not be changed manually for this reason.

A botpress module looks like so:

```
/src
    index.js
    /views
         index.jsx
         style.scss
package.json
webpack.js
LICENSE
.gitignore
.npmignore
```

As you can see, all the module's logic is inside the `/src` directory. A module has a backend module and a frontend component (/views/index.jsx).

- `webpack.js` bundles your module. Botpress can't load your module if it's not bundled. In most cases, you won't have to deal with webpack or this file directly; everything should work out of the box.

- `package.json` is a regular package.json file, except that is has a mandatory `botpress` configuration entry. You may change the module display name and logo there. Some necessary dependencies have also been installed by default.

- `LICENSE` either AGPL3 or the Botpress License. Defaults to AGPL3.

- `/src/index.js` The module's backend entry point. This is where the module logic goes.

- `/src/views/index.jsx` The module's frontend entry component (written in [React](TODO)). This is where the frontend logic goes.

### Backend

A module entry point is an object that exposes two methods: `init` and `ready`.

Both methods take **`bp`** as their first argument and does not need to return anything.

- `init(bp)` is called on module initialization (before the bot is started). Middlewares registration usually goes here.
- `ready(bp)` is called once all modules are loaded and the bot is fully started. Routing and module logic usually go here.

To see examples of how modules are implemented, you may look at the source of existing modules such as [`botpress-messenger`](https://github.com/botpress/botpress-messenger/blob/master/src/index.js).

### Frontend

The front-end of a module is a [React Component](https://facebook.github.io/react/docs/react-component.html). All you have to do is import React and export a React.Component class in `/src/views/index.jsx`.

Botpress will pass an instance of the front-end `bp` instance and a pre-configured `axios` to your module component:

- `bp` exposes `bp.events`, which is an instance of the [EventBus](TODO)
- [`axios`](https://github.com/mzabriskie/axios) is pre-configured to provide the required authentication token by the API routes

#### Example

```js
import React from 'react'

export default class TemplateModule extends React.Component {

  emitEvent() {
    this.props.bp.events.emit('test.clicked', { a: '123' })
  }
  render() {
    return <button onClick={::this.emitEvent}>Click me</button>
  }
}
```

To see more examples of how modules are implemented, you make have a look to the source of existing modules such as [`botpress-messenger`](https://github.com/botpress/botpress-messenger/blob/master/src/views/index.jsx).
### Compiling

### Testing & Local development

### Publishing<commit_msg>Updates docs/creating-a-module.md<commit_after>## Creating a module

Creating a module for botpress is extremely easy and straightforward. You may choose to create local modules or to publish them back to the community (please!). In either way, the process is exactly the same; so you may choose to create a module for yourself and later publish it.

### Anatomy of a module

To create a module, simply run the following command in an empty directory:

```
botpress create
```

Botpress will ask you a couple of questions and bootstrap the module for you. At this point you should have a new folder with some files in it. All you need to do now is `cd` in the directory and install the local dependencies:

```
npm install
```

**Note: modules are required to start by `botpress-`, otherwise they are ignored and won't be loaded by your bot.** The CLI tool enforces this rule and it should not be changed manually for this reason.

A botpress module looks like so:

```
/src
    index.js
    /views
         index.jsx
         style.scss
package.json
webpack.js
LICENSE
.gitignore
.npmignore
```

As you can see, all the module's logic is inside the `/src` directory. A module has a backend module and a frontend component (/views/index.jsx).

- `webpack.js` bundles your module. Botpress can't load your module if it's not bundled. In most cases, you won't have to deal with webpack or this file directly; everything should work out of the box.

- `package.json` is a regular package.json file, except that is has a mandatory `botpress` configuration entry. You may change the module display name and logo there. Some necessary dependencies have also been installed by default.

- `LICENSE` either AGPL3 or the Botpress License. Defaults to AGPL3.

- `/src/index.js` The module's backend entry point. This is where the module logic goes.

- `/src/views/index.jsx` The module's frontend entry component (written in [React](TODO)). This is where the frontend logic goes.

### Backend

A module entry point is an object that exposes two methods: `init` and `ready`.

Both methods take **`bp`** as their first argument and does not need to return anything.

- `init(bp)` is called on module initialization (before the bot is started). Middlewares registration usually goes here.
- `ready(bp)` is called once all modules are loaded and the bot is fully started. Routing and module logic usually go here.

To see examples of how modules are implemented, you may look at the source of existing modules such as [`botpress-messenger`](https://github.com/botpress/botpress-messenger/blob/master/src/index.js).

### Frontend

The front-end of a module is a [React Component](https://facebook.github.io/react/docs/react-component.html). All you have to do is import React and export a React.Component class in `/src/views/index.jsx`.

Botpress will pass an instance of the front-end `bp` instance and a pre-configured `axios` to your module component:

- `bp` exposes `bp.events`, which is an instance of the [EventBus](TODO)
- [`axios`](https://github.com/mzabriskie/axios) is pre-configured to provide the required authentication token by the API routes

#### Example

```js
import React from 'react'

export default class TemplateModule extends React.Component {

  emitEvent() {
    this.props.bp.events.emit('test.clicked', { a: '123' })
  }

  render() {
    return <button onClick={::this.emitEvent}>Click me</button>
  }
}
```

To see more examples of how modules are implemented, you make have a look to the source of existing modules such as [`botpress-messenger`](https://github.com/botpress/botpress-messenger/blob/master/src/views/index.jsx).
### Compiling

### Testing & Local development

### Publishing
{'fraction_non_alphanumeric': 0.08737995401055051, 'fraction_numerical': 0.0013526308670363857, 'mean_word_length': 4.060917180013689, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3187544', 'n_tokens_mistral': 2064, 'n_tokens_neox': 1985, 'n_words': 1004}