This automation responds to new WhatsApp messages based on the day of the week when the message was received.
Example usage: If message is received on Sunday, automation sends text "We are not available on weekends. Please leave your request and we will get back to you first thing Monday morning" in response.
Open TimelinesAI Workflow Builder https://app.timelines.ai/albato/automations and click New Automation
Click Add Trigger
Set up a trigger:
App where your data will come from: TimelinesAI
Event to trigger the automation: New incoming message
Connection token: leave as is.
Click Add action:
Add an action
App where your data will come from: TimelinesAI
Action to perform: Send message in existing Chat
Connection token: leave as is.
Map fields for the action and click Save:
Chat ID: click the field. New window with data from previous steps will appear. Unfold the fields from Step1 and find Chat ID. On click, value will will be inserted into "Chat ID" field.
Message: type desired message text. Example: "We are not available on weekends. Please leave your request and we will get back to you first thing Monday morning"
Click the "+" icon after the Step1 and select Сode
Select JavaScript
Add JavaScript code:
Input data: dateString , type= String, value = click the field. New window with data from Step1 will appear. Find Date and time the message was sent. On click, value will will be inserted into field.
Code: add code
function getWeekdayName(dateString) { // Checking timezone offset if (!/[+-]\d{4}$/.test(dateString)) { dateString += " +0000"; }// Checking format const match = dateString.match(/^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2}) ([+-]\d{4})$/); if (!match) return 'Invalid format';const [_, datePart, timePart, offset] = match;// Working with formats const formattedOffset = offset.slice(0, 3) + ":" + offset.slice(3); const isoString = ${datePart}T${timePart}${formattedOffset};const date = new Date(isoString); if (isNaN(date.getTime())) return 'Invalid date';// Returning results return new Intl.DateTimeFormat('en-US', { weekday: 'long' }).format(date);}const weekday = getWeekdayName(dateString);weekday;
Output data: weekday, type= String
Save the JavaScript.
Click the "+" icon after the Step2 ( JavaScript) and select Tool
Select Stop automation on condition tool and set it up:
Condition: Continue automation
Condition1: IF value = click the field. New window with data from previous steps will appear. Unfold the JavaScript ste and find weekday. On click, value will will be inserted into field. Condition value = contains. Value = type "Saturday"
Optional: click "Add condition to the group" and configure additional conditions in similar way. For example: to include "Sunday" or other desired days of the week.
Click "Start" to launch the flow
Additional recommendations ( optional)
Add error handler to each action step and choose what to do when errors occur:
Stop the automation
Continue the automation
Move on to the selected step below