Skip to content

Instantly share code, notes, and snippets.

@dbredvick

dbredvick/text.ts

Created Jan 12, 2020
Embed
What would you like to do?
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
.create({
body: `\n
Create your todo list the night before with categories:
\n- Work
\n- Health
\n- Relationships
\n- Self Improvement
\n
\n Get better every day: https://jamesclear.com/continuous-improvement`,
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();
}
}
@dbredvick

This comment has been minimized.

Copy link
Owner Author

@dbredvick dbredvick commented Jan 12, 2020

Don't forget, never commit your secrets to source code 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.