https://discord.gg/botpress logo
n
Hello guys I’m new to botpress , I’m trying to build a bot the send different message and stores the persons replies for 30 days and only send the messages from sunday to Friday . Can anyone help with this?
c
if you want them to be deleted after 30 days, you can use the Botpress API to retrieve conversations then check if some of them are older than 30 days and programatically delete them: https://botpress.com/docs/api-reference/runtime-api/openapi/listConversations https://botpress.com/docs/api-reference/runtime-api/openapi/deleteConversation
n
Not what i meant, I want the bot to send an automated message every single day for 30 days straight , and store the person reply, how can i do that
c
If you only want the chatbot to respond at certain times, my initial thought would be checking the current day by using the "Code Execution Card", then checking if the day is correct or not. https://cdn.discordapp.com/attachments/1397154530805678130/1397178849883721779/image.png?ex=6880c7b4&is=687f7634&hm=e10b6f07552749de6a28dfbcd6028b596b5959b54ca28609ea672b4757f13b96&
Code Execution Card: const currentDate = luxon.DateTime.now() // Get the current date and time const currentDayOfWeek = currentDate.toFormat('cccc') // Format to get the full name of the day console.log(
Today is ${currentDayOfWeek}.
) // Log the current day of the week workflow.currentDayOfWeek = currentDayOfWeek // Save the current day of the week into the workflow variable
n
What about using the fixed schedule trigger ?
c
Expression Card: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'].includes(workflow.currentDayOfWeek)
this trigger will only "Kick-off" the workflow at certain times. you will need it to automate stuff
n
Well I need the bot to send automated messages every message is different for 30 days but only on certain days like Sunday until Friday
c
i see, hen the fixed schedule trigger is the correct way. where are you planning to deploy your chatbot
n
WhatsApp
Can you help with the workflow ?
c
got it. you can do this, so it will automatically fire the workflow on your desired days. of course you can change the time too, keep in mind that the timezone is UTC. https://cdn.discordapp.com/attachments/1397154530805678130/1397181563862519948/image.png?ex=6880ca3b&is=687f78bb&hm=cb08739704dc64bc06fc976730a2e609f33ed1c0b71bf2fed9aa44f7ca48d7ea&
n
Okay but how do i make so it send a different message everyday the message are already written , which node to I choose
@clever-insurance-2779
c
you could check which day it is like it shown you before by connecting your "fixed schedule trigger" with a "standard node" that looks like this (code). depending on the day you can execute a different workflow. or even save different messages in a variable array and map it to the days
in the code execution card you type: const currentDate = luxon.DateTime.now() // Get the current date and time const currentDayOfWeek = currentDate.toFormat('cccc') // Format to get the full name of the day console.log(
Today is ${currentDayOfWeek}.
) // Log the current day of the week workflow.currentDayOfWeek = currentDayOfWeek // Save the current day of the week into the workflow variable let dailyMessage // Variable to hold the message for the day // Switch statement to set a different message for each weekday switch (currentDayOfWeek) { case 'Monday': dailyMessage = 'Start of the week! Let’s make it productive.' break case 'Tuesday': dailyMessage = 'Keep going! It’s Tuesday.' break case 'Wednesday': dailyMessage = 'We are halfway through the week!' break case 'Thursday': dailyMessage = 'Almost there! Just one more day to go.' break case 'Friday': dailyMessage = 'It’s Friday! The weekend is near.' break case 'Sunday': dailyMessage = 'Relax, it’s Sunday!' break default: dailyMessage = 'Have a great day!' } workflow.dailyMessage = dailyMessage // Save the current message of the week into the workflow variable console.log(dailyMessage) // Log the message for the day
now, in the variable {{workflow.dailyMessage}} you will always have a different message, depending on which day it is.
hope it helps
n
Idk it doesn’t run
c
could you share what you did šŸ™‚
i change it to very minute so i can test itbut it deosnt work
i did the variables and and same code
@clever-insurance-2779
c
it won't work like that because, you are expecting a response in the test webchat at the right-screen, is this correct? the trigger wont work on the emulator. it just fires a signal but doesn't know where to fire unless you specify it. you can already directly ping your message on Whatsapp
now you can do the same. but instead of sending a message to this random test endpoint, you can do so to whatsapp
to a specific user
n
still doesnt work
@clever-insurance-2779