# Overwrite user message (custom component)

**URL:** <https://forum.rasa.com/t/overwrite-user-message-custom-component/42633>\
**Category:** Rasa Open Source\
**Created:** [April 20, 2021, 8:41am UTC](https://forum.rasa.com/t/overwrite-user-message-custom-component/42633 "2021-04-20T08:41:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rosodelu](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@rosodelu](https://forum.rasa.com/u/rosodelu)\
**Post date:** [April 20, 2021, 8:41am UTC](https://forum.rasa.com/t/overwrite-user-message-custom-component/42633/1 "2021-04-20T08:41:47Z")

</div>

Hello!

I am trying to create a custom component, which overwrite the user input message. I am working on rasa version 2.3.4. I have read the documentation, the forum discussions, and have considered the different suggestions, but I can’t get it to work!

Your input → Hee llo!!! my name is: DÁÑIEL, 35=YEARS old! someone on the other side?? rasa.core.processor - Received user message ‘Hee llo!!! my name is: DÁÑIEL, 35=YEARS old! someone on the other side??’

My custom component not overwrite the user input message.

my config.yml looks like this:

language: es

pipeline:

- name: edit\_message.Preprocessor
- name: SpacyNLP
  - model: es\_core\_news\_sm

and my custom component: import typing

from typing import Any, Optional, Text, Dict, List, Type

import re

import unidecode

from rasa.nlu.components import Component

from rasa.nlu.config import RasaNLUModelConfig

from rasa.shared.nlu.training\_data.training\_data import TrainingData

from rasa.shared.nlu.training\_data.message import Message

if typing.TYPE\_CHECKING:

```
from rasa.nlu.model import Metadata

```

class edit\_message(Component):

```
provides = ["text"]

#requires = []

defaults = {}

language_list = None

def __init__ (self, component_config=None):

    super(edit_message, self). __init__ (component_config)

def train(self, training_data, cfg, **kwargs):

    pass

def process(self, message: Message, **kwargs: Any) -> None:

    mt = message.get("text")

    if mt!=None:

        mt = unidecode.unidecode(mt)

        mt = mt.lower()  

        mt = re.sub(r'(\!)', " ! ", mt)

        mt = re.sub(r'(\:)', " : ", mt)

        mt = re.sub('=', ' = ', mt)

        mt = re.sub(r'(\?)', " ? ", mt)

        mt = re.sub(r'\s{2,}', ' ', mt)

        message.set('text', mt, add_to_output = True)

    pass

```

Can anybody help me?

---

<div class="post-metadata">

**Author:** ![jjuzl](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@jjuzl](https://forum.rasa.com/u/jjuzl)\
**Post date:** [April 27, 2021, 11:18am UTC](https://forum.rasa.com/t/overwrite-user-message-custom-component/42633/2 "2021-04-27T11:18:58Z")

</div>

Hi @rosodelu

What exactly is the component doing? Do you see any errors in the logs. Also, if you formated your post better it would be easier to help.

---

<div class="post-metadata">

**Author:** ![rosodelu](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@rosodelu](https://forum.rasa.com/u/rosodelu)\
**Post date:** [April 28, 2021, 12:52pm UTC](https://forum.rasa.com/t/overwrite-user-message-custom-component/42633/3 "2021-04-28T12:52:32Z")

</div>

I want to add a custom component, to replace certain characters. In order to improve the recognition of entities separated by these.

Example user input message:

He llooo! my name is: Dáñiel! 15=years old

It would be overwritten as:

he lloo ! my name is : daniel ! 15 = years old

Then I could put as an example of training data:

he lloo ! my name is : [daniel](name) ! [15](years) = years old

I’ve been trying to change this line:

message.set (‘text’, mt, add\_to\_output = True)

to

message.set (‘text’, ‘hello’, add\_to\_output = True)

and now i am sure my component is working, and is working as i want, as in that case all input messages will be overwritten as hello.

Thanks @jjuzl !!

---

<div class="post-metadata">

**Author:** ![Mazyod](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/mazyod/32/10904_2.png) [@Mazyod](https://forum.rasa.com/u/Mazyod)\
**Post date:** [May 5, 2021, 12:09pm UTC](https://forum.rasa.com/t/overwrite-user-message-custom-component/42633/4 "2021-05-05T12:09:54Z")

</div>

Thanks for sharing your solution. I’ve been wondering whether it was safe or not to override the TEXT key in message. Seems like it’s safe.

---

<div class="post-metadata">

**Author:** ![HarshMagiya7](https://avatars.discourse-cdn.com/v4/letter/h/e47774/32.png) [@HarshMagiya7](https://forum.rasa.com/u/HarshMagiya7)\
**Post date:** [January 31, 2022, 2:27pm UTC](https://forum.rasa.com/t/overwrite-user-message-custom-component/42633/5 "2022-01-31T14:27:51Z")

</div>

Hey I am trying to achieve similar thing But what happens is my bot doesnt give a reply back I am not sure what mistake i am doing What should i do Also the message.set,.get where is this documentation

---

<div class="post-metadata">

**Author:** ![rosodelu](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@rosodelu](https://forum.rasa.com/u/rosodelu)\
**Post date:** [January 31, 2022, 2:57pm UTC](https://forum.rasa.com/t/overwrite-user-message-custom-component/42633/6 "2022-01-31T14:57:20Z")

</div>

> [@HarshMagiya7](#):
>
> Hey I am trying to achieve similar thing But what happens is my bot doesnt give a reply back I am not sure what mistake i am doing What should i do Also the message.set,.get where is this documentation

Maybe it’s because of the version you’re using. For me it works in the version of RASA 2.8.13.

---

<div class="post-metadata">

**Author:** ![HarshMagiya7](https://avatars.discourse-cdn.com/v4/letter/h/e47774/32.png) [@HarshMagiya7](https://forum.rasa.com/u/HarshMagiya7)\
**Post date:** [January 31, 2022, 2:59pm UTC](https://forum.rasa.com/t/overwrite-user-message-custom-component/42633/7 "2022-01-31T14:59:27Z")

</div>

So you mean to say that rasa custom components doesnt work in rasa 2.1.2?

---

<div class="post-metadata">

**Author:** ![rosodelu](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@rosodelu](https://forum.rasa.com/u/rosodelu)\
**Post date:** [January 31, 2022, 3:04pm UTC](https://forum.rasa.com/t/overwrite-user-message-custom-component/42633/8 "2022-01-31T15:04:35Z")

</div>

No, what I mean is that the way to get the message text in another version MAY BE slightly different. Have you checked the documentation for the version you’re using?

---

<div class="post-metadata">

**Author:** ![HarshMagiya7](https://avatars.discourse-cdn.com/v4/letter/h/e47774/32.png) [@HarshMagiya7](https://forum.rasa.com/u/HarshMagiya7)\
**Post date:** [January 31, 2022, 3:08pm UTC](https://forum.rasa.com/t/overwrite-user-message-custom-component/42633/9 "2022-01-31T15:08:38Z")

</div>

Hey So i couldnt find the documentation for message.set or like that I checked the custom aomponents category and there is no mention of how to get the message
