-1
Hello
I’m trying to set up a function but without success. I use a "client.classifyImageUrl" function that will process a cognitive service, when finished, I need to take the result value (more specifically: result.Predictions[0].tagname) and return to the bot with step.context.sendActivity but I’m not sure how to do it. I left the code as follows but is generating an error of: Syntaxerror: await is only Valid in async Function when trying to start the service (npm start). Could you help me?
async identificarSabor(step) {
endDialog = false;
const credentials = new ApiKeyCredentials({ inHeader: { "Prediction-key": process.env.CustonVisionKey } });
const client = new PredictionAPIClient(credentials, process.env.CustonVisionEndpoint);
//console.log(step.context.activity['attachments'][0].contentUrl);
console.log(result);
client
.classifyImageUrl(process.env.CustonVisionProjectId, process.env.CustonVisionIteration,
{ url: step.context.activity['attachments'][0].contentUrl })
.then(result => {
if ('predictions' in result) {
await step.context.sendActivity(result.predictions[0].tagName);
}
})
.catch(err => {
//step.context.sendActivity("Não consegui identificar a pizza nessa imagem. Tente enviar outra imagem!");
console.error(err);
});
return await step.continueDialog();
}
Actually the problem I am is in this line: await step.context.sendActivity(result.Predictions[0].tagname); I’m not being able to return "tagname" using the sendActivity function. If I take it out of the classifyImageUrl function I don’t have the result, if I put it in, the error in the function use, either with await or without. I don’t understand how to do this.
– Marlon
Well, it’s the same. Tu está chamar um await dentro de um bloco .then... Grab it step.context.sendActivity(result.Predictions[0]. tagname) . then( value => value) . ( catch value => value
– user180043
Got it, I’ll try, thanks.
– Marlon