A Google App Script-based bot to manage advent-of-code Slack interactions
npm@3+- A Google account
- Being administrator of your Slack channel (or knowing the admin as you will have to register the bot on it)
- This repository being cloned somewhere on your filesystem
-
cdtoadvent-of-code-slack-bot/directory then runnpm installon it -
Authenticate with
clasp(google app script CLI) withnpx clasp login(follow instructions)
Note:claspis a CLI to manage your Google App Scripts, and it's powered by Google (more infos here) -
Enable app script API here : https://script.google.com/home/usersettings
-
Run
npx clasp create --type api: a new google app script should be created under your google account. Publish keys for this script are going to be set into a.clasp.jsonprivate file :⚠️ don't commit this file otherwise people will have access to your script ! -
Run
npx clasp push(ornpx clasp push --watchif you want to edit/auto-deploy some changes made to the script)Manifest file has been updated. Do you want to push and overwrite?=> Answer "Yes" here Files are going to be compiled and pushed into your Google App Script.
-
Run
npx clasp deploy: a new version of your API is going to be made available on the internet -
Open your app script by running
npx clasp open- Once opened, click on the "play" button in order to try to execute doPost function
- By executing this, you should have an
Authorization requiredpopup : examine and grant authorizations to your current google account Note that if you get a "This application has not been validated (yet) by Google" error, click onAdvanced parametersand proceed to the page (unsecure content) - There may have some errors executing doPost : don't worry that's expected (purpose was only to grant authorization to your user)
- Open the
Publish > Deploy as web appmenu - In the popup, copy
Current Web appURL : this is going to be your HTTP entrypoint for the Bot
⚠️ Avoid sharing this URL too widely, as anyone having access to this URL will be able to control the Bot and cheat :-) - Open
File > Project Propertiesand select theScript Propertiestab then create following properties / values :
Property name Value Meaning LOG_ENABLED true This can be helpful to see logs, particularly at the beginning SLACK_CHALLENGE_ACTIVATED true Put this to true in order to allow Slack bot challenge ADVENT_OF_CODE_PRIVATE_LEADERBOARD_CODE Use your advent of code private leaderboard code (integer) here ADVENT_OF_CODE_SESSION_COOKIE Introspect queries made to advent of code to extract your session cookie value (in headers) and put it here
- As a Slack administrator, open your Slack App page here
- Click on
Create New Appbutton to create a new Application
- Fill App Creation popup and reference the Slack Workspace

- Once done, and from
Basic Informationscreen, open theEvent subscriptionsconfiguration page
- Activate events and paster Google App Script's Slack Bot URL you copied previously :
- Wait for Google App Script challenge verification : if there is a failure, review Google App Script's
SLACK_CHALLENGE_ACTIVATEDproject property to ensure this is valued totrueand verify that GAS execution authorization has been granted. - Declare 1
bot eventsdescribed in screenshot above :message.channels - Don't forget to save changes
- Wait for Google App Script challenge verification : if there is a failure, review Google App Script's
- Once done, navigate to
OAuth & Permissionssection
- In
Scopessection, there should already bechannels:history; Addchannels:joinandchat:write
- Once done, click on
Install App to Workspacebutton on top of the screen, and validate permissions configured previously
- Copy generated
Bot User OAuth Access Token...
- ... and paste it into Google App Script's
SLACK_ACCESS_TOKENProject Properties. At the same time, disableSLACK_CHALLENGE_ACTIVATEDflag.
- In
- Move to the
slack-sheet/directory then runnpm installon it - Run
npx clasp create --type sheets: a new google spreadsheet & app script should be created under your google account. - Run
npx clasp push(ornpx clasp push --watchif you want to edit/auto-deploy some changes made to the script)Manifest file has been updated. Do you want to push and overwrite?=> Answer "Yes" here Files are going to be compiled and pushed into your Google App Script.
- In the spreadsheet, put following formula in a cell :
=SAY_HELLO(): this will call code defined into yourmain/index.tstypescript file and can be useful if you would have to generate complex data into your spreadsheet.
- Open Slack and invite the bot into one of your channels (prefer to choose a testing channel to begin with) :
/invite @<bot_name> - Channel help can be displayed by saying
!help

