Add birthdays in Slack

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. 

mceclip0.png
or

mceclip1.png

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".

Capture_d__cran_2020-12-16___16.51.49.png

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.

Capture_d__cran_2020-12-16___16.52.19.png

You can then choose what time of day the script will run, and whether or not you want it to run on weekends.

Capture_d__cran_2020-12-16___16.53.07.png

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.

Capture_d__cran_2020-12-16___16.55.13.png

Choose JavaScript

Capture_d__cran_2020-12-16___16.55.34.png

You will first need to fill in the "Input" parts as below:

image__1___2_.png

By replacing the "xxx" with your information.

- In the URL box, replace the "xxx" with the name of the Lucca instance

Capture_d__cran_2020-12-17___11.09.04.png

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 = [];

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.

Capture_d__cran_2020-12-16___17.20.19.png

Choose the "Send Channel Message" option

Capture_d__cran_2020-12-16___17.20.35.png

For the next step, log in with your Slack account login details. Then complete the options, starting with the channel name:

Capture_d__cran_2020-12-16___17.21.16.png

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.

mceclip6.png

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".

mceclip7.png

Every morning at 7 am, Slack gives you the list of today's birthdays.

Page content

Was this article helpful?
1 out of 1 found this helpful