https://discord.gg/botpress logo
How to connect botpress api to appscript
# 🤝help
w
Actually I have used appscript to trigger conversation in the botpress so for that I need to connect botpress api to appscript but getting 404 error even though botId is correct kindly checkout below code let me know if any changes need to be done function postToBotpress(payload) { const botId = "your_bot_id_here"; // e.g., xyz789 const token = "your_PAT_here"; // 🔐 get it from your Botpress account const url = `https://bots.botpress.cloud/v1/chat/${botId}/integration/webhook`; const options = { method: "post", contentType: "application/json", headers: { Authorization:
Bearer ${token}
}, payload: JSON.stringify(payload), muteHttpExceptions: true }; const response = UrlFetchApp.fetch(url, options); Logger.log("Response code: " + response.getResponseCode()); Logger.log("Response body: " + response.getContentText()); } #🤝help #💻developers #💼business-inquiries @prehistoric-airplane-85682
p
Can you show your workflow?
Actually I have used event.preview so Im confused which api end point to use in the appscript to run Which starts conversation in botpress
For example if I give trigger variable as breakfast in the appscript it need to go to event.preview as incoming message and need to start conversation
p
If your calling a webhook then you should have the associated trigger in your workflow attached to your first node.
You can attach the first message in the payload.
w
Can we have a call ?
p
Unfortunately, I don't take calls, but you're welcome to join on tomorrow's livestream and ask for clarifications. Alternatively, you can provide more information or a clearer issue description in this thread.
actually my point is how it will work ?
// Function to send data securely to Botpress API function postToBotpress(payload) { const workflowId = "xxxxxxxxxxxxx"; // From Botpress const botId = "xxxxxxxxxxxxxx"; // From Botpress const baseUrl = "https://bots.botpress.cloud"; // Default Botpress Cloud URL const pat = "xxxxxxxxxxxxxxxxxxxxxxx"; // Personal Access Token (ideally store securely) const url = `https://bots.botpress.cloud/v1/chat/${botId}/integration/webhook`; const options = { method: "post", contentType: "application/json", headers: { Authorization:
Bearer ${pat}
}, payload: JSON.stringify({ input: payload, // Pass entire payload as input to workflow state: {}, // Leave empty for new conversations }) }; const response = UrlFetchApp.fetch(url, options); // Optional: log response for debug Logger.log(response.getContentText()); }
above is the code I have written to connect botpress from appscript
I don't know exactly which end point to take to trigger message which starts conversation in botpress
did you understand my question ?
My Objective: I have a set of variables, such as breakfast, lunch, and dinner. My goal is to pass any of these variables as a parameter to my code, which will then trigger a conversation in botpress by sending the variable's value as the conversation starter. For example: If the parameter is breakfast, the code will send this as a message to botpress to start the conversation. This message will be captured by event.preview in botpress. Based on the captured event.preview, the transition nodes in the workflow will proceed accordingly. @User
p
You would need to use the chat API createConversation endpoint: https://botpress.com/docs/api-reference/chat-api/openapi/createConversation
2 Views