Message object does not recognize text attribute in Custom Component for RASA 2.0

Hey,

Currently I am migrating to RASA 2.0 but my custom components are not working anymore. When I try to train the core model it gives me an AttributeError saying:

‘Message’ object has no attribute ‘text’.

My code looks as follows:

    def process(self, message, **kwargs):
    message.text = message.text.translate(message.text.maketrans('', '', '!?$%&(){}^'))

Can someone explain to me why it was working before but it is not working anymore with the newest version of RASA?

Kind regards,

Fabrice

Apparently the Message object has changed whereas the “text” is available in the data dict attribute of the Message object.

Hi @fabrice-toussaint. If I understand correctly, you were able to resolve your own issue?

Yes but the documentation for custom components for Rasa 2.0 is currently not adjusted properly. Also, the tutorial will not reflect a real scenario anymore. I believe this should be updated. :slight_smile:

@fabrice-toussaint Thanks for letting me know. Do you mean these docs? Also, what tutorial are you referencing?

No problem @tyd! Yes I mean those docs and I am referring to the tutorial mentioned in the docs under custom components. For me it was not clear how the Message object changed from RASA 1.X to RASA 2.0.

Hey @fabrice-toussaint, just to clarify, the docs themselves are updated, it’s just the tutorial that is out of date? In that case, we’ll take reference to the tutorial out of the docs, until it’s updated again.

Hey @akelad, yes the docs are updated but missing information about the updated Message object (which I think might come in handy). However, this could also be deducted from an updated tutorial (or diving into the code). :smiley:

I think the Message object stuff is probably covered somewhere in the changelog :sweat_smile: i’ll update the docs to remove the reference to the blog post for now, and eventually we’ll make sure to update it

1 Like

I am facing the same error “AttributeError: ‘Message’ object has no attribute ‘text’”. It was not an issue earlier and occurred without any changes to the code created. Please help to fix this issue.

@sreerajm for me it was resolved as follows:

    try:
        message.data['text']
    except KeyError:
        pass

The text now is in a dictionary attribute of the Message object called data. However, you also need to catch a KeyError (at least in my case) as when starting this key does not exist. I am not sure whether this is the best way to do this but it works for me.

3 Likes

@fabrice-toussaint, thanks for the reply. I am getting the key error now.

hi @sreerajm can you tell how did you do?

@fabrice-toussaint I changed message.text by message message.data[‘text’] and this is the error

  File "E:\act\sentiment.py", line 44, in process
    res = sid.polarity_scores(message.data['text'])
KeyError: 'text'