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}.