Update 14/09/2020: Now you can create your custom module using a new tool that you can download from here. Checkout above video for more details.
The simplest way that worked for me was to copy the existing complete-module to a custom module, say test-module.
Copy examples\module-templates\complete-module
to modules\test-module
location
Next, change the following files with details like module name and description wherever applicable
- modules\test-module\package.json
- modules\test-module\src\backend\index.ts
- modules\test-module\src\backend\api.ts
Inside out\bp\data\global\botpress.config.json
add below entry, to register and enable your custom module
{ ... "modules": [ ... { "location": "MODULES_ROOT/test-module", "enabled": true } ... ] ... }
Open a terminal in modules\test-module
location, run yarn && yarn build
and start Botpress yarn start
Choose any bot in your workspace and you should see test-module
on the side bar.
Congratulations you have created your very own custom module.
Note: Using Botpress v12.10.5
Troubleshooting module-builder error
If you encounter below errors, then most probably the Botpress source is missing (dev tools), you must build the source.
$ ./node_modules/.bin/module-builder build '.\node_modules\.bin\module-builder' is not recognized as an internal or external command, operable program or batch file. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
All modifications and customization needs the below 2 steps, module builder is not included in the shipped binary (no dev tools are present, the reason being the binary size would increase)
- Clone the repository https://github.com/botpress/botpress
- Build using
yarn && yarn build
16 Comments
Kenneth Kaigu · August 3, 2019 at 7:05 pm
Great tutorial…
What kind of custom module can you create ?
Abhishek Simon · August 3, 2019 at 7:46 pm
Thank you, so far I have created a few chart.js components, customized scrollable card and a rating component.
Few other components like datatable, calendar date picker are some components that I will be creating in some days.
Joey Stella · August 9, 2019 at 9:53 pm
I am trying to do this; however, my terminal does not recognize ‘yarn’ commands, when it is in the module. Do you know how to solve this problem?
Abhishek Simon · August 10, 2019 at 12:36 am
Check whether yarn is present in your path.
Joey Stella · August 14, 2019 at 8:15 pm
So, if you are trying to create a fully custom module, do you need to move botpress-master into whatever version of botpress you are using? Because I have not been able to figure that part out.
Abhishek Simon · November 17, 2019 at 8:35 pm
@Joey Stella: Botpress-master is the source where you create your custom module and components. You can keep your custom module as a shared folder between all your Botpress source/binaries and refer them and it should work.
Also, check out the latest post, it might help you further.
https://abhisheksimon.wordpress.com/2019/11/17/upgrading-bot-to-latest-botpress-version/
Anil · November 19, 2019 at 4:23 pm
I am getting the same error >>>
$ ./node_modules/.bin/module-builder build
‘.\node_modules\.bin\module-builder’ is not recognized as an internal or external command,
operable program or batch file.
error Command failed with exit code 1.
Can you please tell what I need to do to solve this…
Abhishek Simon · November 19, 2019 at 7:12 pm
@Anil Are you trying to build from binary, as it will not work? Please follow the last 2 steps mentioned in this guide. 1. clone from the repository then run “yarn && yarn build”
Anil · December 4, 2019 at 12:08 pm
How to include dev tools that are missing in the existing botpress withourt cloning the entire repo.If possible Can you add a video of creating module and creting custom component,That would be very heplful
Abhishek Simon · December 4, 2019 at 8:53 pm
@Anil The process is, create a custom module in the source (Github) once you are satisfied, use it in the binary, for your deployment purposes. If you follow the steps exactly mentioned in this post, you will be able to create your own custom module. Next, you can follow the exact steps mentioned in “How to create a custom component in Botpress?”.
If you still feel something is missing do let me know, will try to clarify your doubts.
At present, I am unable to create any videos due to work-related commitments.
Harald · June 7, 2020 at 10:12 pm
I get this error.
harald@Entwicklung:~/botpress/modules/test-module$ yarn && yarn build
yarn install v1.22.4
[1/4] Resolving packages…
success Already up-to-date.
Done in 0.07s.
yarn run v1.22.4
$ node ../../build/module-builder/bin/entry build
[module-builder] [ERROR] in /home/harald/botpress/modules/test-module/src/backend/index.ts (38,3)
TS2322: Type ‘(botId: string) => Promise’ is not assignable to type ‘(bp: typeof import(“botpress/sdk”), botId: string) => Promise’.
Types of parameters ‘botId’ and ‘bp’ are incompatible.
Type ‘typeof import(“botpress/sdk”)’ is not assignable to type ‘string’.
[test-module] Generated frontend bundle (1082 ms)
[test-module] Generated frontend bundle (922 ms)
[module-builder] Build completed
Done in 8.96s.
Simon · June 8, 2020 at 2:00 pm
@Harald Can you check below 3 files, whether it has proper name changes according to your module name?
1. modules\custom-module\src\backend\index.ts
Provide name, menuText and fullName according to your module name
2. modules\custom-module\src\backend\api.ts
Provide module name in
bp.http.createRouterForBot
andawait bp.config.getModuleConfigForBot
3. modules\test-module\package.json
Provide name according to your module name
AHMAD FAUZAN ARIF X RPL · June 2, 2021 at 7:02 am
i got this eror while process install npm install prompt mustache fs fs-extra path
E:\test\create-botpress-custom-module-master>npm install prompt mustache fs fs-extra path
npm ERR! code ENOENT
npm ERR! syscall spawn git
npm ERR! path git
npm ERR! errno -4058
npm ERR! enoent Error while executing:
npm ERR! enoent undefined ls-remote -h -t https://git@github.com/flatiron/prompt.git
npm ERR! enoent
npm ERR! enoent
npm ERR! enoent spawn git ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\dell\AppData\Roaming\npm-cache\_logs\2021-06-02T01_33_23_112Z-debug.log
Simon · June 29, 2021 at 11:35 pm
@Ahmad Try using npm v6.14.11 and node v12.21.0 Check this screenshot
How to create a wrapper over dialog in Botpress? – Abhishek Simon · August 2, 2019 at 2:18 pm
[…] infa-module is my custom module, all customizations are done under this module. Read through this blog and create your own custom […]
How to create a custom component in Botpress? – Abhishek Simon · August 6, 2019 at 2:59 pm
[…] jump in to create our custom component, one needs to create a custom module. Please follow along this guide to create your custom module, then come back and […]