return new Promise((resolve) => {
let pincode = app.data.message;
app
.executeApi("pincode", { pin: pincode })
.then((Response) => {
app.log(Response, "-------RESPONSE OF ----pincode API--------");
if (
Response &&
Response.statusCode &&
Response.statusCode == 200 &&
Response.body
) {
let details = JSON.parse(Response.body).results[0].address_components;
let detailsCard = ``;
app.log(details, "------DETAILS FOUND-------");
for (let i = 1; i < details.length; i++) {
detailsCard =
detailsCard +
`\n<strong>${details[i].types[0]} :</strong>${details[i].long_name}`;
}
app
.sendTextMessage(
`Here are the details for the pin code -<strong>${app.context.steps["pincode"]}</strong>\n ${detailsCard}`
)
.then(() => {
resolve();
});
} else {
app
.sendTextMessage(
"We have not found any detail for the pin code -<strong>${app.context.steps['pincode']}</strong>"
)
.then(() => {
resolve();
});
}
})
.catch((Error) => {
app
.sendTextMessage("There is some problem, please try again later !!")
.then(() => {
resolve();
});
});
});
This code is showing app is not defined. This code runs after an API and extract necessary info from the API.