I'm having issues with specifying an API response

Hey
Im currently trying to make a kind of verifycation process to a user [for example - user input is his name and phone number and then the bot verifying the rest of his details from the database nad make a confirmation node]

I’ve managed to build a service node with working API but i can’t seem to manage a correct response.

This is the API sample response[Some of the data is not in latin alphabet, sorry for the inconvienice but its irrelevant]

“statusCode”: 200,
“body”: {
“count”: 3,
“next”: null,
“previous”: null,
“results”: [
{
“id”: 1,
“order”: “1.99999999999999999999”,
“UID”: “100001”,
“UserName”: “AAAA”,
“Mobile”: “000000”,
“City”: “CCCCC”,
“Street”: “SSSSS”,
“BuildingNum”: “35”,
“ActivPolicy”: true,
“EndDate”: “2022-12-31”,
“Email”: “AAA@BBB.co.il”,
“Supplier”: [
{
“id”: 338957,
“value”: “כלל”,
“color”: “dark-green”
}
]
},
{
“id”: 2,
“order”: “2.99999999999999999999”,
“UID”: “100002”,
“UserName”: “AAVAVDS”,
“Mobile”: “11111111”,
“City”: “VDAVDAV”,
“Street”: “WQEQEW”,
“BuildingNum”: “35”,
“ActivPolicy”: false,
“EndDate”: null,
“Email”: “VVV@aAA.com”,
“Supplier”: []
},
{
“id”: 3,
“order”: “3.00000000000000000000”,
“UID”: “100003”,
“UserName”: “דור”,
“Mobile”: “0501234567”,
“City”: “חולון”,
“Street”: “הכישור”,
“BuildingNum”: “47”,
“ActivPolicy”: true,
“EndDate”: “2022-12-31”,
“Email”: “DDD@VVV.co.il”,
“Supplier”: [
{
“id”: 338958,
“value”: “AIG”,
“color”: “light-green”

above is the current process ive made only to test the API response.
I would appreciate some sort of help to understand how the flow below should look like

User - Hey, Im AAAA and my phone number is 000000
BOT - hey AAAA, your building number is CCCCCC

Thanks

Hello @dor.shneider ,

In your case, if my understanding is correct you want to be able to capture the user account based on the name and later confirm some if the retrieved values - like email, phone number , city etc…

If my service node name is retrievedatafields for example, after the service node, you will need to set up a script node to store the data in context and set up an object to capture the data fields you want to display to user.

Eg bot flow will be as below:

After the service node we will have a script node with example code like this:

var resultscount = context.retrievedatafields.response.body.count,
var resultdata = context.retrievedatafields.response.body.results,
context.session.BotUserSession.SearchResult = [],


for(i=0; i<resultdata.length; i++ )
{
    currentItem {};
    currentItem = {
        
        Name: resultdata[i].UserName,
        ID: resultdata[i].UID,
        Mobile: resultdata[i].Mobile,
        Email: resultdata[i].Email
    }
    
    context.session.BotUserSession.SearchResult.push(currentItem)
}

context.finalresult = context.session.BotUserSession.SearchResult

Post that, we will use the condition for message prompts as:

In the message node, you can use the context.finalresult objects for displaying the prompt. For a single value the prompt will be simple-

You can adjust the prompt for multiple values by using the Advanced mode.

Hope this helps your usecase. Let me know if you have any more questions.

thanks for the detailed answer.
I have managed to make the script node work but i don’t understand how the message node should be constructed accordingly to the user input.


i wish the message node will replay success only if the user entered a name that exist in the database linked by the API.
Also, i would like to understand how do i specify another response that will give back the other details connected to the User input name in the database.

@dor.shneider ,

We were able to correct the script. Please test with this:

var resultscount = context.demoapi.response.body.count;
var resultdata = context.demoapi.response.body.results;
context.session.BotUserSession.SearchResult = [];
var currentItem = {};

for(var i=0;i<resultdata.length;i++){
    currentItem = {
        Name: resultdata[i].field_788105,
        ID: resultdata[i].field_788104,
        Mobile: resultdata[i].field_788106,
        Email: resultdata[i].field_788112
    }
    
    context.session.BotUserSession.SearchResult.push(currentItem)
}

context.finalresult = context.session.BotUserSession.SearchResult;

thanks for the answer. the code is now working.
can you please help me to continue the process?
I have managed to make the script node work but i don’t understand how the message node should be constructed accordingly to the user input.

i wish the message node will replay success only if the user entered a name that exist in the database linked by the API.
Also, i would like to understand how do i specify another response that will give back the other details connected to the User input name in the database.

Thanks, Dor