https://discord.gg/botpress logo
Push data from bot to my server
# 🤝help
c
So, I made a lead generation type of bot on botpress cloud that interacts with the users that visiting my website and I want the inputs given by user to be saved on my server. I have created an API to do so, but I don't know why the bot isn't pushing the data from bot to my local server. I already tested the API to see if there is something wrong in the API in the first place, but the API is fully fully functional. Are there any additional integration that I need to make in order to do so. I have created the API using Node.Js (express). Please help me out.. Thanks in Advance!
b
Firstly, make sure that you are setting either a BOT, User or Workflow variable to the value of the input you are capturing in the bot flow. Then if you are comfortable with Typescript you can use the "Before Outgoing Message" Hook with something like the code below (Change as needed)
Copy code
let data = outgoingEvent
//if your variable is not already available in the event object
data.MyVariable = workflow.MyVariable // or user..MyVariable etc

let config = {
  method: 'post', //or whatever verb you are using at your API endpoint
  url: 'https://yourapi.com/api/YourEndpoint',
  headers: {
    accept: '*/*',
    'Content-Type': 'application/json'
  },
  data: data
}

axios
  .request(config)
  .then((response) => {
  //Do whatever you want here, this just logs the response to the console.
    console.log(JSON.stringify(response.data))
  })
  .catch((error) => {
    //If you still don't have success then log what error is occurring when calling your API
    console.log(error)
  })
Hope that helps.
c
Thank you soo much!!