You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Error Handling in Dev Server](#error-handling-in-dev-server)
34
+
-[Contributing](#contributing)
35
+
-[Code of Conduct](#code-of-conduct)
36
+
-[Contributors](#contributors)
37
+
-[License](#license)
34
38
35
39
## About
36
40
@@ -54,18 +58,68 @@ npx twilio-run
54
58
55
59
## Usage
56
60
61
+
Check out the [commands](#commands) for in depth usage, but here are some things you will want to know:
62
+
63
+
### Create a new project
64
+
65
+
To create a new project with the Twilio Serverless Toolkit you can use [`create-twilio-function`](https://github.com/twilio-labs/create-twilio-function/) which will scaffold a new project that is ready to be used with `twilio-run`.
66
+
57
67
```bash
58
68
# Create a valid project, for example:
59
-
npx create-twilio-function my-project
69
+
npm init twilio-function my-project
60
70
61
71
# Navigate into project
62
72
cd my-project
73
+
```
63
74
64
-
# Start local development server
65
-
twilio-run start
75
+
You can then use `twilio-run` to run a local development server to serve your functions and assets.
66
76
67
-
# Deploy to Twilio
68
-
twilio-run deploy
77
+
```bash
78
+
npx twilio-run start
79
+
```
80
+
81
+
### Project conventions
82
+
83
+
By default JavaScript Functions should be placed in the `functions` directory and assets, which can be JavaScript, images, CSS, or any static asset, should be placed in the `assets` directory. You can choose other directories by providing a `--functions-folder` or `--assets-folder` option to `twilio-run` commands.
84
+
85
+
Twilio Functions and Assets can be public, protected or private. The differences are:
86
+
87
+
***Public**: Any one with the URL can visit the Function or Asset
88
+
***Protected**: Twilio signs webhook requests, making a Twilio Function protected means that the Function will validate the webhook signature and reject any incoming requests that don't match
89
+
***Private**: The Function or Asset doesn't a URL, it can only be required within another Function or Asset
90
+
91
+
Within `twilio-run` you can make your Functions or Assets public, protected or private by adding to the function filename. Functions and Assets are public by default. To make a Function or Asset protected or private, add `.protected` or `.private` to the filename before the extension. For example: `functions/secret.protected.js` or `assets/hidden.private.jpg`.
92
+
93
+
### Function templates
94
+
95
+
There are a number of pre-written Function templates that you can add to your project. The [templates are available on GitHub](https://github.com/twilio-labs/function-templates) and you can also propose your own via pull request.
96
+
97
+
To list the available templates you can run:
98
+
99
+
```bash
100
+
npx twilio-run list-templates
101
+
```
102
+
103
+
To add a new function into your project from a template you can run:
104
+
105
+
```bash
106
+
npx twilio-run new namespace
107
+
```
108
+
109
+
The command will walk you through choosing the template.
110
+
111
+
### Deploy a project
112
+
113
+
To deploy a project to the Twilio infrastructure you can run the command:
114
+
115
+
```bash
116
+
npx twilio-run deploy
117
+
```
118
+
119
+
This will deploy your project to the "dev" environment by default. You can then promote the project from "dev" to other environments with the command:
0 commit comments