Sample application demonstrating Telnyx-Node SMS and MMS attachments
The full documentation and tutorial is available on developers.telnyx.com
You will need to set up:
- Telnyx Account
- Telnyx Phone Number enabled with:
- Ability to receive webhooks (with something like ngrok)
- Node & NPM installed
- AWS Account setup with proper profiles and groups with IAM for S3. See the Quickstart for more information.
- Previously created S3 bucket with public permissions available.
- Send an SMS or MMS and receive a copy of the attachments back to your phone number
- Upload a file to AWS S3
- Send those file as an MMS via Telnyx
The following environmental variables need to be set
Variable | Description |
---|---|
TELNYX_API_KEY |
Your Telnyx API Key |
TELNYX_PUBLIC_KEY |
Your Telnyx Public Key |
TELNYX_APP_PORT |
Defaults to 8000 The port the app will be served |
AWS_PROFILE |
Your AWS profile as set in ~/.aws |
AWS_REGION |
The region of your S3 bucket |
TELNYX_MMS_S3_BUCKET |
The name of the bucket to upload the media attachments |
This app uses the excellent dotenv package to manage environment variables.
Make a copy of .env.sample
and save as .env
and update the variables to match your creds.
TELNYX_API_KEY=
TELNYX_PUBLIC_KEY=
TENYX_APP_PORT=8000
AWS_PROFILE=
AWS_REGION=
TELNYX_MMS_S3_BUCKET=
Callback Type | URL |
---|---|
Inbound Message Callback | {ngrok-url}/messaging/inbound |
Outbound Message Status Callback | {ngrok-url}/messaging/outbound |
Run the following commands to get started
$ git clone https://github.com/d-telnyx/demo-node-telnyx.git
This application is served on the port defined in the runtime environment (or in the .env
file). Be sure to launch ngrok for that port
./ngrok http 8000
Terminal should look something like
ngrok by @inconshreveable (Ctrl+C to quit)
Session Status online
Account Little Bobby Tables (Plan: Free)
Version 2.3.35
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://your-url.ngrok.io -> http://localhost:8000
Forwarding https://your-url.ngrok.io -> http://localhost:8000
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
At this point you can point your application to generated ngrok URL + path (Example: http://{your-url}.ngrok.io/messaging/inbound
).
Start the server npm run start
When you are able to run the server locally, the final step involves making your application accessible from the internet. So far, we've set up a local web server. This is typically not accessible from the public internet, making testing inbound requests to web applications difficult.
The best workaround is a tunneling service. They come with client software that runs on your computer and opens an outgoing permanent connection to a publicly available server in a data center. Then, they assign a public URL (typically on a random or custom subdomain) on that server to your account. The public server acts as a proxy that accepts incoming connections to your URL, forwards (tunnels) them through the already established connection and sends them to the local web server as if they originated from the same machine. The most popular tunneling tool is ngrok
. Check out the ngrok setup walkthrough to set it up on your computer and start receiving webhooks from inbound messages to your newly created application.
Once you've set up ngrok
or another tunneling service you can add the public proxy URL to your Inbound Settings in the Mission Control Portal. To do this, click the edit symbol [✎] next to your Messaging Profile. In the "Inbound Settings" > "Webhook URL" field, paste the forwarding address from ngrok into the Webhook URL field. Add messaging/inbound
to the end of the URL to direct the request to the webhook endpoint in your server.
For now you'll leave “Failover URL” blank, but if you'd like to have Telnyx resend the webhook in the case where sending to the Webhook URL fails, you can specify an alternate address in this field.
Once everything is setup, you should now be able to:
- Text your phone number and receive a response!
- Send a picture to your phone number and get that same picture right back!