Search works in VoiceFlow but not working in ADC

Hi,

I am building a Podcast alexa skill for my company. I am using a custom code block to search in the JSON file that I get from the URL that my company gave me and find the specific title to play. The search is working great in VoiceFlow but is not working in Amazon Developer Console.

Can somebody help please with this issue.
I don’t know if is my problem or Voice Flow has any bug or Amazon Developer Console doesn’t like my code!

This is the flow I have!

This is how it looks in the Amazon Developer Console!

This is my custom code:

Thank You

1 Like

Hi! It’s likely not the search itself but actually the fact that the Alexa Developer Console does not support the Alexa Stream function.

Try playing this on an actual Alexa device and let me know if it streams properly :slight_smile:

Happy to help you out here!

@OltiAs see my response above!

@Braden Hi Braden,

Thank you very much for the response. I tried with amazon echo dot is not working. I am not sure what to try or change.

When it goes here it fails:


Instead of going “If Found” block it fails and goes to “RSS2JSON Fail” block. This is the only part of the podcast that is failing.

Do you have any other idea on how to fix this? In VoiceFlow is working fantastic.

Thanks,
Olti

Hmmm, can you share the code that you’re using within the Code block? It might be that Alexa isn’t allowing something within that code block to be executed, so it’s going down to the fail port vs the success port.

@OltiAs

Hi Braden,

This is my custom code for that block that I showed you before with arrow:

function getObjects(obj, key, val) {
var objects = [];
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (typeof obj[i] == ‘object’) {
objects = objects.concat(getObjects(obj[i], key, val));
} else
//if key matches and value matches or if key matches and value is not passed (eliminating the case where key matches but passed value does not)
if (i == key && obj[i].includes(val) || i == key && val == ‘’) { //
objects.push(obj);
} else if (obj[i] == val && key == ‘’){
//only add if the object is not already in the array
if (objects.lastIndexOf(obj) == -1){
objects.push(obj);
}
}
}
return objects;
}

var obj = getObjects(JSON ,‘title’, “APC By Schneider Electric Partnership Powers Your Success”);

search_Title = obj[0].title;
search_Desc = obj[0].description;
search_Url = obj[0].enclosure.link;

@Braden

1 Like

@Braden Hi Braden,

I found the solution to my question.

So this is the solution:

Amazon Developer Console doesn’t allow:

  1. Special characters in the string
  2. Every character must be lowercase.

So the title instead of being like this:
“Pardon The Integration: Barco - Bring People Together, Boost Productivity, Partnerships And Profitability”

Should be like this:
“pardon the integration barco bring people together boost productivity partnerships and profitability”

This is the final code:

function getObjects(obj, key, val) {
var objects = [];
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (typeof obj[i] == ‘object’) {
objects = objects.concat(getObjects(obj[i], key, val));
} else
//if key matches and value matches or if key matches and value is not passed (eliminating the case where key matches but passed value does not)
if (i == key && obj[i].toLowerCase().replace(/[~!@#$%^*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '').replace('&amp', 'and').replace(' ', ' ').includes(val.toLowerCase().replace(/[~!@#$%^*()_|+-=?;:’",.<>{}[]\/]/gi, ‘’).replace(’&amp’, ‘and’).replace(’ ', ’ ')) || i == key && val == ‘’) {
objects.push(obj);
} else if (obj[i] == val && key == ‘’){
//only add if the object is not already in the array
if (objects.lastIndexOf(obj) == -1){
objects.push(obj);
}
}
}
return objects;
}

var obj = getObjects(j_stream,‘title’, “Pardon The Integration: Barco - Bring People Together, Boost Productivity, Partnerships And Profitability”);

search_Title = obj[0].title;
search_Desc = obj[0].description;
search_Url = obj[0].enclosure.link;

Thanks for the Help.
Olti

1 Like

Great to hear you found the solution! :slight_smile: