Add Dynamic Configs

Power dynamic configs for “Pokémon of the Day” by adding an initSync flow that outputs Slack user and Pokémon type options to stdout, 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 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:

  1. 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 
  ├── .env
  ├── package.json
  ├── PANDIUM.yaml
  └── tsconfig.json
  1. Within src/processLogic/initSync.ts add the shell of an asynchronous initSync function.

  1. Within src/index.ts import initSync and invoke it within the run function when the run mode is init.

The src/index.ts should look something like this:

  1. In the .env update the run mode:

  1. Run npm run build && npm run start.

You should see the following logged, which shows that initSync is running:

  1. Fetch the Slack users by doing the following:

The initSync.ts file should look something like this:

  1. Run npm run build && npm run start.

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 options printed to the initSync standard out for your slack_user config should only have 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.

  1. Create a Typescript interface for OneOfOption.

  1. Print the slack user options to the standard out.

The initSync.ts should now look like this:

  1. Run npm run build && npm run start. 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!

  1. Fetch the Pokémon types by doing the following:

The initSync.ts file should look something like this:

  1. Run npm run build && npm run start. You should see the same information logged as before - except that there should now also be an array of Pokémon types. This confirms the PokeClient within initSync is working.

  2. Loop through each of the Pokémon types list and add its name to a list of pokemonTypes. Then add the pokemon_types to the standard out object returned by initSync.

  3. Run npm run build && npm run start. The logs should look something like this:

    The standard out of the initSync now lists options for both the slack_user and pokemon_type configs.

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?