I found a new best feeling ever! Pranking your non-tech friends with code.
I always wanted to try Twilio, but I wasn't motivated to do so until a meme that recently went viral. A chicken screaming while sitting in a tree.
For those who don't know what I am talking about, here is the video.
When I got spammed on Instagram by my friends with this chicken scamming meme, I decided to get back to them. So I created a quick Twilio-powered app that will call the phone number you provide and play a chicken-screaming sound.
Let's see how I did it!
Prerequisites
- A free Twilio account
- Node JS Installed
Creating the app
Create a new project and install this dependency.
npm install twilio dotenv express
Create an index.js file and copy this code into it.
require('dotenv').config();
const twilio = require('twilio')(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);
const MP3Url = 'https://chickensound-1470.twil.io/ch.mp3'; // Hosted MP3 file URL
async function createCall() {
const call = await twilio.calls.create({
from: process.env.TWILIO_PHONE_NUMBER,
to: "number", // Replace with desired phone number. It should be verified by Twilio first.
twiml: `<Response> <Play> ${MP3Url} </Play> </Response>`,
});
}
createCall();
The code above is a Node.js script that uses Twilio to programmatically place a phone call and play an MP3 audio file when the call is answered. It loads Twilio credentials from environment variables that you will provide in a .env file and sends a call from your Twilio number to a specified phone number using TwiML.
You will find all the credentials in your Twilio console.
Running the code
After the above is done, just run node index.js in your terminal to execute the code. Within 5 seconds, the Twilio call with the chicken sound will be initiated.
Conclusion
While it's a simple app, it's a lot of fun to make you and your friends laugh.
Resources:
GitHub Repo: https://github.com/akshatvirmani/Chicken-Screaming-Prank-Twilio
Original Twilio Blog: https://www.twilio.com/en-us/blog/adding-mp3-voice-calls-twilio-nodejs

Top comments (0)