Created
September 28, 2020 01:56
-
-
Save MattSandy/b408ea86b8699751b2f8bc4ba3d43253 to your computer and use it in GitHub Desktop.
Checks Tacocat for when burritos are available for order.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Twilio Credentials | |
const accountSid = "accountSid"; | |
const authToken = "authToken"; | |
//require the Twilio module and create a REST client | |
const client = require("twilio")(accountSid, authToken); | |
//END Twilio | |
const fetch = require("node-fetch"); | |
setInterval(() => { | |
check_if_available(); | |
}, 5000); | |
async function check_if_available() { | |
fetch("https://ws.toasttab.com/consumer-app-bff/v1/graphql", { | |
headers: { | |
accept: "*/*", | |
"accept-language": "en-US,en;q=0.9", | |
"apollographql-client-name": "takeout-web", | |
"apollographql-client-version": "336", | |
"cache-control": "no-cache", | |
"content-type": "application/json", | |
pragma: "no-cache", | |
"sec-fetch-dest": "empty", | |
"sec-fetch-mode": "cors", | |
"sec-fetch-site": "same-site", | |
"toast-customer-access": "", | |
}, | |
referrer: "https://www.toasttab.com/taco-cat/v3", | |
referrerPolicy: "no-referrer-when-downgrade", | |
body: | |
'[{"operationName":"RESTAURANT_INFO","variables":{"restaurantGuid":"1f64c1a7-e453-4dc6-900e-b8ef367904ee"},"query":"query RESTAURANT_INFO($restaurantGuid: ID!) {\\n restaurant(guid: $restaurantGuid) {\\n guid\\n whiteLabelName\\n description\\n imageUrl\\n bannerUrls {\\n raw\\n __typename\\n }\\n minimumTakeoutTime\\n minimumDeliveryTime\\n location {\\n address1\\n address2\\n city\\n state\\n zip\\n phone\\n latitude\\n longitude\\n __typename\\n }\\n logoUrls {\\n small\\n __typename\\n }\\n schedule {\\n asapAvailableForTakeout\\n todaysHoursForTakeout {\\n startTime\\n endTime\\n __typename\\n }\\n __typename\\n }\\n socialMediaLinks {\\n facebookLink\\n twitterLink\\n instagramLink\\n __typename\\n }\\n giftCardLinks {\\n purchaseLink\\n checkValueLink\\n addValueEnabled\\n __typename\\n }\\n giftCardConfig {\\n redemptionAllowed\\n __typename\\n }\\n specialRequestsConfig {\\n enabled\\n placeholderMessage\\n __typename\\n }\\n spotlightConfig {\\n headerText\\n bodyText\\n __typename\\n }\\n curbsidePickupConfig {\\n enabled\\n __typename\\n }\\n popularItemsConfig {\\n enabled\\n __typename\\n }\\n upsellsConfig {\\n enabled\\n __typename\\n }\\n creditCardConfig {\\n amexAccepted\\n tipEnabled\\n __typename\\n }\\n __typename\\n }\\n}\\n"},{"operationName":"DINING_OPTIONS","variables":{"input":{"restaurantGuid":"1f64c1a7-e453-4dc6-900e-b8ef367904ee","includeBehaviors":[]}},"query":"query DINING_OPTIONS($input: DiningOptionsInput!) {\\n diningOptions(input: $input) {\\n guid\\n behavior\\n deliveryProvider {\\n provider\\n __typename\\n }\\n asapSchedule {\\n availableNow\\n availableAt\\n __typename\\n }\\n futureSchedule {\\n dates {\\n date\\n timesAndGaps {\\n ... on FutureFulfillmentTime {\\n time\\n __typename\\n }\\n ... on FutureFulfillmentServiceGap {\\n description\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n}\\n"},{"operationName":"RESTAURANT_SPOTLIGHT","variables":{"restaurantGuid":"1f64c1a7-e453-4dc6-900e-b8ef367904ee"},"query":"query RESTAURANT_SPOTLIGHT($restaurantGuid: ID!) {\\n restaurant(guid: $restaurantGuid) {\\n spotlightConfig {\\n headerText\\n bodyText\\n __typename\\n }\\n __typename\\n }\\n}\\n"},{"operationName":"GIFT_CARD_LINKS","variables":{"guid":"1f64c1a7-e453-4dc6-900e-b8ef367904ee"},"query":"query GIFT_CARD_LINKS($guid: ID!) {\\n restaurant(guid: $guid) {\\n giftCardLinks {\\n purchaseLink\\n checkValueLink\\n addValueEnabled\\n __typename\\n }\\n __typename\\n }\\n}\\n"},{"operationName":"RESTAURANT_LOGO","variables":{"guid":"1f64c1a7-e453-4dc6-900e-b8ef367904ee"},"query":"query RESTAURANT_LOGO($guid: ID!) {\\n restaurant(guid: $guid) {\\n logoUrls {\\n small\\n __typename\\n }\\n __typename\\n }\\n}\\n"}]', | |
method: "POST", | |
mode: "cors", | |
}) | |
.then((res) => res.json()) | |
.then(async (json) => { | |
let dining = json.filter((obj) => { | |
return obj.data.hasOwnProperty("diningOptions"); | |
})[0].data.diningOptions; | |
let available = dining.filter((obj) => { | |
return obj.behavior == "DELIVERY"; | |
})[0].asapSchedule.availableNow; | |
if (available) { | |
await send_message("5555555555", "🌯 Burritos Available"); | |
process.exit(); | |
} | |
}); | |
} | |
async function send_message(phone, message) { | |
await client.messages | |
.create({ | |
body: message, | |
from: "+15555555555", | |
to: "+1" + phone, | |
}) | |
.then((message) => console.log(message.sid)); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment