early-train-33247
08/03/2023, 8:16 PMin-0
and out-0
. If you change these names, remember what you changed them to, we'll need them later.
5. Click on "Deploy"
early-train-33247
08/03/2023, 8:17 PMcall_stack_ai
. 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:
js
// 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 =
'https://www.stack-inference.com/run_deployed_flow?flow_id=64b12e0b300d2b8f5f828099&org=8dc59f7b-40a4-41c4-ad11-d5e0f4691e27'
try {
const response = await axios.post(
url,
{ [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 = response.data[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 apiKey
. In the right box, paste your API key. You can get this by clicking on "Show Token" in the Stack AI deployment page.early-train-33247
08/03/2023, 8:21 PM@stackAIResponse
. If you see an error or a squiggly red line, you can ignore it for now 😉
Your node in Botpress should look like this:early-train-33247
08/03/2023, 8:22 PMearly-train-33247
08/03/2023, 8:23 PMearly-train-33247
08/03/2023, 8:24 PMhttps://www.stack-inference.com/run_deployed_flow?flow_id=12345678
To get your API key, click the "Show token" button. The API key will appear in the code after the word Bearer
and looks like abcd12-efg1-hi3jk-lmnop1
early-train-33247
08/03/2023, 8:25 PMin-0
and out-0
. 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:
js
{ [inNode]: `${workflow.userName} ${event.preview}` },
Here are some common things you might want to add:
* event.preview
is the thing the user said, exactly as they said it (without any spellcheck or other processing)
* event.tags
has information from WhatApp or other channels (if your Botpress bot is deployed to them) like phone number or user ID.
* turn.KnowledgeAgent.answer
has the Botpress knowledge agent's answer (if it is enabled).
* If you've made any workflow variables, workflow.variableName
can add them.early-train-33247
08/03/2023, 8:25 PMfresh-cricket-89011
10/29/2023, 6:10 AMearly-train-33247
11/03/2023, 5:53 PMwide-oyster-38514
11/09/2023, 4:43 PMearly-train-33247
11/21/2023, 1:40 PM