Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update express-messaging to typescript #21

Merged
merged 5 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/express-messaging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: CI

on:
push:
branches: [master]
paths:
- "express-messaging/**"
pull_request:
branches: [master]
paths:
- "express-messaging/**"

jobs:
type-check:
runs-on: ubuntu-latest
defaults:
run:
working-directory: express-messaging
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run type-check
9 changes: 9 additions & 0 deletions express-messaging/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
parserOptions: {
ecmaVersion: 6,
},
rules: {
'new-cap': 'off',
'no-console': 'off',
},
};
1 change: 1 addition & 0 deletions express-messaging/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.17.0
2 changes: 2 additions & 0 deletions express-messaging/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nodejs 20.17.0
npm 10.8.1
37 changes: 19 additions & 18 deletions express-messaging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ Sample application demonstrating Telnyx-Node SMS and MMS attachments

## Documentation & Tutorial

The full documentation and tutorial is available on [developers.telnyx.com](https://developers.telnyx.com/docs/v2/development/dev-env-setup?lang=dotnet&utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link)
The full documentation and tutorial is available on [developers.telnyx.com](https://developers.telnyx.com/docs/development?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link)

## Pre-Reqs

You will need to set up:

* [Telnyx Account](https://telnyx.com/sign-up?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link)
* [Telnyx Phone Number](https://portal.telnyx.com/#/app/numbers/my-numbers?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) enabled with:
* Ability to receive webhooks (with something like [ngrok](https://developers.telnyx.com/docs/v2/development/ngrok?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link))
* [Node & NPM](https://developers.telnyx.com/docs/v2/development/dev-env-setup?lang=node&utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) installed
* AWS Account setup with proper profiles and groups with IAM for S3. See the [Quickstart](https://docs.aws.amazon.com/sdk-for-javascript/index.html) for more information.
* Previously created S3 bucket with public permissions available.
- [Telnyx Account](https://telnyx.com/sign-up?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link)
- [Telnyx Phone Number](https://portal.telnyx.com/#/app/numbers/my-numbers?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) enabled with:
- Ability to receive webhooks (with something like [ngrok](https://developers.telnyx.com/docs/development?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link#ngrok-setup))
- [Node & NPM](https://developers.telnyx.com/docs/development?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link#node-red) installed
- AWS Account setup with proper profiles and groups with IAM for S3. See the [Quickstart](https://docs.aws.amazon.com/sdk-for-javascript/index.html) for more information.
- Previously created S3 bucket with public permissions available.

## What you can do

* 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
- 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

## Usage

The following environmental variables need to be set

| Variable | Description |
|:-----------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------|
| :--------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `TELNYX_API_KEY` | Your [Telnyx API Key](https://portal.telnyx.com/#/app/api-keys?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) |
| `TELNYX_PUBLIC_KEY` | Your [Telnyx Public Key](https://portal.telnyx.com/#/app/account/public-key?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) |
| `TELNYX_APP_PORT` | **Defaults to `8000`** The port the app will be served |
Expand All @@ -60,7 +60,7 @@ TELNYX_MMS_S3_BUCKET=
### Callback URLs For Telnyx Applications

| Callback Type | URL |
|:---------------------------------|:---------------------------------|
| :------------------------------- | :------------------------------- |
| Inbound Message Callback | `{ngrok-url}/messaging/inbound` |
| Outbound Message Status Callback | `{ngrok-url}/messaging/outbound` |

Expand All @@ -74,7 +74,7 @@ $ git clone https://github.com/d-telnyx/demo-node-telnyx.git

### Ngrok

This application is served on the port defined in the runtime environment (or in the `.env` file). Be sure to launch [ngrok](https://developers.telnyx.com/docs/v2/development/ngrok?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) for that port
This application is served on the port defined in the runtime environment (or in the `.env` file). Be sure to launch [ngrok](https://developers.telnyx.com/docs/development?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link#ngrok-setup) for that port

```
./ngrok http 8000
Expand All @@ -97,20 +97,21 @@ 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`).
At this point you can point your application to generated ngrok URL + path (Example: `http://{your-url}.ngrok.io/messaging/inbound`).

### Run

Start the server `node index.js`
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](/docs/v2/development/ngrok) 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.
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!

- Text your phone number and receive a response!
- Send a picture to your phone number and get that same picture right back!
13 changes: 6 additions & 7 deletions express-messaging/config.js → express-messaging/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ if (!process.env.TELNYX_MMS_S3_BUCKET) {
process.exit();
}


module.exports.TELNYX_API_KEY = process.env.TELNYX_API_KEY;
module.exports.TELNYX_PUBLIC_KEY = process.env.TELNYX_PUBLIC_KEY;
module.exports.TELNYX_APP_PORT = process.env.TELNYX_APP_PORT || 8000;
module.exports.AWS_PROFILE = process.env.AWS_PROFILE;
module.exports.AWS_REGION = process.env.AWS_REGION;
module.exports.TELNYX_MMS_S3_BUCKET = process.env.TELNYX_MMS_S3_BUCKET;
export const TELNYX_API_KEY = process.env.TELNYX_API_KEY;
export const TELNYX_PUBLIC_KEY = process.env.TELNYX_PUBLIC_KEY;
export const TELNYX_APP_PORT = process.env.TELNYX_APP_PORT || 8000;
export const AWS_PROFILE = process.env.AWS_PROFILE;
export const AWS_REGION = process.env.AWS_REGION;
export const TELNYX_MMS_S3_BUCKET = process.env.TELNYX_MMS_S3_BUCKET;
Loading