The unidirectional file synchronization interface allows you to implement 1-way sync in your integration to import files from an external service to Botpress.
package.json
filefiles-readonly
interface is:
You will need this version number for the next steps.
Open the package.json file
package.json
file.Add the bpDependencies section
bpDependencies
section in your integration‘s package.json
file, create one:Add the interface as a dependency
bpDependencies
section, add the file synchronization interface as a dependency. For example, for version 0.2.0
, you would add the following:"<interface-name>": "interface:<interface-name>@<version>"
.Save the package.json file
package.json
file.Install the interface
bp add
command to install it. This command will:bp_modules
in your integration‘s root directory.package.json
file:
Open the package.json file
package.json
file.Add the build script
scripts
section, add the following script:build
script already exists in your package.json
file, please replace it.Save the package.json file
package.json
file.npm run build
, it will automatically install the file synchronization interface and build your integration.
Open the integration.definition.ts file
integration.definition.ts
file.Import the interface
Extend your definition
.extend()
function at the end of your new IntegrationDefinition()
statement:.extend()
will be explained in the next section..extend()
function takes two arguments:
filesReadonly
.listItemsInFolder
- Used by the file synchronizer plugin to request a list of all files and folders in a folder.transferFileToBotpress
- Used by the file synchronizer plugin to request that a file be downloaded from the external service and uploaded to Botpress.listItemsInFolder
to crawlFolder
, you can do it like this:
listItemsInFolder
to listNotebooksAndPages
and transferFileToBotpress
to downloadPage
. This way, the action names reflect the specific context of the notetaking platform, making your integration clearer and easier to understand.fileCreated
- Emitted by your integration to notify the file synchronizer plugin that a new file has been created in the external service.fileUpdated
- Emitted by your integration to notify the file synchronizer plugin that a file has been updated in the external service.fileDeleted
- Emitted by your integration to notify the file synchronizer plugin that a file has been deleted in the external service.folderDeletedRecursive
- Emitted by your integration to notify the file synchronizer plugin that a folder and all of its contents have been deleted in the external service.aggregateFileChanges
event, which contains all the changes in a single event.fileCreated
to pageCreated
, you can do it like this:
listItemsInFolder
listItemsInFolder
action is used by the file synchronizer plugin to request a list of all files and folders in a folder.
listItemsInFolder
in the “Configuring the interface” section, please use the new name instead of listItemsInFolder
.Get the folder ID
input.folderId
. When this value is undefined
, it means the file synchronizer plugin is requesting a list of all items in the root directory of the external service. For root directory requests, please refer to the documentation of the external service to determine the correct root identifier - this is typically an empty string, a slash character (/
), or a special value defined by the service.Get the list of items
input.nextToken
), use it to get the next page of items. The external service should return a new pagination token in the response, which you should return with the action’s response.Map each items to the expected schema
Yield control back to the plugin
nextToken
field. The file synchronizer plugin will use this token to request the next page of items. Otherwise, return undefined
.transferFileToBotpress
transferFileToBotpress
action is used by the file synchronizer plugin to request that a file be downloaded from the external service and uploaded to Botpress.
transferFileToBotpress
in the “Configuring the interface” section, please use the new name instead of transferFileToBotpress
.Get the file ID
input.file.id
. This is the identifier of the file to be downloaded from the external service.Download the file from the external service
Upload the file to Botpress
client.uploadFile
method. This method expects both the file’s content and a file key, which is provided by the file synchronizer plugin as input.fileKey
.Yield control back to the plugin
fileCreated
Add a webhook handler
Map the file to the expected schema
Emit the event
fileCreated
event with the mapped file as the payload. The file synchronizer plugin will then handle the rest of the synchronization process.fileUpdated
fileCreated
event, but you should emit the fileUpdated
event instead.
fileDeleted
fileCreated
event, but you should emit the fileDeleted
event instead.
folderDeletedRecursive
Add a webhook handler
Map the folder to the expected schema
Emit the event
folderDeletedRecursive
event with the mapped folder as the payload. The file synchronizer plugin will then handle the rest of the synchronization process.aggregateFileChanges
fileCreated
, fileUpdated
, fileDeleted
, or folderDeletedRecursive
events, but you should emit the aggregateFileChanges
event instead:
aggregateFileChanges
event. This is more efficient and faster to process for the file synchronizer plugin.