https://discord.gg/botpress logo
#🤝help
info from console log
# 🤝help
f

future-vegetable-66332

07/06/2023, 11:51 AM
i make this request const headers = { 'User-Agent': 'YourCustomUserAgent/1.0' // Replace with your custom User-Agent header value }; // This function wraps your axios call and returns a Promise that resolves with the formatted response data function fetchOutput() { return new Promise((resolve, reject) => { setTimeout(() => { axios.get(url, { headers }) .then(response => { const data = response.data; // Format your response as needed here. Assuming your payload is just the
data
property. const payload = data; // Resolve the promise with the payload resolve(payload); }) .catch(error => { // Reject the promise with the error reject(error); }); }, 100000); }); } // You can use the fetchOutput function like this fetchOutput().then(payload => { console.log("Payload:", payload); }).catch(err => { console.error("An error occurred:", err); }); and i get the info i need to send to the client but its shown in console how can i pick up that info to be sent to the user in chat?
a

acceptable-kangaroo-64719

07/06/2023, 11:52 AM
Instead of
console.log("Payload:", payload);
, save the payload to a variable like
workflow.myVar = payload
Then you can ue a text card or other content and write
@myVar
to share the content with the user
f

future-vegetable-66332

07/06/2023, 11:54 AM
do i have to format the payload in a special way ?
and do i have to save it in a string ? and thanks for the quick response 🙂
im confused to how i should make the variable 😦
@acceptable-kangaroo-64719 am i doing something wrong ?
i tried so many things but i don't know what im overlooking
can i invite u as collaberator to see where it goes wrong ?
a

acceptable-kangaroo-64719

07/06/2023, 2:48 PM
what does your flow look like?
f

future-vegetable-66332

07/06/2023, 3:29 PM
i did it but it sends an empty variable
i think it's because the info gets updated while it sends the message so is there a way to create a delay before the message is sent?
a

acceptable-kangaroo-64719

07/06/2023, 5:15 PM
oh yeah, all code is async in capture cards so you need to await your API call
Copy code
js
const headers = {
  'User-Agent': 'YourCustomUserAgent/1.0' // Replace with your custom User-Agent header value
};

// This function wraps your axios call and returns a Promise that resolves with the formatted response data
async function fetchOutput() {
  return new Promise((resolve, reject) => {
    setTimeout(async () => {
      try {
        const response = await axios.get(url, { headers });
        const data = response.data;

        // Format your response as needed here. Assuming your payload is just the data property.
        const payload = data;

        // Resolve the promise with the payload
        resolve(payload);
      } catch (error) {
        // Reject the promise with the error
        reject(error);
      }
    }, 100000);
  });
}

// You can use the fetchOutput function like this
fetchOutput()
  .then(payload => {
    console.log("Payload:", payload);
  })
  .catch(err => {
    console.error("An error occurred:", err);
  });
4 Views