Skip to content

Instantly share code, notes, and snippets.

@beveradb
Created May 20, 2023 03:47
Show Gist options
  • Save beveradb/a816721cf9347b9e047498564ed40d06 to your computer and use it in GitHub Desktop.
Save beveradb/a816721cf9347b9e047498564ed40d06 to your computer and use it in GitHub Desktop.
Cat facts SMS text number Twilio function, for random fun stickers around Austin!
const request = require('request');
const responsePrefix = "Here's your random cat fact! - ";
const responseSuffix = " - For more cat facts, text again! To learn more, or if you're interested in learning to code, text Andrew on 803-636-3267."
const catFacts = [
"Cats have been domesticated for over 4,000 years.",
"The average lifespan of a cat is around 15 years.",
"Cats use their whiskers to determine if they can fit through a space.",
"A group of cats is called a clowder.",
"Cats have five toes on their front paws and four on their back paws.",
"The oldest cat on record lived to be 38 years old.",
"Cats have retractable claws.",
"Cats have a specialized collarbone that allows them to always land on their feet when they fall.",
"The world's largest cat measured over 48 inches long.",
"Cats have a third eyelid called a haw.",
"A cat's nose is as unique as a human's fingerprint.",
"Cats have five different types of vocalizations: meow, purr, chirp, hiss, and growl.",
"A cat's nose pad is ridged with a unique pattern, similar to a human's fingerprint.",
"Cats have excellent night vision due to a layer of tissue behind their retinas called the tapetum lucidum.",
"The average cat sleeps for 12-16 hours a day.",
"Cats have a specialized grooming tool on their tongues called papillae.",
"The average cat can jump up to six times its body length in one leap.",
"Cats have 32 muscles in each ear, allowing them to rotate their ears 180 degrees.",
"Cats have a specialized collarbone that allows them to squeeze through tight spaces.",
"A cat's brain is 90% similar to a human's brain.",
"A cat's nose is cool and wet to help them detect scents better.",
"The world's smallest cat breed is the Singapura, weighing between 4-8 pounds.",
"Cats have five toes on their front paws but only four on their back paws.",
"The average cat has a vocabulary of over 100 different sounds.",
"Cats have a unique sense of balance due to their inner ear.",
"The largest litter of kittens ever recorded was 19.",
"A cat's hearing is much more sensitive than a human's.",
"Cats have a specialized grooming claw on their front paws called a dewclaw.",
"The average cat spends 30% of its waking hours grooming itself.",
"Cats have a specialized tongue that helps remove loose fur and dirt from their coats.",
"A cat's nose is lined with scent receptors, allowing them to detect odors more effectively.",
"The world's oldest cat breed is the Egyptian Mau, dating back over 3,000 years.",
"Cats have a heightened sense of hearing compared to humans.",
"A cat's tail helps with balance and communication.",
"The average cat has 12 whiskers on each side of its face.",
"Cats have a specialized sensory organ located on the roof of their mouths called the vomeronasal organ.",
"Cats have a natural instinct to hunt and capture prey.",
"The world's fastest recorded cat speed is 48 miles per hour.",
"Cats have a specialized muscle that allows them to rotate their front paws inward when walking.",
"A cat's nose is unique to each individual, similar to a human's fingerprint.",
"Cats have a highly developed sense of smell, even better than dogs.",
"A cat's purring has been shown to have therapeutic benefits for humans, reducing stress and promoting healing.",
"Cats have five toes on their front paws but can have four or even three on their back paws.",
"The world's most expensive cat breed is the Ashera, with prices ranging up to $125,000.",
"A cat's eyesight is best in low light conditions, allowing them to see in the dark.",
"Cats have a specialized grooming behavior called allogrooming, where they groom other cats as a form of social bonding.",
"The average cat has 230 bones in its body.",
"A cat's whiskers are roughly as wide as its body, helping them determine if they can fit through a space.",
"Cats have a unique collarbone structure that allows them to maintain balance while running or jumping.",
"The world's oldest cat on record lived to be 38 years and 3 days old.",
"Cats have a specialized toe pad on their paws called a carpal pad, which helps with traction.",
"A cat's pupils can dilate to three times their normal size, allowing them to see better in dim light.",
"Cats have a unique ability to rotate their ears independently, allowing them to pinpoint the source of a sound.",
"The average cat has a heart rate of 140-220 beats per minute.",
"Cats have a highly developed sense of taste, but they cannot taste sweetness.",
"A cat's tail acts as a communication tool, signaling emotions such as fear, happiness, and aggression.",
"Cats have a specialized grooming technique called tongue-bathing, which helps keep their fur clean and tangle-free.",
"The world's largest breed of domestic cat is the Maine Coon, with males weighing up to 25 pounds.",
"A cat's sense of smell is 14 times stronger than a human's.",
"Cats have a specialized claw on their front paws called a dewclaw, which is similar to a thumb and helps with gripping.",
];
function handler (context, event, callback) {
const from = event.From || 'UnknownFrom';
const to = event.To || 'UnknownTo';
const body = event.Body || 'UnknownBody';
const pushbulletApiKey = context.PUSHBULLET_API_KEY;
const now = new Date();
const secs = now.getSeconds();
const randomFact = catFacts[secs];
console.log("Random fact chosen using current datetime: " + now.toISOString() + " seconds: " + secs + ": " + randomFact);
const responseText = responsePrefix + randomFact + responseSuffix
console.log("Proceeding to send pushbullet message");
// Send a push notification to Andrew's Pushbullet account
request.post({
url: 'https://api.pushbullet.com/v2/pushes',
headers: {
'Access-Token': pushbulletApiKey,
'Content-Type': 'application/json'
},
body: JSON.stringify({
type: 'note',
title: 'Cat fact requested!',
body: 'Someone requested a cat fact. Meow! From: ' + from + ', Message: ' + body + ' || and this is the fact they received! - ' + randomFact,
})
}, function(error, response, body) {
console.log("Got pushbullet response");
if (error) {
console.error("Error during pushbullet post: " + error);
}
console.log("Ending, calling callback to sent SMS response");
const twiml = new Twilio.twiml.MessagingResponse();
twiml.message(responseText);
callback(null, twiml);
});
}
exports.handler = handler;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment