From 6969139a9a4b893bb1f054234afcf18009134e8c Mon Sep 17 00:00:00 2001 From: David Dooley Date: Thu, 10 Feb 2022 11:28:34 +0000 Subject: [PATCH 01/13] Added forwarding MMS to sendgrid This script will forward a incoming MMS image as an attachment to a email using Sendgrid. --- .../functions/forward-mms-sendgrid.js | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 forward-message-sendgrid/functions/forward-mms-sendgrid.js diff --git a/forward-message-sendgrid/functions/forward-mms-sendgrid.js b/forward-message-sendgrid/functions/forward-mms-sendgrid.js new file mode 100644 index 00000000..54830a64 --- /dev/null +++ b/forward-message-sendgrid/functions/forward-mms-sendgrid.js @@ -0,0 +1,56 @@ +const got = require('got'); +const request = require('request-promise-native'); + +exports.handler = function(context, event, callback) { + imagePath = event.MediaUrl0; + + //read in the image here: + request({ + url: imagePath, + method: 'GET', + encoding: null + }) + .then(result => { + + let imageBuffer = Buffer.from(result); + let imageBase64 = imageBuffer.toString('base64'); + + //now create the email message + const msg = { + personalizations: [{ to: [{ email: context.TO_EMAIL_ADDRESS }] }], + from: { email: context.FROM_EMAIL_ADDRESS }, + subject: `New SMS message from: ${event.From}`, + content: [ + { + type: 'text/plain', + value: event.Body + } + ], + attachments: [ + { + content: imageBase64, + filename: "owl.png", + type: "image/png", + disposition: "attachment", + content_id: "my_image" + } + ] + }; + + //send mail + got.post('https://api.sendgrid.com/v3/mail/send', { + headers: { + Authorization: `Bearer ${context.SENDGRID_API_KEY}`, + 'Content-Type': 'application/json' + }, + body: JSON.stringify(msg) + }) + .then(response => { + let twiml = new Twilio.twiml.MessagingResponse(); + callback(null, twiml); + }) + .catch(err => { + callback(err); + }); + }); +}; \ No newline at end of file From 8ae6c0395aaf0d9633f88c2d44a6d995c656520e Mon Sep 17 00:00:00 2001 From: David Dooley Date: Tue, 2 Jan 2024 11:47:47 +0000 Subject: [PATCH 02/13] Update README.md Added warning in README --- forward-message-sendgrid/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/forward-message-sendgrid/README.md b/forward-message-sendgrid/README.md index ee6e3d58..00014a2d 100644 --- a/forward-message-sendgrid/README.md +++ b/forward-message-sendgrid/README.md @@ -1,5 +1,7 @@ # Forward SMS message as an email (SendGrid) +### This Repo is redundant. With the release of Node v18, how we use the 'got' dependency has chnaged. If you want to use this repo as a reference, you will need to adjust the source code to work with Node v18 and above. + The SendGrid Function will forward incoming SMS messages to an email address using the [SendGrid API](https://sendgrid.com/). You will need a SendGrid account and an [API key](https://app.sendgrid.com/settings/api_keys) to use this Function. From 4eab40ed7ec6a26db11d5ba61df01b39ef2c7a07 Mon Sep 17 00:00:00 2001 From: David Dooley Date: Tue, 2 Jan 2024 11:48:47 +0000 Subject: [PATCH 03/13] Update README.md --- forward-message-sendgrid/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/forward-message-sendgrid/README.md b/forward-message-sendgrid/README.md index 00014a2d..70c558ab 100644 --- a/forward-message-sendgrid/README.md +++ b/forward-message-sendgrid/README.md @@ -1,7 +1,9 @@ -# Forward SMS message as an email (SendGrid) ### This Repo is redundant. With the release of Node v18, how we use the 'got' dependency has chnaged. If you want to use this repo as a reference, you will need to adjust the source code to work with Node v18 and above. + +# Forward SMS message as an email (SendGrid) + The SendGrid Function will forward incoming SMS messages to an email address using the [SendGrid API](https://sendgrid.com/). You will need a SendGrid account and an [API key](https://app.sendgrid.com/settings/api_keys) to use this Function. From ccf71b88c7cd7113f53c34d0212913643a760460 Mon Sep 17 00:00:00 2001 From: David Dooley Date: Wed, 10 Jan 2024 19:34:55 +0000 Subject: [PATCH 04/13] Update README.md Updated README with waring message. --- forward-message-sendgrid/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/forward-message-sendgrid/README.md b/forward-message-sendgrid/README.md index 70c558ab..71a4f448 100644 --- a/forward-message-sendgrid/README.md +++ b/forward-message-sendgrid/README.md @@ -1,6 +1,8 @@ -### This Repo is redundant. With the release of Node v18, how we use the 'got' dependency has chnaged. If you want to use this repo as a reference, you will need to adjust the source code to work with Node v18 and above. +### WARNING !!! +### This Repo is now out of date. +With the release of Node v18, the Node.js ecosystem are migrating over from the old CommonJS (CJS) standard to the newer, ES Modules (ESM) standard. You can read about the differences in far more detail in this blog post.https://www.twilio.com/docs/serverless/functions-assets/faq#how-can-i-use-an-es-module-in-my-function # Forward SMS message as an email (SendGrid) From ecb337587d07b49be42e8c6d7eb7ce173c41abaf Mon Sep 17 00:00:00 2001 From: David Dooley Date: Wed, 10 Jan 2024 19:37:09 +0000 Subject: [PATCH 05/13] Update README.md Touched up appearance of the URL --- forward-message-sendgrid/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/forward-message-sendgrid/README.md b/forward-message-sendgrid/README.md index 71a4f448..59202fa1 100644 --- a/forward-message-sendgrid/README.md +++ b/forward-message-sendgrid/README.md @@ -2,8 +2,7 @@ ### WARNING !!! ### This Repo is now out of date. -With the release of Node v18, the Node.js ecosystem are migrating over from the old CommonJS (CJS) standard to the newer, ES Modules (ESM) standard. You can read about the differences in far more detail in this blog post.https://www.twilio.com/docs/serverless/functions-assets/faq#how-can-i-use-an-es-module-in-my-function - +With the release of Node v18, the Node.js ecosystem are migrating over from the old CommonJS (CJS) standard to the newer, ES Modules (ESM) standard. You can read about the differences in far more detail in this [Blog Post.](https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1) # Forward SMS message as an email (SendGrid) The SendGrid Function will forward incoming SMS messages to an email address using the [SendGrid API](https://sendgrid.com/). From 6680878471e4cc3bbaa96914ce6720db752bf2ff Mon Sep 17 00:00:00 2001 From: David Dooley Date: Wed, 10 Jan 2024 20:07:08 +0000 Subject: [PATCH 06/13] Update README.md --- forward-message-sendgrid/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/forward-message-sendgrid/README.md b/forward-message-sendgrid/README.md index 59202fa1..0a1ceb70 100644 --- a/forward-message-sendgrid/README.md +++ b/forward-message-sendgrid/README.md @@ -2,7 +2,9 @@ ### WARNING !!! ### This Repo is now out of date. -With the release of Node v18, the Node.js ecosystem are migrating over from the old CommonJS (CJS) standard to the newer, ES Modules (ESM) standard. You can read about the differences in far more detail in this [Blog Post.](https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1) +With the release of Node v18, the Node.js ecosystem are migrating over from the old CommonJS (CJS) standard to the newer, ES Modules (ESM) standard. You can read about the differences in far more detail in this [Blog Post.](https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1). The following snippets may causes errors. + + # Forward SMS message as an email (SendGrid) The SendGrid Function will forward incoming SMS messages to an email address using the [SendGrid API](https://sendgrid.com/). From 9a022256755aeca743db6ffc35395947113b927f Mon Sep 17 00:00:00 2001 From: David Dooley Date: Thu, 11 Jan 2024 11:26:57 +0000 Subject: [PATCH 07/13] Update forward-mms-sendgrid.js Edited "SMS" to "MMS" --- forward-message-sendgrid/functions/forward-mms-sendgrid.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/forward-message-sendgrid/functions/forward-mms-sendgrid.js b/forward-message-sendgrid/functions/forward-mms-sendgrid.js index 54830a64..7cc421ec 100644 --- a/forward-message-sendgrid/functions/forward-mms-sendgrid.js +++ b/forward-message-sendgrid/functions/forward-mms-sendgrid.js @@ -19,7 +19,7 @@ exports.handler = function(context, event, callback) { const msg = { personalizations: [{ to: [{ email: context.TO_EMAIL_ADDRESS }] }], from: { email: context.FROM_EMAIL_ADDRESS }, - subject: `New SMS message from: ${event.From}`, + subject: `New MMS message from: ${event.From}`, content: [ { type: 'text/plain', @@ -53,4 +53,4 @@ exports.handler = function(context, event, callback) { callback(err); }); }); -}; \ No newline at end of file +}; From a47185740fe8a358c9e185368456ac90d3e25239 Mon Sep 17 00:00:00 2001 From: David Dooley Date: Thu, 11 Jan 2024 11:29:38 +0000 Subject: [PATCH 08/13] Update README.md Changed "Blog" to "blog" --- forward-message-sendgrid/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forward-message-sendgrid/README.md b/forward-message-sendgrid/README.md index 0a1ceb70..d1911060 100644 --- a/forward-message-sendgrid/README.md +++ b/forward-message-sendgrid/README.md @@ -2,7 +2,7 @@ ### WARNING !!! ### This Repo is now out of date. -With the release of Node v18, the Node.js ecosystem are migrating over from the old CommonJS (CJS) standard to the newer, ES Modules (ESM) standard. You can read about the differences in far more detail in this [Blog Post.](https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1). The following snippets may causes errors. +With the release of Node v18, the Node.js ecosystem are migrating over from the old CommonJS (CJS) standard to the newer, ES Modules (ESM) standard. You can read about the differences in far more detail in this [blog Post.](https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1). The following snippets may causes errors. # Forward SMS message as an email (SendGrid) From 5f74ce4e775092ab3e6028045a1081f0ff75508a Mon Sep 17 00:00:00 2001 From: David Dooley Date: Mon, 15 Jan 2024 12:14:34 +0000 Subject: [PATCH 09/13] Update forward-mms-sendgrid.js Added EOF \n From 4f87ee5417ca256f248290da04e06786b21c018b Mon Sep 17 00:00:00 2001 From: David Dooley Date: Mon, 15 Jan 2024 12:18:27 +0000 Subject: [PATCH 10/13] Update README.md "ecosystem are migrating" to "ecosystem is migrating" --- forward-message-sendgrid/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forward-message-sendgrid/README.md b/forward-message-sendgrid/README.md index d1911060..93c51d3e 100644 --- a/forward-message-sendgrid/README.md +++ b/forward-message-sendgrid/README.md @@ -2,7 +2,7 @@ ### WARNING !!! ### This Repo is now out of date. -With the release of Node v18, the Node.js ecosystem are migrating over from the old CommonJS (CJS) standard to the newer, ES Modules (ESM) standard. You can read about the differences in far more detail in this [blog Post.](https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1). The following snippets may causes errors. +With the release of Node v18, the Node.js ecosystem is migrating over from the old CommonJS (CJS) standard to the newer, ES Modules (ESM) standard. You can read about the differences in far more detail in this [blog Post.](https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1). The following snippets may causes errors. # Forward SMS message as an email (SendGrid) From 60433712fb224e556495e8d27190888667fc4299 Mon Sep 17 00:00:00 2001 From: David Dooley Date: Thu, 25 Jan 2024 14:28:10 +0000 Subject: [PATCH 11/13] Removed "warning" from README.md Warning redundant and removed. Simply just included text stating repo out of date --- forward-message-sendgrid/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/forward-message-sendgrid/README.md b/forward-message-sendgrid/README.md index 93c51d3e..a0f1466f 100644 --- a/forward-message-sendgrid/README.md +++ b/forward-message-sendgrid/README.md @@ -1,5 +1,4 @@ -### WARNING !!! ### This Repo is now out of date. With the release of Node v18, the Node.js ecosystem is migrating over from the old CommonJS (CJS) standard to the newer, ES Modules (ESM) standard. You can read about the differences in far more detail in this [blog Post.](https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1). The following snippets may causes errors. From 3a8c2c47bd9b1f457eb46c4fe949ab91595f0eb1 Mon Sep 17 00:00:00 2001 From: David Dooley Date: Fri, 15 Mar 2024 11:20:22 +0000 Subject: [PATCH 12/13] Added info for attention at the start of README.md Removed the words "out of date" and clarified the JS migration --- forward-message-sendgrid/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/forward-message-sendgrid/README.md b/forward-message-sendgrid/README.md index a0f1466f..100a4b61 100644 --- a/forward-message-sendgrid/README.md +++ b/forward-message-sendgrid/README.md @@ -1,7 +1,7 @@ -### This Repo is now out of date. +###Attention -With the release of Node v18, the Node.js ecosystem is migrating over from the old CommonJS (CJS) standard to the newer, ES Modules (ESM) standard. You can read about the differences in far more detail in this [blog Post.](https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1). The following snippets may causes errors. +With the release of Node v18, the Node.js ecosystem is migrating over from the old CommonJS (CJS) standard to the newer, ES Modules (ESM) standard. Using ESM modules in CJS code is not possible. You can read about the differences in far more detail in this [blog Post.](https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1). The following snippets may causes errors. # Forward SMS message as an email (SendGrid) From 01586e028cfa274094058ada973fddb6ae322d3c Mon Sep 17 00:00:00 2001 From: David Dooley Date: Fri, 15 Mar 2024 11:21:39 +0000 Subject: [PATCH 13/13] Removed warning README.md --- forward-message-sendgrid/README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/forward-message-sendgrid/README.md b/forward-message-sendgrid/README.md index 100a4b61..27a1c774 100644 --- a/forward-message-sendgrid/README.md +++ b/forward-message-sendgrid/README.md @@ -1,9 +1,4 @@ -###Attention - -With the release of Node v18, the Node.js ecosystem is migrating over from the old CommonJS (CJS) standard to the newer, ES Modules (ESM) standard. Using ESM modules in CJS code is not possible. You can read about the differences in far more detail in this [blog Post.](https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1). The following snippets may causes errors. - - # Forward SMS message as an email (SendGrid) The SendGrid Function will forward incoming SMS messages to an email address using the [SendGrid API](https://sendgrid.com/).