Before starting
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 "Create a zap" button takes you to this page, where you have to choose a "Trigger". 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 should complete the "Input" sections first, by replacing the "xxx" with your information.
- The first key is the URL and for the value replace the "xxx" with the Lucca instance name
- The second key is appToken and for the value replace the "xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx" with your Lucca API key.
Please note: the API key to use is a Lucca API key and you must give it the permission to "view Lucca data".
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 = []; if(monthS=="02" && dayS == "29") { 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 + " years 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 = "Happy Birthday" + person.firstName + " " + person.lastName.slice(0, 1) + ". ! " + person.year + " years only! :cake: "; }); } getSeniorityAnniversary(people); }).catch(function (error) { console.log(error); }); |
Important: the test must be performed on a day when at least one user has their birthday.
The Javascript code test will not work if you have an IP address restriction on your Lucca instance.
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 then enter your text. You can use this example for your configuration:
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".