Manipulating user output


I would like to add some manipulation to a user input to trigger a flow I have in the solution.


User: “What can you help me with?”
Bot: “I can help you with … and also buying your new shirt”
User: “Alright, I would like to buy a shirt!”
Bot: “What shirt mark would you prefer”
User: “Polo”

At this point I want to manipulate the user output instead of saying just “Polo” I would like it to say “I want to buy a polo shirt”. How do I do that, tried to add a script with ._setOutputText but that is manipulating bots output rather then users.

Also inside of the solution I have “I want to buy polo shirt”, “I want to buy gant shirt” etc etc flow which I want to access. That is why having a flow link is not of the choice.


Hello Stasysha. I think you mean you want to change the user input (not output) before checking triggers. You can certainly do that, but I’m not sure of your goal - in this use case, are you assuming a single word is always a reference to a shirt? Or are you trying to incorporate context, ie the context here is the user is interested in purchasing a shirt.

The most elegant solution might be to use skip conditions and listeners. Create a Buy Shirt flow that looks for input like “i want to buy a shirt”. In that flow, create a local listener that listens for your shirt types (most likely best stored in an entity object) and saves the type to a local variable, eg sShirtType = “polo”. On the output node where you ask what type of shirt, you can add a skip condition for sShirtType (groovy truthiness - if it’s not empty and not false, it’s true) to carry on in the flow without asking for shirt type if the user has already specified.

You may also want to set a global variable, eg sTopic = “buyShirt”, and add this as context to a trigger that looks for your examples such as “polo”, “gant”, etc (and you’d likely have another trigger looking for a complete input, “i want to buy a polo shirt” or i want to buy a gant shirt". That way the user could followup the question about polo with “what about gant?”

You can find comprehensive documentation on using context and skip conditions on the Teneo Developers site: As I’ve just signed up here to answer you, I’m not allowed to post links to the documentation for you, but if you search for “Context” and “Skip Conditions” you should find the right pages. There should be examples for the default Longberry Barista solution.

If you really do need to modify the user input before checking triggers, you can add script to the Global Preprocessing script using the command _.setUserInputText(“your modified user input here”). This will modify the user input text to whatever you pass it.

Let us know if you have additional questions or need further clarification.

Best regards,


Adding the links mentioned by Tim,


Best regards,

Thank you for the answer Tim. Yes I mean changing user input! :slight_smile: You talk a lot about design of “I want to buy a shirt” flow and I am more interested in entering that flow from a “what can you help me with?” flow.

Skip conditions and local listeners are elegant and pretty way to work with - totally agree, we use them in many situations.

Here we went for design decision so we have a lot of “I want to buy …” and 60 different flows for (if we stick to example) shirts. So inside the solution I can write, I want to buy a gant shirt in different ways and I will come to the right flow. What I want to do is to pretend writing “I want to buy a .lastInpu() shirt” in situation when the customer was unsure of what he can get assistance with through chatbot so he may have entered a “what can you help me with” flow where we can give alternatives in form of buttons as a guideline. One of those could buy “Buy shirts”. If customers decides to go for buy shirts we want to ask “what kind of shit would you like to buy?” - and here I would want to modify input to “I want to buy a gant shirt”.

I know I can solve it by using a conditional transitions with .lastInput / listener and send them to respective flow link but that would mean a huge tree of 60 flows after the node.

Preprocessing script is changing all the user inputs if I am not mistaken? That would not be optimal :smile:

Any further ideas if my approach is realizable? Or should I simply go for a different approach? What I am looking for is to through script node or other way do same thing as if customer writes something and presses enter.


P.S. Thanks for links Ramazan

OK, I think I understand better now - thanks. 60 flows is quite a bit - is the process that different for each type of shirt?

I don’t think modifying user input for specific inquiries is best practice as you’re right, it applies to every input. Global variables or scripted context might be your friend here. Once it’s clear the user wishes to buy a shirt, set a variable like sUserIntent = “buyShirt” which is then used as part of the trigger condition for each flow along with the shirt type, eg

    {sUserIntent == "buyShirt"} &^ %POLO.ADJ.LEX
    {sUserIntent == "buyShirt"} &^ %GANT.ADJ.LEX

You’d also need a trigger if the user expresses the whole thing directly using a condition for inputs like “I want to buy a polo shirt”, “Can I get a polo shirt”, etc. Classes would be harder to use here as the inputs look pretty similar from a pattern perspective.

Also, if you’re using a Teneo 6 instance, this can be more elegantly implemented than in Teneo 5 using Match Requirements, adding a script (or context) and an LO condition.

You could also use that variable to decide whether to modify the input in preprocessing:

    if (sUserIntent == "buyShirt") {_.setUserInputText("i want to buy a " + _.userInputText + " shirt");}

That would be risky and you would also need logic to make sure the user actually mentioned a shirt type rather than another topic or something like “forget it, changed my mind”.

It’s a bit hard for me to visualise so if it helps, I’m happy to set up a time to take a look at the solution with you - just DM me.