Problem with Stack-IA to Botpress
# 🤝help
c
Hello, I have a problem with Stack-IA, I imported my project on Botpress, except that when I ask a question, it answers me this: https://cdn.discordapp.com/attachments/1221478165504069692/1221478274602111076/image.png?ex=6612b94a&is=6600444a&hm=4f147f5e5d9ae7f15dbdb0fa7af1f7a3a1ed661bfdce0e92891503b6bf036cb4&
I followed this tutorial to the letter, however I don't get the same result. :

https://www.youtube.com/watch?v=nusk9-nfyoA&ab_channel=MaximeHalley

g
There's probably an error with your execute code cards
And if you didn't change accordingly with your API key the execute code card, then that's probably the reason why your bot isn't working
w
Adding to what Jet said, you can trouble shoot with this tutorial: https://discord.com/channels/1108396290624213082/1136754491266437241
function uuidv4() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8 return v.toString(16) }) } workflow.acheterPlus = "J'attendrai jusqu'à demain !" workflow.conversationID = uuidv4() console.log(workflow.conversationID) const endpoint = "https://www.stack-inference.com/inference/v0/run/b070374c-a524-4d9c-91fe-4e61a4261965/660038b292cd58e24160e26b" workflow.nombreDeMessages += 1 console.log(workflow.nombreDeMessages) const headers = { Authorization: 'Bearer e63b9f84-6989-43a3-9c26-d7ebfe51725a', 'Content-Type': 'application/json' } function extractInitialMessage(sessionConversation) { for (const conversation of sessionConversation) { if (conversation['sender'] === 'user') { workflow.question = conversation['preview'] } } } extractInitialMessage(event.state.session.history) const data = { 'in-0': workflow.question, user_id: workflow.conversationID } try { const response = await axios.post(endpoint, data, { headers }) if (response.status === 200) { workflow.messageSuivant = response.data['out-0'] } } catch (error) { if (error instanceof Error) { throw new Error(
api-error: ${error.message}
) } throw new Error(
api-error: ${error}
) }
// Collez votre url javacript Stack AI const endpoint = "https://www.stack-inference.com/inference/v0/run/b070374c-a524-4d9c-91fe-4e61a4261965/660038b292cd58e24160e26b" workflow.nombreDeMessages += 1 console.log(workflow.nombreDeMessages) // Collez votre PUBLIC API KEY const headers = { "Authorization": "Bearer e63b9f84-6989-43a3-9c26-d7ebfe51725a", "Content-Type": "application/json" } const data = { 'in-0': workflow.question, 'user_id': workflow.conversationID } try { const response = await axios.post(endpoint, data, {headers}) if (response.status === 200) { workflow.messageSuivant = response.data["out-0"] } } catch (error) { if (error instanceof Error) { throw new Error(
api-error: ${error.message}
) } throw new Error(
api-error: ${error}
) }
This is good ?
g
I'm not that good in API javascript code but I would personally use a different execute code template like the one on the google docs (not copy/pasting here the code because you won't be able to copy it correctly because discord has like special characters for bold,italic,etc) : https://docs.google.com/document/d/1DSeDW0zzXqAQns1kATh0trQ47fcARhVN_SxYTBVG9Ps/edit?usp=sharing
c
What is this ?
I have to replace ?
g
yes you should replace your code under the question card
c
for both ?
g
No, I think only the one under question
c
So, the one ?
This ?
g
make sure to create a variable called stackAiResponse (must be written like that).
I'd say replace this part : // Collez votre PUBLIC API KEY const headers = { "Authorization": "Bearer e63b9f84-6989-43a3-9c26-d7ebfe51725a", "Content-Type": "application/json" } const data = { 'in-0': workflow.question, 'user_id': workflow.conversationID } try { const response = await axios.post(endpoint, data, {headers}) if (response.status === 200) { workflow.messageSuivant = response.data["out-0"] } } catch (error) { if (error instanceof Error) { throw new Error(api-error: ${error.message}) } throw new Error(api-error: ${error}) }
c
I replaced it like this, is it good ? :
Copy code
const inputMessage = workflow.question;
const API_URL = "https://www.stack-inference.com/inference/v0/run/b070374c-a524-4d9c-91fe-4e61a4261965/660038b292cd58e24160e26b";
const headers = {
     'Authorization': 'Bearer e63b9f84-6989-43a3-9c26-d7ebfe51725a', 'Content-Type': 'application/json'
};
const payload = {
        "in-0": inputMessage
};
try {
    const response = await axios.post(API_URL, payload, { headers: headers });
    workflow.stackAiResponse = response.data["out-0"];
} catch (error) {
    throw new Error(`Error in Stack AI: ${error}`)
}
f
There is a problem with the workflow.stackAIResponse variable. You should try and debug that 🙂
A red underline usually means that its a problem
c
I do not know how to do..
g
I think the error is coming from the fact that he didn't create a variable called stackAiResponse
c
It's weird, because in the video it works, the video was released not long ago, so it's weird.
g
have you created the workflow.stackAiResponse variable ?
if yes after the new code, add a text card with : @workflow.stackAiResponse
c
In the video code, there is not that, this is the code :
Copy code
function uuidv4() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
        return v.toString(16);
    });
}

