Stack-ai API into Botpress
# 🤝help
Hello, I am looking to add my stack-ai API into BotPress. The bot will read information from the question the user has asked "@question" and stack-ai will feed the answer back to the user in the variable "@apiMessage". I have used the below code in the card 'execute code' however I am receiving an error message when testing my bot. I would greatly appreciate the help, as I've been stuck on this for days. // Add your stack AI endpoint URL in place of "YOUR_STACK_AI_ENDPOINT_URL" const endpoint = "" // Add your stack AI API key in place of "YOUR_API_KEY_HERE" const headers = { Authorization:
, "Content-Type": "application/json" } const data = { "in-0": workflow.question, } try { const response = await, data, { headers }) workflow.apiResponse =["out-0"] } catch (error) { throw new Error(
stack-error: ${error}
) }
use this code:
Copy code
// Set these to the names of your stack-AI in/out nodes
var inNode = 'in-0'
var outNode = 'out-0'
// Change this to your Stack-AI URL
let url =

try {
  const response = await
    { [inNode]: `${event.preview}` },
    // Be sure to set your API key as an env variable
    { headers: { Authorization: `Bearer ${env.apiKey}`, 'Content-Type': 'application/json' } }
  workflow.stackAIResponse =[outNode]
} catch (e) {
  console.error(`There was an error calling Stack-AI: ${e}`)
Be sure to set an config variable called
with your Stack ai API key
That worked, thank you so much!