How to trigger flow based on user input?

hi - new to this, but i have what seems like a simple question, maybe someone can point me in the right direction.

How can we trigger a flow based on user typed input?

for example: i have a main flow, and 2 other flows (flow 1 & flow 2), my main flow asks a question with two choices, if they choose choice 1 they go to flow 1 if they choose choice 2 they go to flow 2. IF however, they do not click a choice, instead they TYPE something, i would like to trigger flow 1 if they type specific words. Tips?

Hie @chris, you can use an action which detects the word then uses jumpTo function to go wherever you wanna take your user. For example (this is unedited code from the top of my head for illustration so you can debug or use an alternative way)

	if (event.state.user.profile === 'generated' && typeof event.payload.text !== 'undefined') {
		//get session ID
	  	const sessionId = bp.dialog.createId(event);	

		//get what the user said
		const uSaid = event.payload.text;

		//remove spaces, full stops and commas
		const uSaidRegex = /[.,\s]/g;
		const uSaidResult = uSaid.replace(uSaidRegex, '');

		//convert what the user said to lower case. 		
		const uSaidLC = uSaidResult.toLowerCase();

		//test if what the user said matches any of the keyword
		switch (uSaidLC) {
			  case 'return':
				    bp.dialog.jumpTo(sessionId, event, 'main.flow.json', 'entry-node');'*Reset conversation');
                  //you can test as much more as you want using case statements

Another way is to create intents for each of the two choices. Then using a similar action you can check for the intent in the event and if it is present you can jumpTo another part of the chatbot. Using an intent, you can also create a transition in your flow based on intent detection.

You can also create a QnA entry with what the user might say and then create a redirect as a response to the QnA.

I hope you will find a method that works best for your use-case here.

hi @Michael_BotpressTeam
Thanks for taking a minute to reply, it’s encouraging that a member of the team is reviewing the forum and providing responses.

in this case, i will try your example code, but i am very interested in this redirect option you offered, however, adding a single QA, with a single q for exact match, and setting to redirect, is not working (no mater the context i try) maybe i am missing something. any insight?

Hi @chris,

You can also checkout this solution we created to redirect the user on when an exact intent is sent to the bot. It’s very close to what you are trying to accomplish.

Hope this can help :slight_smile: