https://discord.gg/botpress logo
Help me please
# 🤝help
p
w
Hi Antonio, in conversationId you must paste the ID of the conversation, not the string
{{workflow.conversationId}}
. You are looking at the docs and executing an API call the same way you would in Postman.
p
Hi Zanax, but if I have to paste the code in execute code conversation Id is a variable value right? So I made sure that event.conversationId is saved in the workflow.conversationId variable.
I don't know if I explained myself.
w
When you make an
axios.post()
call inside an Execute card and need the conversation ID, use the
{{event.conversationId}}
https://botpress.com/docs/learn/guides/advanced/event-properties#event-properties
you don't need to copy
event.conversationId
in a
workflow
variable
p
You're right, it's not necessary. However, it shouldn't be the reason why it gives me an error, right?
Sei italiano? Possiamo parlare italiano ? @white-nest-40686
w
you're getting an error in that case because {{workflow.conversationIdd}} is a string
since you're in the docs
you can try grabbing a real conversationId from your botpress and inputting it there
emulator ids do not work however (user-2, convo-1)
w
The conversation in the emulator are not saved, so you can't delete them. Se parliamo in italiano, altri con lo stesso problema, non capirebbero
p
@white-nest-40686 @wide-umbrella-5226 I tried to test directly on WhatsApp and in the Logs I saw that the problem is the webhook. It says "Only Get and Post methods are supported”. I got the webhooks from botpress studio->integrations->webhooks. Thank you both for your patience
w
can you send the code in your card here please
w
what webhookurl are you using in the url:
also conversation id should be
${event.conversationID}
also that x-user-api is wrong
it needs to be a JWT token that is your userId signed with an encryption key
it's a complicated mess maybe you should try using the runtime API deleteconversation instead
i can build that request for you
w
i suggest to use runtime api too
p
yes I would really appreciate it thank you very much
w
ok no problem
just tested it on postman and it works
im gonna build it for you, 5 mins
w
your url string must be include in `` to use ${event.conversationID}`
w
@powerful-restaurant-49993
p
all these errors are strange because the code was created by botpress in its generator, as in the photo I sent at the beginning
w
Copy code
javascript
const axios = require('axios');

const config = {
  method: 'delete',
  url: `https://api.botpress.cloud/v1/chat/conversations/${event.conversationId}`,
  headers: { 
    'x-bot-id': 'YOUR_BOT_ID', // you can grab this on the url after "studio.botpress.cloud" and before /flows/ 
    'Authorization': 'Bearer YOUR_PERSONAL_TOKEN' // you can grab this in your botpress profile. go back to your botpress app, click your profile picture, enter account settings, "access tokens" and then create one. don't delete the "Bearer"
  }
};

axios.request(config)
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.error('Error:', error.message);
  });
here you go
its because you didn't fill the fields correctly
but it's not really your fault because everything is pretty confusing
using the chatapi is a headache
p
thanks you very much.
I'm trying it and I'll let you know
w
const axios = require('axios');
is not necessary, axios is already imported
w
whoops true
@powerful-restaurant-49993 here's the corrected code
Copy code
javascript

const config = {
  method: 'delete',
  url: `https://api.botpress.cloud/v1/chat/conversations/${event.conversationId}`,
  headers: { 
    'x-bot-id': 'YOUR_BOT_ID', // you can grab this on the url after "studio.botpress.cloud" and before /flows/ 
    'Authorization': 'Bearer YOUR_PERSONAL_TOKEN' // you can grab this in your botpress profile. go back to your botpress app, click your profile picture, enter account settings, "access tokens" and then create one. don't delete the "Bearer"
  }
};


axios.request(config)
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.error('Error:', error.message);
  });
thatnks zannax
w
my pleasure, well done.
p
where can I find the bot id?
w
in the comments @wide-umbrella-5226 wrote where to find bot id and personal token 😉
It still won't delete the conversation it's weird
w
In your code delete lines after line 20, they are duplicated.
But the errore 401 is an authoritation problem
p
The conversation has been deleted. Thank you both so much
w
Bene, mi fa piacere.
3 Views