Background information
To wish someone a Happy Birthday and celebrate the years of seniority automatically in slack, Zapier can help you to perform this task easily and quickly.
or
Log in to zapier
You can log in to zapier here : https://zapier.com.
Create an account or use an existing account.
Zap configuration
You have to configure the first step. The "Choose App" button will display a list of tools available. In the "Built-in apps" feature, please select the schedule icon.
You will now have to set your schedule. First, make sure you select how often you want the script to run, for example every day.
You will then choose the time of the day to run the script, as well as whether you want it to be triggered during weekends or not.
Once this first step has been completed, you can test it with the “Test this Step” feature. For the second step (being the action), please choose the "Code" icon.
Select Javascript
You will first need to fill in the “Input” part by replacing the “xxx” with your information:
In the first box, please replace the “xxx” with the name of your company. In the appToken box, please replace the “xxx” with your token, that you can obtain by contacting the Lucca support team
Then, you can copy the code below into the “Code” field:
var today = new Date(); var yearS = "" + today.getFullYear(); var month = today.getMonth() + 1; var monthS = month > 9 ? "" + month : "0" + month; var dayS = today.getDate() > 9 ? "" + today.getDate() : "0" + today.getDate(); var todayS = yearS + "-" + monthS + "-" + dayS; var urlBase = input.url + "/api/v3/users?fields=birthDate,picture.href,firstName,lastName,DtContractStart&dtContractEnd=since," + todayS + ",null"; var appToken = input.appToken; var potentialBirthDateArray = []; for (var yearShift = 1; yearShift <= 70; yearShift++) { potentialBirthDateArray.push((today.getFullYear() - yearShift) + "-" + monthS + "-" + dayS); } var getSeniorityAnniversary = function (people) { fetch(urlBase + "&DtContractStart=" + potentialBirthDateArray.join(","), { "headers": { "Authorization": "lucca application=" + appToken } }).then(function (response) { return response.json(); }).then(function (results) { results = results.data.items; results.map(function (result) { if (result.picture && result.picture.href) { result.pictureHref = result.picture.href; } else { result.pictureHref = null; } result.year = (today.getFullYear() - result.dtContractStart.split("-")[0]); result.birthDayMessage = result.firstName + " " + result.lastName.slice(0, 1) + ". déjà " + result.year + " ans avec nous ! :cake: "; people.push(result); }); callback(null, people); }).catch(function (error) { console.log(error); }); } fetch(urlBase + "&birthDate=" + potentialBirthDateArray.join(","), { "headers": { "Authorization": "lucca application=" + appToken } }) .then(function (res) { return res.json(); }).then(function (data) { var people = data.data.items; if (people.length > 0) { people.map(function (person) { if (person.picture && person.picture.href) { person.pictureHref = person.picture.href; } else { person.pictureHref = null; } person.year = (today.getFullYear() - person.birthDate.split("-")[0]); person.birthDayMessage = "Joyeux anniversaire " + person.firstName + " " + person.lastName.slice(0, 1) + ". ! " + person.year + " ans seulement ! :cake: "; }); } getSeniorityAnniversary(people); }).catch(function (error) { console.log(error); }); |
Finish by completing the last action that will be sending the results to one of your Slack channels.
Choose the option “Send Channel Message”
To carry on with the next step, please sign in with your Slack account login details. Then, complete the options, starting with naming your channel:
Once the channel name has been entered you will have to enter the message you want to display.
Feel free to use the text in the example below.
To finish the set-up, validate this step and run the tests.
zap launch
You can launch the zap by switching the “OFF” button to “ON”.
Every morning at 7 am, Slack will be giving you the list of the daily absences.