Consult pokeapi, cant capture the pokemon correctly

Hi.

I’m starting with rasa, for the moment, I want to make a telegram bot in which I can ask the pokedex number of a pokemon, and have it answer me.

The problem is that it only consults the pokemons that are defined in my nlu.yml, if I ask about another pokemon, it tells me that it could not find information about None. The request to the API is made but it passes None as a parameter, it is not capturing the entity correctly.

Would I have to define all the pokemons in the nlu.yml? I don’t think so, it wouldn’t be optimal at all. Can someone help me configure it so that it is whatever pokemon it is, the request to the API is made correctly?

This is my nlu.yml:

- intent: ask_pokedex_num
  examples: |
    - What pokedex number is [charizard](pokemon)
    - I want to know [snorlax](pokemon)'s pokedex number
    - Tell me [pikachu](pokemon)'s pokedex number'
    - [ditto](pokemon)'s pokedex number'
  

actions.py:

class ActionGetPokedexNumber(Action):
    def name(self):
        return "action_get_pokedex_number"

    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        
        #pokemon = tracker.get_slot("pokemon")
        
        pokemon = next(tracker.get_latest_entity_values("pokemon"), None)
        api_url = f"https://pokeapi.co/api/v2/pokemon/{pokemon}"
        response = requests.get(api_url)

        if response.status_code == 200:
            data = response.json()
            pokedex_number = data.get("id")
            response_message = f"{pokemon}'s pokedex number is {pokedex_number}."
        else:
            response_message = f"I couldn't find information about {pokemon} in the pokedex"

        dispatcher.utter_message(response_message)

        #return [SlotSet("pokemon", pokemon)]
        return []

config.yml:

pipeline:
  - name: WhitespaceTokenizer
  - name: RegexFeaturizer
  - name: LexicalSyntacticFeaturizer
  - name: CountVectorsFeaturizer
  - name: CountVectorsFeaturizer
    analyzer: "char_wb"
    min_ngram: 1
    max_ngram: 4
  - name: DIETClassifier
    epochs: 200

Thanks.

I assume there is a limited set of pokemon’s that don’t change too often?

Would I have to define all the pokemons in the nlu.yml?

Yes, I would do this. You can automate this if names are added periodically and generate the examples.

In the api there are 1292 pokemons to consult their data. So, in case I want to consult information about any of those pokemons, would I have to add them all to the nlu.yml manually?

What do you mean by adding names periodically and generating examples automatically?

Isn’t there a way to make rasa detect that I have introduced a pokemon that is not in my nlu.yml and query the api?

I would consider automating the export of the pokemon list from your api and creating an nlu.yml with the examples. You can run this periodically or trigger an update when changes are made in the db.