How to integrate with Stack AI
# 🤝help
A lot of folks here are looking to combine their Botpress bot with [Stack AI]( In this post, we'll walk through the step-by-step of how you can get your Botpress bot and your Stack-AI middleware to talk to each other. 🤖 What is Stack-AI? [Stack AI]( is a low-code, web-based tool for building AI systems (like Botpress!). It offers highly customizable ways to use your own documents and data, query different foundation models (like GPT 4, Claude, or Huggingface hosted models), and even digest and generate images. Stack AI also provides an easy API to access your tools from anywhere on the internet. 🤨 What's an API? API stands for Application Programming Interface, and it is a standard way for computers to talk to each other. APIs can only be access through code, which can make them a bit scary- but it also makes them extremely flexible and super useful. In order to get your Botpress bot and Stack AI to talk to each other, we need to use an API. 🪧 Stack AI Setup First we need to make something on Stack AI. A great way to get started is to use their "Simple Chatbot" template. 1. Head to [Stack AI]( and make an account (or log in if you have an account already) 2. Make a new project with the "Simple Chatbot" template. 3. Pick your LLM and your prompt. For this tutorial, I'll be using Anthropic's Claude 2 model to generate haikus. ⚠️ Make sure you include an input for your LLM 4. Pay attention to the names of your input and output nodes. By default, they are called
. If you change these names, remember what you changed them to, we'll need them later. 5. Click on "Deploy"

Botpress Time! Now we're ready to make our Botpress bot! 1. Head to [Botpress]( and make a new bot. Use a template and select "blank" 2. Make a new node and call it
. Add a "Raw Input" capture card with the question, "What would you like a haiku about?" 3. Add an execute code card after the capture card. Copy and paste the below code into your Execute code card:
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}`)
4. Change the following things in the code: - URL: Change this to your Stack-AI URL. You can get this by going to "Deployments" from your project dashboard. - inNode / outNode: If you changed the names of your input and output nodes, update them here. Otherwise, leave them as the default values 5. Finally, you'll need to add your Stack-AI API key as an environmental variable. To do this: - Go to "Chatbot Settings" and click on the "variables" tab - Scroll down to 'Configuration Variables' and click on the '+'sign - In the left box write
. In the right box, paste your API key. You can get this by clicking on "Show Token" in the Stack AI deployment page.

6. Finally, add a Text card and make your bot say
. If you see an error or a squiggly red line, you can ignore it for now 😉 Your node in Botpress should look like this:

⛳️ The Finish Line Now you should be able to talk to your bot, and, after it asks you a question, talk to your Stack-AI tool, too! Pop open the emulator and give it a try!

Here's an export of the Botpress bot used in this tutorial to get you started. ⚠️ You will need to add your own API key ⚠️
* 🙋‍♂️ FAQs 🙋🏽‍♀️ * ❓_How do I get my Stack AI URL and API Key?_ The easiest way is to: 1. Deploy your Stack-AI tool 2. Click on the "Deployments" tab in the upper-left corner. The URL is displayed in the code (no matter what language). It looks like
To get your API key, click the "Show token" button. The API key will appear in the code after the word
and looks like

❓_I've followed the instructions but I still get an error in Botpress!_ Here's a good troubleshooting process: 1. Verify that you have set an API key as a config variable and that it is called apiKey (with a capital 'K') 2. Verify that you have changed the URL to your Stack-AI URL (and not my Stack-AIURL). 3. Verify that your Stack-AI input & output nodes are called
. If they are not, update the code. 4. Verify that your Stack-AI bot has been deployed by clicking the blue "Deploy" button in the top right 5. Verify that your Stack-AI bot actually works as expected 6. Look in the logs in the Botpress bottom panel and see what the error is and read its description. You can search this Discord channel (and Google) for this error and see how other people have solved it.
❓_How do I send more data than just the user's message to my Stack-AI?_ In the code, modify line 11 to include the data you want. For example, if you want to include a variable called "userName", change it to:
Copy code
    { [inNode]: `${workflow.userName} ${event.preview}` },
Here are some common things you might want to add: *
is the thing the user said, exactly as they said it (without any spellcheck or other processing) *
has information from WhatApp or other channels (if your Botpress bot is deployed to them) like phone number or user ID. *
has the Botpress knowledge agent's answer (if it is enabled). * If you've made any workflow variables,
can add them.
How do I build on Stack-AI? I'm not sure 😅 , but here's what the tool I built on Stack-AI looks like. Perhaps it will help you.

Yo, I'm calling external api in execute code, and I'm saving response into a variable, which will then be sent in chat with text field. The problem is that it just runs all fields and sends text (old value) to chat without waiting for api call to finish. How do I wait for exexute code to finish or maybe somehow send response into chat when it is returned, or? Pls tag me if u answer.
@wide-pharmacist-63065 can you paste your code here or screenshot? make sure you have
statements everywhere
Thanks for sharing...also is it possible to use it for contextual Q&A? Like you want it to use the recent conversation as the context and send responses accordingly. For eg. User:Do you have the X product. Bot: yes we sell the product "x" User: tell me more about it. ( I want the bot to remember the previous line about the "X" product and then give me more details about it without me typing the whole thing again like " tell me more about the Product X " )
i am still trying to figure out how to make the AI remember the previous conversations. it has something to do with the summary agent. You have to input the summary into the AI task ------ {{conversation.SummaryAgent.transcript}} ------- however i have tried this under @acceptable-kangaroo-64719 's instruction and it still does not work. Wish there could a final and definitive solution to this
The new v3 Knowledge Agent allows you to pass context to the search. In this example, we add the chat transcript from the summary history to every knowledge search, and that would provide helpful context.

thank u, i added await and it works
Has anyone been successful in creating the same sort of ai response as in botpress as stack AI? I understand they both use turbo but for some reason the response in botpress is limited...perhaps it's a character thing?
I think botpress don't uses embedding and vector databases
@little-doctor-93292 That would make sense, thanks!
Good stuff lads
@little-doctor-93292 have you had success calling the stack API key? getting this error:

code is: "// 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 = 'URL here' try { const response = await url, { [inNode]:
}, // 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}
) } " I have also tried @boundless-pencil-51555 code from his dope template.
I find stack Ai very expensive and choose Flowise and an viable alternative
Thanks Raj, a great help. I will have a look at Flowise. Do you have any code to call the api for flowise you dont mind sharing?
This should work but { [inNode]: ${event.preview} }, doesn't need square brackets around it. { inNode: ${event.preview} },
Here is a botpress file I made a while ago using @brave-scientist-86214 's has the code in execute code...and a flow of Flowise Api... It's not properly arranged as I was still experimenting with it at that time but you should be able to find what you need in there
Sick, will give that a squizz and see how she runs.
Cheers for sharing that Raj, when I get back to the computer I'm goanna give it a go. Thanks heaps
You're welcome