How to create autocomplete with valid input

In this yellow ai docs , there is no valid inputs.
https://docs.yellow.ai/docs/platform_concepts/studio/cloud-function/#autocomplete.

Can you please guide me to create a autocomplete on question node

1 Like

Hey @pradeepkumaresan

I understand the current documentation for the autocomplete feature is not sufficient. I’ve informed the team to update the documentation ASAP.

Thanks!

Hey @pradeepkumaresan
Can you please share more details about the use case?

@pratik,
There are list of countries. Customer need to select one of the available countries.
To avoid typo error, if we can able to provide auto complete option in web chatbot, it would be easy for customer.

1 Like

Thank you @senthil.vasan. Will share with the team and revert back to you ASAP if this can be implemented.

Hi @Pratik , Does we have any update regarding this. We having the blocker . Please guide us to sort it.
Thanks

@Pratik , In question node we have option to chose function for autocomplete

Could you please give us sample code for the function? Code shared here Code | yellow.ai is not helpful

1 Like

The function you select in the prompt setting to autocomplete using, should resolve (return) an array of items you wish to be shown in autocomplete.

In most cases, this is pretty dynamic so people use results returned from a DB to create an array in function mostly; but for static items, you can directly do that too.

For your usecase, you can use this code snippet

return new Promise(resolve => {
    let result = ["India", "USA", "Canada", "UK"]; // list of countries you want to suggest
    const {term} = data;
    let suggestions = []
        result.forEach((hit) => {
            if (hit.component.toLowerCase().includes(term.toLowerCase())) {
                suggestions.push([hit.component, hit.component])
            }
        });
      resolve(suggestions);
  }); 

I have used question node by calling the function by the code you provide with and without ticking the select boxes . Still it’s not working. I have attached the screenshot .

Function not calling on question prompt node.

Can you send a video of autocomplete work. So that i can verify.
Thanks

1 Like

Can you please raise a JIRA ticket for this issue? It seems like there’s an issue with the bot.

@Pratik how can we raise ticket in JIRA? could you provide the URL?

1 Like

Sure, you can raise a JIRA ticket on the yellow.ai Support board: Log in with Atlassian account

Please share the ticket ID once you’ve raised the ticket.

Following code works fine.

return new Promise(resolve => {
    console.log("inside autoSuggestion");
    let options = [
		{
			'question' : 'India'
		},
		{
			'question' : 'America'
		},
		{
			'question' : 'USA'
		},
		{
			'question' : 'UK'
		},
		{
			'question' : 'INDIA'
		},
		{
			'question' : 'india'
		},
		{
			'question' : 'Russia'
		},
		{
			'question' : 'Russia123'
		},
		{
			'question' : 'RUssia12'
		},
		{
			'question' : 'Where is my sim card'
		}
	]
    
    const { term } = data;
    let suggestions = [];
    options.forEach((hit) => {
        if (hit.question.toLowerCase().includes(term.toLowerCase())) {
            suggestions.push([hit.question, hit.question]);
        }
    });
    resolve(suggestions);
});     
1 Like

Thank you for sharing the solution with the community @senthil.vasan!