Configuration

Sometimes you need to configure your module and have a different configuration for different environments. QA vs Production for example.

You can use the Backoffice to set the configuration key/values:

The key to the Backoffice Service Configuration depends on the component.json. If it is a component with auth section, then the key is the service. Let's take a Slack component.json for example:

{
    "name": "appmixer.slack.list.NewChannelMessageRT",
    "description": "As opposed to NewChannelMessage and NewPrivateChannelMessage this trigger fires immediately every time a message is posted to a channel. Works both for public and private channels.",
    "webhook": true,
    "auth": {
        "service": "appmixer:slack",  // appmixer:slack will be used as a 'key'
        "scope": [
            "channels:read",
            "channels:history"
        ]
    },
    "outPorts": [
    ...
}

In this case, the appmixer:slack will be used as a key into the Backoffice. Then you can store various key/value pairs in the Service Configuration:

A good example is the clientID and clientSecret. Slack is an Oauth2 application and it needs a different Oauth application for each environment (due to the redirect URL). All of these values will be available in the component's context object (and in the context object in the auth.js file as well).

module.exports = {

    async tick(context) {
    
        context.auth.clientId;
        context.auth.clientSecret;
        context.auth.orAnythingElse;
        
        // all of those will be available at context.config as well
        context.config.clientId;
        context.config.clientSecret;
        context.config.orAnythingElse;        
    }
}

If your component/module does not use user authentication (no auth section in the component.json file), then the key to the Backoffice Service Configuration depends on the name of the component. Here's an example.

// component.json file without "auth" section
{
    // the property "name" will be used to look for configuration stored through
    // the Backoffice. Appmixer will try to look for a key [vendor]:[service] and
    // [vendor]:[service]:[module]
    "name": "appmixer.utils.tasks.RequestApprovalEmail",
    "description": "People Task is a feature of Appmixer that allows human interaction inside workflows.",
    "webhook": true,
    "inPorts": [
        {
   ...
}

For such component/module you can store configuration under appmixer:utils or under appmixer:utils:tasks. Such key/value configuration pairs will be then available under context.config.

Last updated