Custom Component: HelloAppmixer
Last updated
Last updated
At this point, you have your Appmixer system up and running and you know how to create and start a flow. Now it's time to guide you through the process of implementing your own, custom component. In our tutorial, we implement a component that has one input and one output port, consumes messages on its input port, sends an HTTP request to an external API for each incoming message and outputs the response to the output port for other connected components to ingest.
Our component will live in a namespace "appmixer.myservice.mymodule.HelloAppmixer". All components in Appmixer are organized in the hierarchy [vendor].[service].[module].[component].
We prepared the HelloAppmixer component from this tutorial for you. You can download it from here:
You can just download the component and publish it with:
If you prefer to go step by step instead (which we recommend), create the following files and the required directories:
myservice/mymodule/HelloAppmixer/HelloAppmixer.js
, component source code file
myservice/mymodule/HelloAppmixer/component.json
, component manifest file
myservice/service.json
, service manifest file
The resulting directory structure should look like this:
Now let's fill up the files with the minimum content necessary for the engine to consider this as a valid component.
This file exports a plain NodeJS module. Normally, this module exports virtual methods that the Appmixer engine understands (the most important one is the receive()
). For now, we just leave the module empty. It's enough to create bare minimum for the engine to be able to work with our component.
The component manifest file defines properties of our component (such as name, icon, input/output ports, ....). For now, we just fill in the only required field, the name
and the optional but useful icon
. It's important to note that the name
must be a fully qualified namespace or our component:
The service manifest defines properties of our app as it appears in the left palette in the Designer UI.
Now you can pack and publish your component using the Appmixer CLI tool. When you then refresh the Designer page in your browser, you should see a new app in the left pane:
Now let's make our component actually do something. First, we start with extending the component manifest file (component.json
) by adding an input port so that we can connect our component to other components:
This is enough to define an input port with no restrictions. However, we would like to add two properties (text
and count
) that we can count on in our component behaviour and that we can assume are always defined (i.e. marked as required in the Designer UI). Moreover, we will also define the Inspector UI for both our properties so that the user can fill them in in the Designer UI.
When you now republish your component, refresh the Designer page and connect our component to another component, you should see both our properties in the Inspector:
Note that we're using the Controls/OnStart component in our flow below. This utility component is useful especially during development of your custom components as the only thing it does is that it triggers/fires as soon as we start our flow.
Note that at this point, our component will still not work. If you try to run this flow, you will notice errors coming from the engine in the Insights/Logs page (click on the triple dot and then go to Insights):
This is because we have defined an input port on our component but did not yet implement the receive()
method.
In this section, we will show how to extend our component to be able to receive messages, call an external API and send the result to the output port so that other connected components can work with the data. Let's now again extend the component manifest file (component.json
) by adding an output port:
Our component behaviour will also change. We will call an external HTTP endpoint and pass the result to our output port. For a convenience, we will use a NodeJS library Axios to send HTTP requests. Before we can start using the library, we have to install it first. This can simply be done by creating a package.json
file with the Node package manager and installing our library:
Now we can use the library in our component module (HelloAppmixer.js
):
Notice the context.messages
object that is a dictionary with keys pointing to input ports and values containing the content
property that gives us a dictionary with all our properties that we defined on the input port.
Now we can republish our component again and create a flow like this:
When you run this flow, you should see a new tweet in your Twitter account that looks something like this:
You can also check the Insights page for this flow to see the logs:
In this tutorial, we demonstrated how you can create a custom component that processes incoming messages, calls an external HTTP API and sends outgoing messages for other connected components to consume. We used simple example flows with the OnStart component as a trigger. However, instead of our OnStart trigger component, we could have used other triggers, such as schedulers, polling components (e.g. the included PipeDrive.NewPerson trigger that checks for new contacts in the Pipedrive CRM), webhooks and more. We suggest to browse the online documentation to learn more about all the features of Appmixer and how you can apply them in your custom components.