Create a message using the javascript client insid...
# 🤝help
w
Hey , I'm fairly new to using the javascript client, and I believe I can use it inside of an execute code card, but I'm struggling to create a message (from the bot to the user) with it Maybe this has something to do with this post https://discordapp.com/channels/1108396290624213082/1253354171306872853 @fresh-fireman-491 ?
if i code something like this
Copy code
const messageDetails = {
  payload: {
    text: 'text'
  },
  userId: event.userId,
  conversationId: event.conversationId,
  type: 'text', 
  tags: {}
}

// Send the message using the Botpress API client
client
  .createMessage(messageDetails)
  .then((response) => {
    console.log('Message sent successfully:', response)
  })
  .catch((error) => {
    console.error('Error sending message:', error)
  })
i get an error
Error sending message: {"id":"err_20240625201304x5946D634","code":403,"type":"Forbidden","message":"Bot \"0d8e6b9b-edd5-4f15-a992-4877470fd516\" is not authorized to create messages as an integration"}
and i didn't find why
n
did you turn on client in the settings? im trying something similar. your code at least worked for me though without any response
and where'd you find out how to do that?
w
Yep i did for sure
Hum I globally followed the API doc
But that’s not working 😅 Obviously that’s not made for this purpose but I was trying to do so
n
those api docs are incredibly unhelpful. i ran the code you posted in an exec block but i guess you did the npm botpress client install right? Hmm 403 probably you're not passing up the token correctly. i was playing with the api in postman a little bit and it looks like there are a few x-* fields you need to pass a header. x-bot-id with the id though that is a 400 not 403. could be you're not passing the token up right or its missing the word Bearer in the Authorization. I also saw an x field for the auth when i was searching the discord.
though im a little unclear what client handles/what client calls vs direct api calls vs integration...and again the docs suck. im gonna try and catch their office hours this coming AM. If i get anything that can help you ill let you know
w
Thanks , I will keep trying 👍
2 Views