A Cypress bot to book restaurants on Tock and optionally report attempts to Slack.
Ensure your computer has node
and npm
installed. You can use nodenv if you don't. Once installed, use npm install
to pull down the dependencies for the project. Before you can run the bot, you'll also need to configure it. Read on to the next section for how to do that.
If you don't already have an account on Tock, make one. Once you've created your account, take note of your credentials as you'll need them in a bit. Next, navigate to your account billing page and ensure you have a credit card on file. Take note of the CVV number for the card.
Next go find the restaurant you'd like to book, and grab the path for the booking page. In the example above, that would be:
/otiumgrillandgreens/experience/330688/reservation
Last but not least, if you want to use Slack, create an incoming webhook for your Slack account. This will be the endpoint the runner uses to send notifications to the slack room of your choice.
With all this in-hand, you can create your configuration file. There's an example in the repo you can start with, though you'll need to create a real one named cypress.env.json
in the project root:
cp cypress.env.example.json cypress.env.json
open cypress.env.json
The fields are all pretty self explanatory, though you can use dryRun
to avoid actually booking if you just want to test the whole thing out. The only optional fields are those related to slack*
, which you can omit if you don't want to send notifications to slack.
A lot of restaurants set their next month's schedule on a particular day and time. You can use github actions to
schedule jobs on a cron and try to snag a spot as things open up. The example in this repo attempts bookings every 15 minutes. You can fork the repo and try it out yourself. Just be sure to set a secret CYPRESS_ENV
with the above JSON so that the action will run.
Tock uses Cloudflare's bot detection system, Turnstile, to prevent automated access to their site. Thankfully, Cypress is pretty good about presenting itself as a human. The only times it runs into issues is when Cypress runs in "studio" mode, which unfortunately is the default mode for developers using Cypress (i.e. cypress open
).
The underlying issue is that Cypress studio runs its end to end tests in an iframe, which Turnstile immediately flags as a bot. To avoid this, the bot is set up to run in a frameless mode (i.e. cypress run
), but can still run in "headed" mode for local development. In the end, this change to the normal working style of Cypress is a small price to pay for the convenience of automated booking.