How to implement an interface in your integration
Finding the interface to implement
Unfortunately, interface are not yet listed on our website, so you must find them in the Botpress GitHub repository. To find the interface you want to implement, follow these steps:
Open the interfaces directory
Navigate to the interfaces
directory of the botpress/botpress repository.
Find the interface
Find the interface you want to implement and open its directory.
Find the name and version
Open the interface.definition.ts
file to find the interface name
and version
.
Adding the interface as a dependency
Once you have the interface name and version, you can add it as a dependency to your integration:
Open the package.json file
Open your integration’s package.json
file.
Add the bpDependencies section
If there is no bpDependencies
section in your integration’s package.json
file, create one:
Add the interface as a dependency
In the bpDependencies
section, add the interface name and version as a dependency. For example, with an interface named creatable
and version 0.0.1
, you would add the following:
It is very important to follow this syntax:
"<interface-name>": "interface:<interface-name>@<version>"
.
Save the package.json file
Save the package.json
file.
Install the interface
Now that you have added the interface as a dependency, you can run the bp add
command to install it. This command will:
- Download the interface from Botpress.
- Install it in a directory named
bp_modules
in your integration’s root directory.
Adding a helper build script
To keep your integration up to date, we recommend adding a helper build script to your integration:
Open the package.json file
Open your integration’s package.json
file.
Add the build script
In the scripts
section, add the following script:
If the build
script already exists in your package.json
file, please replace it.
Save the package.json file
Save the package.json
file.
Now, whenever you run npm run build
, it will automatically install the interface and build your integration. This is useful for ensuring that your integration is always up to date with the latest version of the interface.
Adding the interface to your integration definition file
Now that the interface is installed, you must add it your integration definition file in order to implement it.
Open the integration.definition.ts file
Open your integration’s integration.definition.ts
file.
Import the interface
At the top of the file, import the interface. For example, with an interface named creatable
, you would add the following import statement:
Extend your definition
Use the .extend()
function at the end of your new IntegrationDefinition()
statement. For example, with an interface named creatable
, you would add the following:
Next steps
Since each interface has its own specific requirements, you should refer to the interface documentation for more information.
Was this page helpful?