I'm writing a little program which does a GET request and returns the result, which work. Homewer, I cannot manage how to get the value of userShortEmail (it always returns undefined when I call the getUserInfo(session)
function (It's supposed to return a String. I tried with timeout and callbacks but no luck so far.
Can you help me? Thanks
function callWebsite(session, args, next) {
var userShortEmail = "";
userShortEmail = getUserInfo(session);
var x = session.message.text.split(" ").pop();
x = jiraIssue.substring(0, jiraIssue.length - 1);
session.sendTyping();
setTimeout(function () {
var options = putHeader('/bikes/yellow' + x, "GET", userShortEmail);
function callback(error, response, body) {
var info = JSON.parse(body);
if (!error && response.statusCode == 200) {
session.endDialog(issueDetails(info));
}
else {
session.endDialog(info.errorMessages);
}
}
request(options, callback);
}, 300);
}
Edit : Here's the sode of getUserInfo function :
function getUserInfo(session) {
setTimeout(function () {
var conversationId = session.message.address.conversation.id;
connector.fetchMembers(session.message.address.serviceUrl, conversationId, function (err, result) {
if (err) {
console.log('There is some error');
}
else {
result.forEach(function (result) {
if (session.message.user.id === result.id) {
console.log("User is " + result.userPrincipalName);
return result.userPrincipalName;
}
});
}
});
}, 3000);
}