Categories:
Develop a plugin and activate it in Aura Bridge
Guidelines for the generation of a new plugin and its activation/deactivation in Aura Bridge
Introduction
The process for the generation of a plugin and its activation or deletion in aura-bridge includes the following steps:
- Plugin development
- Plugin activation in Aura bridge
- Plugin removal (if required)
Plugin development
Install aura-development-cli (aucli)
To generate a new plugin, use aucli, a set of tools available in the “Command Line Interface” format to help you with development and testing.
How to use aucli?
-
Access the “help” command:
$ aucli bridge -h Usage: aucli bridge [options] [command] tasks associated with 'bridge' commands Options: -h, --help display help for command Commands: generate tasks associated with 'generate' commands help [command] display help for command -
Execute the following command in the aura-bridge project path:
$ aucli bridge generate plugin ✔ Whats the origin of the process? (ex.: Directline, Whatsapp, ...)? · channel1 ✔ Whats the destination of the process? (ex.: Directline, Whatsapp, ...)? · channel2 ✔ The name of processor is correct? (y/N) · true -
The following files will be generated in aura-bridge:
added: src/plugins/channel1-channel2-processor/channel1-channel2-consume-services.ts added: src/plugins/channel1-channel2-processor/channel1-channel2-controller.ts added: src/plugins/channel1-channel2-processor/channel1-to-channel2-converter.ts added: src/plugins/channel1-channel2-processor/error-to-channel2-api-converter.ts added: src/plugins/channel1-channel2-processor/channel1-channel2-flow.ts added: src/plugins/channel1-channel2-processor/index.ts added: src/plugins/channel1-channel2-processor/package.json added: src/plugins/channel1-channel2-processor/channel1-channel2-destination-channel2-response-error.ts added: src/plugins/channel1-channel2-processor/channel1-channel2-utils.ts
Add a new swagger
-
Add a swagger inside your plugin in the path:
src/plugins/channel1-channel2-processor/swagger.yamlopenapi: 3.0.0 info: title: administration api to aura bridge description: Set of endpoints related to bridge administration version: 1.0.0 tags: - name: admin description: Bridge administration plugin servers: - url: 'http://localhost:8045' description: Local server - url: 'https://svc-ap-current.auracognitive.com' description: ap-current paths: /aura-services/v1/testing/channel1: # include the path to the new plugin get: tags: - testing-channe1 description: channel1 testing. operationId: getChannel1Messages # controller function name. x-router-controller: plugins # in path src/controllers/plugins.ts responses: '200': description: OK headers: { } '500': description: An internal server error has occurred.
Add a new function controller
-
Add all the controllers in the path: src/controllers/plugins.ts
import Channel1Channel2Message from '../plugins/channel1-channel2-processor/channel1-channel2-controller'; export function getChannel1Messages(req: express.Request, res: express.Response) { Channel1Channel2Message.controller(req, res); }
Plugin activation in Aura bridge
Every plugin to be loaded in aura-bridge must be defined in the plugin-config.json file.
⚠️ If this plugin has dependence with other plugins, they must also be added to the plugins list. If during the aura-bridge boot a plugin has a dependency with another not installed plugin, the bridge will fail in the boot process and will log an error indicating the lost dependency.
- Add the plugin to the configuration file
plugin-config.json(located at the root of the aura-bridge project):
[
...
"./lib/plugins/channel1-channel2-processor",
...
]
Activate a new plugin during development
To activate a new plugin during development, it is only necessary to add the plugin path in the plugin-config.json file:
[
"./lib/plugins/directline-service",
"./lib/plugins/directline-whatsapp-processor",
"./lib/plugins/whatsapp-incoming-processor",
"./lib/plugins/whatsapp-service",
// New plugin location here.
]
⚠️ take into account the dependencies with other plugins, as explained in the previous section.
Activate a new plugin for production
To add a new plugin in production, it is necessary to define the list of plugins using the plugin-config.json key in the aura-bridge ConfigMap for deployment in Kubernetes.
Example of aura-bridge ConfigMap using a configuration file:
apiVersion: v1
kind: ConfigMap
metadata:
name: aura-bridge
labels:
app: aura-bridge
stack: service
namespace: {{ kubernetes_core_namespace }}
data:
plugin-config.json: |
{{ lookup('file','<FOLDER_PATH>/plugin-config.json',convert_data=False) | indent(4,indentfirst=False) }}
Plugin removal in Aura bridge
To remove a plugin, it is only necessary to delete the plugin path in the plugin-config.json file.
⚠️ In order to eliminate a plugin correctly, it is necessary to verify that no other plugins from those installed depends on the one we want to eliminate.