Skip to content

Instantly share code, notes, and snippets.

Created January 12, 2020 00:22
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dbredvick/602e398b61ac960e326fdd45dab67f3d to your computer and use it in GitHub Desktop.
NextJS Twilio Typescript example
import { NextApiResponse, NextApiRequest } from "next";
const twillio = require('twilio');
const authToken = process.env.TWILIO_AUTH_TOKEN;
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const myCellPhoneNumber = process.env.MY_NUMBER;
const superSecretAPIKey = 'ABCD1234';
export default async (req: NextApiRequest, res: NextApiResponse) => {
const client = twillio(accountSid, authToken);
const auth = req.headers.authorization;
if (auth === superSecretAPIKey) {
await client.messages
body: `\n
Create your todo list the night before with categories:
\n- Work
\n- Health
\n- Relationships
\n- Self Improvement
\n Get better every day:`,
from: '+12694754126', // my twilio testing number
to: `+1${myCellPhoneNumber}`
.then((message: String) => res.json(message), (err: Error) => res.json(err));
} else {
return res.status(401).end();
Copy link

Update: I use tryslater for cron jobs in Next.js now instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment