Add birthdays in Slack

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. 

chrome_2017-08-11_14-28-39.png
or

chrome_2017-08-11_14-28-45.png

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

1_create-a-zap_full_en.png

2_choose-schedule_en.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.

3_event-periodicity_en.png

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

4_setting-trigger_en.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.

5_choosing-code_en.png

Choose Javascript

6_choose-action_en.png

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

7_setting-action_en.png

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

if(monthS=="02" && dayS == "29") {
    increment = 4;
}
for (var yearShift = increment ; yearShift <= 70; yearShift+=increment) {

    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.

8_step-add_en.png

9_process-slack_en.png

Choose the "Send Channel Message" option

10_message-slack_en.png

For the next step, log in with your Slack account login details:

11_sign-in_en.png

Then complete the options, starting with the channel name then enter your text. You can use this example for your configuration:

12_setup-sending-message_en.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".

13_start-zap_en.png

Page content

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