-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added comments to the send-messages.js file so that it's more compreh…
…ensive
- Loading branch information
Showing
10 changed files
with
380 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# Twilio Serverless | ||
.twiliodeployinfo | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
web_modules/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional stylelint cache | ||
.stylelintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variable files | ||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# vuepress v2.x temp and cache directory | ||
.temp | ||
.cache | ||
|
||
# Docusaurus cache and generated files | ||
.docusaurus | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode-test | ||
|
||
# yarn v2 | ||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
18 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"commands": {}, | ||
"environments": {}, | ||
"projects": {}, | ||
// "assets": true /* Upload assets. Can be turned off with --no-assets */, | ||
// "assetsFolder": null /* Specific folder name to be used for static assets */, | ||
// "buildSid": null /* An existing Build SID to deploy to the new environment */, | ||
// "createEnvironment": false /* Creates environment if it couldn't find it. */, | ||
// "cwd": null /* Sets the directory of your existing Serverless project. Defaults to current directory */, | ||
// "detailedLogs": false /* Toggles detailed request logging by showing request body and query params */, | ||
// "edge": null /* Twilio API Region */, | ||
// "env": null /* Path to .env file for environment variables that should be installed */, | ||
// "environment": "dev" /* The environment name (domain suffix) you want to use for your deployment. Alternatively you can specify an environment SID starting with ZE. */, | ||
// "extendedOutput": false /* Show an extended set of properties on the output */, | ||
// "force": false /* Will run deployment in force mode. Can be dangerous. */, | ||
// "forkProcess": true /* Disable forking function processes to emulate production environment */, | ||
// "functionSid": null /* Specific Function SID to retrieve logs for */, | ||
// "functions": true /* Upload functions. Can be turned off with --no-functions */, | ||
// "functionsFolder": null /* Specific folder name to be used for static functions */, | ||
// "inspect": null /* Enables Node.js debugging protocol */, | ||
// "inspectBrk": null /* Enables Node.js debugging protocol, stops execution until debugger is attached */, | ||
// "legacyMode": false /* Enables legacy mode, it will prefix your asset paths with /assets */, | ||
// "live": true /* Always serve from the current functions (no caching) */, | ||
// "loadLocalEnv": false /* Includes the local environment variables */, | ||
// "loadSystemEnv": false /* Uses system environment variables as fallback for variables specified in your .env file. Needs to be used with --env explicitly specified. */, | ||
// "logCacheSize": null /* Tailing the log endpoint will cache previously seen entries to avoid duplicates. The cache is topped at a maximum of 1000 by default. This option can change that. */, | ||
// "logLevel": "info" /* Level of logging messages. */, | ||
// "logs": true /* Toggles request logging */, | ||
// "ngrok": null /* Uses ngrok to create a public url. Pass a string to set the subdomain (requires a paid-for ngrok account). */, | ||
// "outputFormat": "" /* Output the results in a different format */, | ||
// "overrideExistingProject": false /* Deploys Serverless project to existing service if a naming conflict has been found. */, | ||
// "port": "3000" /* Override default port of 3000 */, | ||
// "production": false /* Promote build to the production environment (no domain suffix). Overrides environment flag */, | ||
// "properties": null /* Specify the output properties you want to see. Works best on single types */, | ||
// "region": null /* Twilio API Region */, | ||
"runtime": "node18" /* The version of Node.js to deploy the build to. (node18) */, | ||
// "serviceName": null /* Overrides the name of the Serverless project. Default: the name field in your package.json */, | ||
// "serviceSid": null /* SID of the Twilio Serverless Service to deploy to */, | ||
// "sourceEnvironment": null /* SID or suffix of an existing environment you want to deploy from. */, | ||
// "tail": false /* Continuously stream the logs */, | ||
// "template": null /* undefined */, | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
<link rel="stylesheet" href="./style.css" /> | ||
<title>Hello Twilio Serverless!</title> | ||
</head> | ||
<body> | ||
<header><h1>Hello Twilio Serverless!</h1></header> | ||
|
||
<main> | ||
<p> | ||
<strong>Congratulations</strong> you just started a new Twilio | ||
Serverless project. | ||
</p> | ||
|
||
<h2>Assets</h2> | ||
<p> | ||
Assets are static files, like HTML, CSS, JavaScript, images or audio | ||
files. | ||
</p> | ||
|
||
<p> | ||
This HTML page is an example of a <strong>public</strong> asset, you can | ||
access this by loading it in the browser. The HTML also refers to | ||
another public asset for CSS styles. | ||
</p> | ||
<p> | ||
You can also have <strong>private</strong> assets, there is an example | ||
private asset called <code>message.private.js</code> in the | ||
<code>/assets</code> directory. This file cannot be loaded in the | ||
browser, but you can load it as part of a function by finding its path | ||
using <code>Runtime.getAssets()</code> and then requiring the file. | ||
There is an example of this in | ||
<code>/functions/private-message.js</code>. | ||
</p> | ||
|
||
<h2>Functions</h2> | ||
<p> | ||
Functions are JavaScript files that will respond to incoming HTTP | ||
requests. There are <strong>public</strong> and | ||
<strong>protected</strong> functions. | ||
</p> | ||
|
||
<p> | ||
<strong>Public</strong> functions respond to all HTTP requests. There is | ||
an example of a public function in | ||
<code>/functions/hello-world.js</code>. | ||
</p> | ||
|
||
<p> | ||
<strong>Protected</strong> functions will only respond to HTTP requests | ||
with a valid Twilio signature in the header. You can read more about | ||
<a href="https://www.twilio.com/docs/usage/security#validating-requests" | ||
>validating requests from Twilio in the documentation</a | ||
>. There is an example of a protected function in | ||
<code>/functions/sms/reply.protected.js</code> | ||
</p> | ||
|
||
<h2>twilio-run</h2> | ||
|
||
<p> | ||
Functions and assets are served, deployed and debugged using | ||
<a href="https://github.com/twilio-labs/twilio-run" | ||
><code>twilio-run</code></a | ||
>. You can serve the project locally with the command | ||
<code>npm start</code> which is really running | ||
<code>twilio-run --env</code> under the hood. If you want to see what | ||
else you can do with <code>twilio-run</code> enter | ||
<code>npx twilio-run --help</code> on the command line or check out | ||
<a href="https://github.com/twilio-labs/twilio-run" | ||
>the project documentation on GitHub</a | ||
>. | ||
</p> | ||
</main> | ||
|
||
<footer> | ||
<p> | ||
Made with 💖 by your friends at | ||
<a href="https://www.twilio.com">Twilio</a> | ||
</p> | ||
</footer> | ||
</body> | ||
</html> |
6 changes: 6 additions & 0 deletions
6
sms-notifications/sms-notifications/assets/message.private.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// This is an example of of a private message | ||
const privateMessage = () => { | ||
return 'This is private!'; | ||
}; | ||
|
||
module.exports = privateMessage; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
|
||
::selection { | ||
background: #f22f46; | ||
color: white; | ||
} | ||
|
||
body { | ||
font-family: -apple-system, system-ui, BlinkMacSystemFont, 'Segoe UI', Roboto, | ||
'Helvetica Neue', Arial, sans-serif; | ||
color: #0d122b; | ||
border-top: 5px solid #f22f46; | ||
} | ||
|
||
header { | ||
padding: 2em; | ||
margin-bottom: 2em; | ||
max-width: 800px; | ||
margin: 0 auto; | ||
} | ||
|
||
header h1 { | ||
padding-bottom: 14px; | ||
border-bottom: 1px solid rgba(148, 151, 155, 0.2); | ||
} | ||
|
||
a { | ||
color: #008cff; | ||
} | ||
|
||
main { | ||
margin: 0 auto 6em; | ||
padding: 0 2em; | ||
max-width: 800px; | ||
} | ||
|
||
main p { | ||
margin-bottom: 2em; | ||
} | ||
|
||
main p code { | ||
font-size: 16px; | ||
font-family: 'Fira Mono', monospace; | ||
color: #f22f46; | ||
background-color: #f9f9f9; | ||
box-shadow: inset 0 0 0 1px #e8e8e8; | ||
font-size: inherit; | ||
line-height: 1.2; | ||
padding: 0.15em 0.4em; | ||
border-radius: 4px; | ||
display: inline-block; | ||
white-space: pre-wrap; | ||
} | ||
|
||
main h2 { | ||
margin-bottom: 1em; | ||
} | ||
|
||
footer { | ||
margin: 0 auto; | ||
max-width: 800px; | ||
text-align: center; | ||
} | ||
|
||
footer p { | ||
border-top: 1px solid rgba(148, 151, 155, 0.2); | ||
padding-top: 2em; | ||
margin: 0 2em; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
exports.handler = function(context, event, callback) { | ||
const twiml = new Twilio.twiml.VoiceResponse(); | ||
twiml.say('Hello World!'); | ||
callback(null, twiml); | ||
}; |
9 changes: 9 additions & 0 deletions
9
sms-notifications/sms-notifications/functions/private-message.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
exports.handler = function(context, event, callback) { | ||
const assets = Runtime.getAssets(); | ||
const privateMessageAsset = assets['/message.js']; | ||
const privateMessagePath = privateMessageAsset.path; | ||
const privateMessage = require(privateMessagePath); | ||
const twiml = new Twilio.twiml.MessagingResponse(); | ||
twiml.message(privateMessage()); | ||
callback(null, twiml); | ||
}; |
5 changes: 5 additions & 0 deletions
5
sms-notifications/sms-notifications/functions/sms/reply.protected.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
exports.handler = function(context, event, callback) { | ||
const twiml = new Twilio.twiml.MessagingResponse(); | ||
twiml.message('Hello World!'); | ||
callback(null, twiml); | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "sms-notifications", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"start": "twilio-run", | ||
"deploy": "twilio-run deploy" | ||
}, | ||
"dependencies": { | ||
"twilio": "5.0.3", | ||
"@twilio/runtime-handler": "2.0.3" | ||
}, | ||
"devDependencies": { | ||
"twilio-run": "^4.0.3" | ||
}, | ||
"engines": { | ||
"node": "18" | ||
} | ||
} |