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

Repo now out of date #478

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions forward-message-sendgrid/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# 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/).
Expand Down
56 changes: 56 additions & 0 deletions forward-message-sendgrid/functions/forward-mms-sendgrid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const got = require('got');
const request = require('request-promise-native');

Check failure on line 2 in forward-message-sendgrid/functions/forward-mms-sendgrid.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 14)

Unable to resolve path to module 'request-promise-native'

Check failure on line 2 in forward-message-sendgrid/functions/forward-mms-sendgrid.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16)

Unable to resolve path to module 'request-promise-native'

exports.handler = function(context, event, callback) {
imagePath = event.MediaUrl0;

//read in the image here:

Check failure on line 7 in forward-message-sendgrid/functions/forward-mms-sendgrid.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 14)

Expected space or tab after '//' in comment

Check failure on line 7 in forward-message-sendgrid/functions/forward-mms-sendgrid.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16)

Expected space or tab after '//' in comment
request({
url: imagePath,
method: 'GET',
encoding: null
})
.then(result => {

let imageBuffer = Buffer.from(result);

Check failure on line 15 in forward-message-sendgrid/functions/forward-mms-sendgrid.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 14)

'imageBuffer' is never reassigned. Use 'const' instead

Check failure on line 15 in forward-message-sendgrid/functions/forward-mms-sendgrid.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16)

'imageBuffer' is never reassigned. Use 'const' instead
let imageBase64 = imageBuffer.toString('base64');

Check failure on line 16 in forward-message-sendgrid/functions/forward-mms-sendgrid.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 14)

'imageBase64' is never reassigned. Use 'const' instead

Check failure on line 16 in forward-message-sendgrid/functions/forward-mms-sendgrid.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16)

'imageBase64' is never reassigned. Use 'const' instead

//now create the email message

Check failure on line 18 in forward-message-sendgrid/functions/forward-mms-sendgrid.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 14)

Expected space or tab after '//' in comment

Check failure on line 18 in forward-message-sendgrid/functions/forward-mms-sendgrid.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16)

Expected space or tab after '//' in comment
const msg = {
personalizations: [{ to: [{ email: context.TO_EMAIL_ADDRESS }] }],
from: { email: context.FROM_EMAIL_ADDRESS },
subject: `New MMS 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"

Check failure on line 35 in forward-message-sendgrid/functions/forward-mms-sendgrid.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 14)

Identifier 'content_id' is not in camel case

Check failure on line 35 in forward-message-sendgrid/functions/forward-mms-sendgrid.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16)

Identifier 'content_id' is not in camel case
}
]
};

//send mail

Check failure on line 40 in forward-message-sendgrid/functions/forward-mms-sendgrid.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 14)

Expected space or tab after '//' in comment

Check failure on line 40 in forward-message-sendgrid/functions/forward-mms-sendgrid.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16)

Expected space or tab after '//' in comment
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();

Check failure on line 49 in forward-message-sendgrid/functions/forward-mms-sendgrid.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 14)

'twiml' is never reassigned. Use 'const' instead

Check failure on line 49 in forward-message-sendgrid/functions/forward-mms-sendgrid.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16)

'twiml' is never reassigned. Use 'const' instead
callback(null, twiml);
})
.catch(err => {
callback(err);
});
});
};
Loading