Within src/index.ts import pokemonSync and invoke it within the run function when the run mode is normal.
The src/index.ts should now look something like this:
import * as dotenv from 'dotenv'
dotenv.config()
import { WebClient } from '@slack/web-api'
import Pokedex from 'pokedex-promise-v2'
import { Config, Secret, Context } from './lib.js'
import { pokemonSync } from './processLogic/pokemonSync.js'
const run = async () => {
const context = new Context()
const secrets = new Secret()
const config = new Config()
console.error(`This run is in mode: ${context['run_mode']}`)
console.error('------------------------CONFIG------------------------')
console.error(config)
console.error('------------------------CONTEXT------------------------')
console.error(context)
const pokeClient = new Pokedex()
const slackClient = new WebClient(secrets.slack_token)
if (context.run_mode === 'normal') {
await pokemonSync()
}
}
run().then(
() => {},
() => {
process.exitCode = 1
}
)
Run npm run build && npm run start, and you should see the following logged:
> pokemon-of-the-day@1.0.0 start
> node build/src/
This run is in mode: normal
------------------------CONFIG------------------------
Config {}
------------------------CONTEXT------------------------
Context { run_mode: 'normal' }
------------------------POKEMON SYNC------------------------
Fetch a Pokémon by doing the following:
The pokemonSync.ts file should look something like this:
You should see the same information logged as before - except that now a large Pokémon object has also been printed. This confirms the Pokémon client within pokemonSync is working, so you can remove the console.error(pokemonOfTheDay).
Add a function to transform the pokemonOfTheDay into a Slack message.
Run npm run build && npm run start. You should get a Slack message about the Pokémon of the Day!
We're not quite done though. If you try running npm run start again you will get another Slack message about the same Pokémon. One of the Academy's requests is that we won't repeat Pokémon.
To accomplish this goal, we will use context to learn which Pokémon have already been used.
Alter the integration so that it prints a standard out during a normal sync.
Run npm run build && npm run start.
You should get another slack message about that same Pokémon. However the logs now include the standard out, which should look something like this {"last_pokemon_id":247}.
Run npm run build && npm run start. You should get another Slack message about a new Pokémon!
The logs should look like this:
> pokemon-of-the-day@1.0.0 start
> node build/src/
This run is in mode: normal
------------------------CONFIG------------------------
Config {}
------------------------CONTEXT------------------------
Context {
run_mode: 'normal',
last_successful_run_std_out: '{"last_pokemon_id":247}'
}
------------------------POKEMON SYNC------------------------
{"last_pokemon_id":248}
Notice the following about the logs:
The context now has a the last run's standard out.
The ID printed to the standard out for this run is greater than the ID from the last run's standard out.
The final step is to see what this all looks like when it is run on Pandium!
Last updated
Was this helpful?
Pass nextPokemonId to the pokeClient.getPokemonByNamemethod to fetch a Pokémon by ID, because state "Any function with the designation 'ByName' can also be passed an integer ID."
Review for the postMessage endpoint and the Pokemon Typescript interface to fill out the pokemonToSlackMessage transformation function.
Pandium stores the of each tenant's last successful normal sync, so it can be accessed as an during the next run.
Your pokemonSync.ts should loook like the one . In fact, all your integration files should match all the ones in .