Get None when trying to get the message inside custom component

I am trying to access the message text inside the process method of custom extraction component, but it returns None.

def process(self, message: Message, **kwargs: Any) -> None:
        """Process an incoming message.

        This is the components chance to process an incoming
        message. The component can rely on
        any context attribute to be present, that gets created
        by a call to :meth:`components.Component.pipeline_init`
        of ANY component and
        on any context attributes created by a call to
        :meth:`components.Component.process`
        of components previous to this one."""

  
        print("Text")
        print(message.get(Text))
        print(message.get('text'))
        print(message.get(TEXT))
        print(message.get("text"))

All prints show None when using rasa train or rasa shell Anyone can help me with this ?

rasa --version

Rasa Version      :         2.8.8
Minimum Compatible Version: 2.8.0
Rasa SDK Version  :         2.8.2
Rasa X Version    :         None
Python Version    :         3.8.10
Operating System  :         Linux-5.10.0-1051-oem-x86_64-with-glibc2.29
Python Path       :         /home/lenovo/Desktop/Barham/Custom_components/custom_com_env/bin/python

Thanks in advance

Does it work if you do print(message.get('tokens'))?

If not, can you show me the output of print(message)?

If yes, please try:

tokens = message.get('tokens')
text = [token.text for token in tokens]
text = ' '.join(text)
print(text)

No, it doesn’t work. The output is None.

Can you show me the output of print(message) ?

<rasa.shared.nlu.training_data.message.Message object at 0x7f729c475fa0>

Thanks, that’s what I was looking for, to check the source code.

Now can you show me print(self.data)?

It give an error if I put it the print inside the process method.

self.data
Traceback (most recent call last):
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/bin/rasa", line 8, in <module>
    sys.exit(main())
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/__main__.py", line 117, in main
    cmdline_arguments.func(cmdline_arguments)
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/cli/train.py", line 59, in <lambda>
    train_parser.set_defaults(func=lambda args: run_training(args, can_exit=True))
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/cli/train.py", line 91, in run_training
    training_result = train_all(
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/api.py", line 109, in train
    return rasa.utils.common.run_in_loop(
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/utils/common.py", line 296, in run_in_loop
    result = loop.run_until_complete(f)
  File "uvloop/loop.pyx", line 1456, in uvloop.loop.Loop.run_until_complete
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/model_training.py", line 108, in train_async
    return await _train_async_internal(
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/model_training.py", line 288, in _train_async_internal
    await _do_training(
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/model_training.py", line 352, in _do_training
    await _train_core_with_validated_data(
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/model_training.py", line 549, in _train_core_with_validated_data
    await rasa.core.train.train(
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/core/train.py", line 70, in train
    agent.train(training_data, **additional_arguments)
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/core/agent.py", line 753, in train
    self.policy_ensemble.train(
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/core/policies/ensemble.py", line 206, in train
    policy.train(
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/core/policies/ted_policy.py", line 692, in train
    model_data, label_ids = self._prepare_for_training(
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/core/policies/ted_policy.py", line 586, in _prepare_for_training
    tracker_state_features, label_ids, entity_tags = self._featurize_for_training(
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/core/policies/policy.py", line 191, in _featurize_for_training
    state_features, label_ids, entity_tags = self.featurizer.featurize_trackers(
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/core/featurizers/tracker_featurizers.py", line 382, in featurize_trackers
    tracker_state_features = self._featurize_states(trackers_as_states, interpreter)
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/core/featurizers/tracker_featurizers.py", line 103, in _featurize_states
    return [
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/core/featurizers/tracker_featurizers.py", line 104, in <listcomp>
    [
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/core/featurizers/tracker_featurizers.py", line 105, in <listcomp>
    self.state_featurizer.encode_state(state, interpreter)
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/core/featurizers/single_state_featurizer.py", line 281, in encode_state
    self._extract_state_features(sub_state, interpreter, sparse=True)
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/core/featurizers/single_state_featurizer.py", line 249, in _extract_state_features
    parsed_message = interpreter.featurize_message(message)
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/core/interpreter.py", line 159, in featurize_message
    result = self.interpreter.featurize_message(message)
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/nlu/model.py", line 491, in featurize_message
    component.process(message, **self.context)
  File "/home/lenovo/Desktop/Barham/Custom_components/custom_com_env/lib/python3.8/site-packages/rasa/nlu/extractors/custom_extractors.py", line 97, in process
    print(self.data)
AttributeError: 'maha' object has no attribute 'data'

Hmm… Can you show the full code for your component please?

Thanks, it works for me. I changed the parent class of inheritance from Component to EntityExtractor and everything “until now” works fine.