🏃‍♂️ Automated Advent Calendar

Hey Makers :wave:

:snowflake: Over here in Europe, the pre-holiday season is hitting hard. :snowflake:

Decorations, Wham, and Mariah Carey on every corner.
People shopping for presents and sipping hot wine in the streets.
What a beautiful and messy time!

Looking for something to occupy yourself with while waiting for the holidays?
At Make, we built our own automated Advent calendar!

:make: Make Advent Calendar :make:

:candy: In our office, we have a snack bar that contains all kinds of treats.

:spiral_calendar: Since a couple of days ago, we also have an Advent Calendar scenario running that assigns a random treat from the snack bar to anyone who types a specific keyword into Slack.

:gift_heart: Once you do that - bam - an Advent Bot tells you exactly what you should treat yourself with and makes sure to never offer you the same snack.

:coconut: In a nutshell, this is what happens :coconut:

  • At 8 am, a Slack bot sends an automated message with a countdown till the holidays & a fitting seasonal proverb to our #Advent channel.
  • A user comes in to check out the proverb and types in a key phrase “open a window” in order to get a surprise treat.
  • A random snack is assigned to the user without any chance of them getting the same item more than once.
  • The message that assigns the snack features the user’s name so that it’s clear who should grab what.
  • The message also contains an image of the snack so that you know what you’re supposed to be looking for.

We scheduled the scenario and watched the festive spirit intensify.

:hammer_and_wrench: How we built it :hammer_and_wrench:

What you need

:envelope_with_arrow: a Slack channel

:robot: Integromat app invited into the Slack channel in order to use a bot message

:memo: 2 data stores (one for snack bar items, one to keep track of snacks that have been assigned to each user)

:face_with_peeking_eye: What happens behind the scenes :face_with_peeking_eye:

  1. ‘New Event’ Slack module listens for all new messages in the channel.

  2. A filter checks whether the new messages contain the key phrase (‘open a window’).

  3. ‘Get a User’ Slack module outputs the full name of the user.

  4. Data store checks for all items the user already ate and aggregates them into an array.

  5. The array of snacks from the previous step is converted into a string using the function join.

  1. The data store outputs all the items and a filter passes only those that are not included in the string thanks to a text operator “does not contain”.

  2. All items which passed the filter are aggregated into an array.

  3. Functions “get" :arrow_right: general function, “map”, and “shuffle” :arrow_right: array functions select a random item from the aggregated array.

  1. Data store is searched for the selected item and outputs additional info saved in the data store (in this case, a link to the picture of the snack)

  2. A new record of the user name and the item are created in the second datastore which ensures the user cannot get the same item in the future.

  3. A bot message with the username, a random item, and additional info is sent into the channel.