workflow.acheterPlus = "J'attendrai jusqu'à demain !"

workflow.conversationID = uuidv4();
console.log(workflow.conversationID);

// Collez votre url javacript Stack AI
const endpoint = "https://www.stack-inference.com/inference/v0/run/b070374c-a524-4d9c-91fe-4e61a4261965/660038b292cd58e24160e26b"

workflow.nombreDeMessages += 1
console.log(workflow.nombreDeMessages)

// Collez votre API PUBLIC KEY
const headers = {
  Authorization: 'Bearer e63b9f84-6989-43a3-9c26-d7ebfe51725a',
  'Content-Type': 'application/json'
}

function extractInitialMessage(sessionConversation) {
  for (const conversation of sessionConversation) {
    if (conversation['sender'] === 'user') {
      workflow.question = conversation['preview']
    }
  }
}

extractInitialMessage(event.state.session.history)

const data = {
  'in-0': workflow.question,
  'user_id': workflow.conversationID
}

try {
  const response = await axios.post(endpoint, data, { headers })
  if (response.status === 200) {
    workflow.messageSuivant = response.data['out-0']
  }
} catch (error) {
  if (error instanceof Error) {
    throw new Error(`api-error: ${error.message}`)
  }
  throw new Error(`api-error: ${error}`)
}
I would like to delete the purchase part, what should I delete ?
g
workflow.acheterPlus = "J'attendrai jusqu'à demain !"
yes
c
What do I do with this ?
g
delete that part of the code
and the variable acheterPlus
c
Copy code
function uuidv4() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
        return v.toString(16);
    });
}

workflow.acheterPlus = "J'attendrai jusqu'à demain !"

workflow.conversationID = uuidv4();
console.log(workflow.conversationID);

// Collez votre url javacript Stack AI
const endpoint = "https://www.stack-inference.com/inference/v0/run/b070374c-a524-4d9c-91fe-4e61a4261965/660038b292cd58e24160e26b"

workflow.nombreDeMessages += 1
console.log(workflow.nombreDeMessages)

// Collez votre API PUBLIC KEY
const headers = {
  Authorization: 'Bearer e63b9f84-6989-43a3-9c26-d7ebfe51725a',
  'Content-Type': 'application/json'
}

function extractInitialMessage(sessionConversation) {
  for (const conversation of sessionConversation) {
    if (conversation['sender'] === 'user') {
      workflow.question = conversation['preview']
    }
  }
}

extractInitialMessage(event.state.session.history)

const data = {
  'in-0': workflow.question,
  'user_id': workflow.conversationID
}

try {
  const response = await axios.post(endpoint, data, { headers })
  if (response.status === 200) {
    workflow.messageSuivant = response.data['out-0']
  }
} catch (error) {
  if (error instanceof Error) {
    throw new Error(`api-error: ${error.message}`)
  }
  throw new Error(`api-error: ${error}`)
}
g
As I said you should use this code. By using this you won't have anything associated with number of message and cost.