Example Component
Here's a how a full example of a component that sends SMS via the Twilio service can look like:

Directory Structure
Component Behaviour (sms/SendSMS/SendSMS.js)
Defines how the component reacts on incoming messages.
Component Manifest (sms/SendSMS/component.js)
Defines the component properties and metadata.
Component Dependencies (sms/SendSMS/package.json)
Our component uses the twilio NodeJS library. Therefore, we need to list it as a dependency.
Service Manifest (service.json)
Metadata about the Twilio service. The Appmixer UI uses this information to display the Twilio app in the Apps panel of the Designer UI.
Service Authentication Module (auth.js)
Defines the authentication for the Twilio service. This information is used both for rendering the Authentication dialog (displayed when the user clicks on "Connect New Account" button in the Designer UI inspector) and also for the actual authentication to the Twilio API and validation of the tokens.
Service Authentication Module Dependencies (package.json)
Our auth.js module uses the twilio NodeJS library. Therefore, we need to list it as a dependency.
Helper Component (sms/ListFromNumbers/ListFromNumbers.js)
This is a helper component that is used to list the phone numbers registered in the user's Twilio account. You can see that this component is called in the "static" mode in the SendSMS component manifest. Note that this component is not used out of necessity but more as a convenience for the user. Thanks to this component, the user can just select a phone number from a list of all their registered phone numbers in the Designer UI inspector. An alternative would be to let the user enter the phone number in a text field. However, that might result in errors to the API calls to Twilio if the phone number does not exist in the user's list of registered phone numbers in their Twilio account.

Helper Component Manifest (sms/ListFromNumbers/component.json)
Note the component is marked as "private" meaning that it will not be available in the Designer UI as a standalone component.
Helper Component Dependencies (sms/ListFromNumbers/package.json)
Helper Component Transfomer (sms/ListFromNumbers/transformers.js)
The numbers output port of our helper component returns a list of numbers. However, when the component is called in a static mode from our SendSMS component Inspector UI, the expected value is a list of objects with label and value properties so that it can be rendered by the UI. Alternatively, we could have just skip the transformer altogether and use this array structure right in our context.sendJson() call in our ListFromNumbers.js file. The advantage of using transformers is that we can use the ListFromNumbers component as a regular component (i.e. not private) and so allow the user to put the component in their flows. In other words, the same component can be used for static calls (to show a list of available phone numbers in the Inspector UI of the SendSMS component) as well as in a normal mode (as a regular component that can be put in a flow).
Last updated
Was this helpful?
