Before you get started
To wish someone a happy birthday and celebrate years of seniority automatically on Slack, you can use Zapier to do this easily and quickly.
Important information: a paid Zapier account is required.
or
Zap configuration
You need to configure the first step. The "Make a zap" button offers you a list of available tools. You can then choose "Schedule".
You will then be asked to configure your clock. First by asking yourself how often you want the script to run, e.g. every day.
You can then choose what time of day the script will run, and whether or not you want it to run on weekends.
Once this step has been validated, you can then launch the tests for this step with the final "Test trigger" tab.
For the second step, i.e. the action step, we will choose the "Code by Zapier" application.
Choose JavaScript
You will first need to fill in the "Input" parts as below:
By replacing the "xxx" with your information.
- In the URL box, replace the "xxx" with the name of the Lucca instance
You can then copy the code below in the "Code" part:
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;="70;" yearshift++)="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) + ". already " + result.year + " year with us! :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 + " years only! :cake: "; }); } getSeniorityAnniversary(people); }).catch(function (error) { console.log(error); }); |
You just have to configure the last action that will send the results to one of your Slack channels.
Choose the "Send Channel Message" option
For the next step, log in with your Slack account login details. Then complete the options, starting with the channel name:
Once the name of the channel has been entered, you will have to enter the message you want to display.
You can take the text from the example below.
All you have to do now is validate this step and run the tests to complete the configuration.
Launching zap
You can start zap by pressing the "OFF" button to switch it to "ON".
Every morning at 7 am, Slack gives you the list of today's birthdays.