Add Dynamic Configs
Power dynamic configs for “Pokémon of the Day” by adding an initSync flow that saves Slack user and Pokémon type options to tenant metadata, populating tenant dropdowns automatically.
Your updated Connections Settings page has the new configs you need. Now we're going to write an init sync flow to populate options for each of those configs.
A Pandium integration can be run in normal mode or init mode. The initSync flow is for the init mode.
The goal in this initSync flow is to print a standard out with data that will be saved to the tenant's metadata and populate the options for our two dynamic configurations:
The Slack user to receive the Pokémon of the day message.
The type of Pokémon allowed for Pokémon of the day.
To do this we will need to:
Within src/processLogic add initSync.ts.
Now your file structure should now look like this:
├── build
├── node_modules
├── src
│ ├── processLogic
│ │ ├── initSync.ts
│ │ └── pokemonSync.ts
│ ├── index.ts
│ ├── lib.ts
│ └── transformations.ts
├── package.json
├── PANDIUM.yaml
└── tsconfig.jsonWithin src/processLogic/initSync.ts get a logger for the file and add the shell of an asynchronous
initSyncfunction.
Within src/index.ts import
initSyncand invoke it within themainfunction when the run mode is init.
The src/index.ts should look something like this:
The CLI runs your tenant in normal mode by default. To run in init mode, pass the --mode option.
Run
pandium local build && pandium local run <tenant-id> --mode init.
You should see the following logged, which shows that initSync is running:
Fetch the Slack users by doing the following:
The initSync.ts file should look something like this:
Run
pandium local build && pandium local run <tenant-id> --mode init.
You should see the same information logged as before - except that now an array of Slack members from your workspace has also been printed. This confirms the Slack client within initSync is working.
You may recall from the work on the PANDIUM.yaml that the slack_users metadata should be a list of objects with only the properties const and title. This means the elements of the Slack members array will need to be transformed to the proper const and title format.
Create a Typescript interface for
OneOfOption.
Print the slack user options to the standard out.
The initSync.ts should now look like this:
Run
pandium local build && pandium local run <tenant-id> --mode init. The logs should look something like this:
During the work on the PANDIUM.yaml this is exactly what we'd said needed to be printed to the init sync standard out to populate options for the slack_user config.
Now do the same for the Pokémon types!
Fetch the Pokémon types by doing the following:
The initSync.ts file should look something like this:
Run
pandium local build && pandium local run <tenant-id> --mode init. You should see the same information logged as before - except that there should now also be an array of Pokémon types. This confirms thePokeClientwithininitSyncis working.Loop through each of the Pokémon types list and add its name to a list of
pokemonTypes. Then add thepokemon_typesto the metadata object returned byinitSync.Run
pandium local build && pandium local run <tenant-id> --mode init. The logs should look something like this:The standard out of the
initSyncnow lists options for both theslack_userandpokemon_typeconfigs.
The initSync.ts should now look like this.
Let's take a look at how this standard out of this new init mode affects the options on the tenant setting page!
Last updated
Was this helpful?