# Alter user message text

**URL:** <https://forum.rasa.com/t/alter-user-message-text/26308>\
**Category:** Rasa Open Source\
**Created:** [March 19, 2020, 8:54am UTC](https://forum.rasa.com/t/alter-user-message-text/26308 "2020-03-19T08:54:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexandru-Pirvu](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/alexandru-pirvu/32/7851_2.png) [@Alexandru-Pirvu](https://forum.rasa.com/u/Alexandru-Pirvu)\
**Post date:** [March 19, 2020, 8:54am UTC](https://forum.rasa.com/t/alter-user-message-text/26308/1 "2020-03-19T08:54:24Z")

</div>

Hello!

I have an issue finding the best spot to intervene in the rasa flow. My use case is that I want to alter the user’s message text in a specific case, more exactly, when a certain entity is found. At first, it seemed that the logical place to do that was in a custom nlu component. And indeed, that’s where one add information for future processing in the nlu pipeline. But as it turns out, the only thing that cannot be changed is the text of the message, and I think it is because of this line: [rasa/processor.py at f3a3fb7ab391482da5ae7f6f789f0a8c7d600f8b · RasaHQ/rasa · GitHub](https://github.com/RasaHQ/rasa/blob/f3a3fb7ab391482da5ae7f6f789f0a8c7d600f8b/rasa/core/processor.py#L458) if it would be `parse_data.text`, the situation would’ve been resolved Also, the log following also adds the received text instead of the changed one.

Dummy example:

user says `hi`

nluComponent does `if message.text == hi: message.text = "Hello" `

This being the situation, I have some open questions:

1. Is it intended that you cannot change by all means the user text at this level?
2. Is there a better place to alter user input? It can be done in a custom policy, but it really feels wierd to alter the tracker.
3. Is there a way to implement a custom tracker? (maybe if there is no other evident solution, this would be a better workaround)

PS: This is a very specific use case and the example is just to prove the technical situation, not the functional one.

---

<div class="post-metadata">

**Author:** ![saurabh-m523](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/saurabh-m523/32/7887_2.png) [@saurabh-m523](https://forum.rasa.com/u/saurabh-m523)\
**Post date:** [March 19, 2020, 12:05pm UTC](https://forum.rasa.com/t/alter-user-message-text/26308/2 "2020-03-19T12:05:35Z")

</div>

If you want the bot to extract the entity first and then based on the entity extracted, alter the text then I guess a custom component would be the best option.

But if you know the exact entity value before hand and just want to alter the user text if this entity value is present, then you can have a custom implementation of the channel you are using and intercept the incoming message before sending it to rasa nlu.

---

<div class="post-metadata">

**Author:** ![Alexandru-Pirvu](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/alexandru-pirvu/32/7851_2.png) [@Alexandru-Pirvu](https://forum.rasa.com/u/Alexandru-Pirvu)\
**Post date:** [March 19, 2020, 12:15pm UTC](https://forum.rasa.com/t/alter-user-message-text/26308/3 "2020-03-19T12:15:36Z")

</div>

[saurabh-m523](http://forum.rasa.com/u/saurabh-m523) My case falls into the first situation you described. That was also my first bet, but it seems you cannot change the text in the custom nlu component.

You can change the text property of the received **message: Message** parameter, but that’s not going to alter what is saved in the tracker/tracker store… The only way I found so far was to alter the tracker in a custom policy, but it is weird, as the policies should just predict next actions, not alter nlu output…

---

<div class="post-metadata">

**Author:** ![saurabh-m523](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/saurabh-m523/32/7887_2.png) [@saurabh-m523](https://forum.rasa.com/u/saurabh-m523)\
**Post date:** [April 15, 2020, 4:10am UTC](https://forum.rasa.com/t/alter-user-message-text/26308/4 "2020-04-15T04:10:04Z")

</div>

Hi @Alexandru-Pirvu!

Did you manage solve it? If so could you please let me know how?

---

<div class="post-metadata">

**Author:** ![saurabh-m523](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/saurabh-m523/32/7887_2.png) [@saurabh-m523](https://forum.rasa.com/u/saurabh-m523)\
**Post date:** [April 15, 2020, 4:19am UTC](https://forum.rasa.com/t/alter-user-message-text/26308/5 "2020-04-15T04:19:14Z")

</div>

Also, please help me with the questions in the [initial post](http://forum.rasa.com/t/alter-user-message-text/26308)?

Actually I also need this and I would love to open a PR for it if this behavior is not intentional. @Juste

---

<div class="post-metadata">

**Author:** ![faupotron](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/faupotron/32/20302_2.png) [@faupotron](https://forum.rasa.com/u/faupotron)\
**Post date:** [April 19, 2022, 12:50pm UTC](https://forum.rasa.com/t/alter-user-message-text/26308/6 "2022-04-19T12:50:16Z")

</div>

Hi, @saurabh-m523. Do you know how to intercept and change the incoming message before sending it to rasa nlu.

---

<div class="post-metadata">

**Author:** ![itsjhonny](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/itsjhonny/32/20201_2.png) [@itsjhonny](https://forum.rasa.com/u/itsjhonny)\
**Post date:** [April 19, 2022, 1:14pm UTC](https://forum.rasa.com/t/alter-user-message-text/26308/7 "2022-04-19T13:14:05Z")

</div>

Hi! 😃

You have two ways to do it. Make the change in frontend, when the user click “send” and frontend make post to rasa or…

Build a custom channel to do it

Look my `custom_channel.py` i think it will help you 😃

> [@Enforce authentication on 1st question](http://forum.rasa.com/t/enforce-authentication-on-1st-question/52549/6):
>
> Hi @v_kostis smileyIn my testes, I think isn’t possible to make authentication system using custom actions action\_listen and action\_session\_start is cool but, don’t stop any menssagens So, we have the way build using condition for every story and an front-end solution But, I think found a nice way build an [Custom Connectors](https://rasa.com/docs/rasa/connectors/custom-connectors/) btw, the official docs are outdated My custom connector check slot is\_auth if false and not allowed intent, the user text changed to ‘/please\_make\_login’ Ex: user i…

This is how i get user message

```auto
text = request.json.get("text") 

```

references:

- [https://github.com/RasaHQ/rasa/tree/main/rasa/core/channels](https://github.com/RasaHQ/rasa/tree/main/rasa/core/channels)
- [Custom Connectors](https://rasa.com/docs/rasa/connectors/custom-connectors/)
