Action directory
# 🤝help
t
Hi guys! does anyone know how to access the "data/global/actions" directory to create a custom action? I should mention that I am building my bot using the Botpress web application (on my Google Chrome browser). Thanks!
f
What do you mean "custom action"?
t
Following chat GPT instructions and botpress DOCS, it looks I have to create a new action through à javascript code in a new action file ".js" and to put it in "actions.yml" file which is in the repertory "data/global/actions"
For your information, I am looking to write a short script to set a time-based condition: if the current time is between 6 AM and 10 PM, then go to node X; and if the current time is between 10 PM and 6 AM, then go to node Y. May be there is an easier way to proceed ?
f
Ah okay. We can just do this in Botpress. We can use the Date object to get the current time and then checking it against your conditions.
Copy code
javascript
const now = new Date();

now.setHours(now.getHours() + 1);

const currentHour = now.getHours();

if (currentHour >= 6 && currentHour < 22) {
    workflow.conditionVariable = true;
} else  {
    workflow.conditionVariable = false
}
We start out by creating a new Data object that will represent the current date and time. Then we adjust the timezone of the Date object to GMT+1 (my time zone) by adding 1 hour to the current hour. Then we retrieve the hour component of the current time in the GMT+1 timezone. Then we check if the current hour is between 6AM and 10PM If it is then we set hour workflow variable to true. Else we set it to false.
t
Hi Decay,
I juste tryed your .bpz and it works exactly as I wanted. I had been stuck on this condition for two days. Thank you so much !!!!
f
That is amazing to hear! You are very welcome
e
hello, is it possible to Following chat GPT instructions and botpress DOCS, it looks I have to create a new action through à javascript code in a new action file ".js" and to put it in "actions.yml" file which is in the repertory "data/global/actions"? I am trying to convert when user says today to their current day and Sunday to something in this format 01/09/2024. Is it possible?
52 Views