/now-serverless-sendgrid-inbound-parse

Trigger a Now Serverless Lambda with SendGrid Inbound Parse then send a SMS with Twilio

Primary LanguageJavaScript

Trigger a Now Serverless Lambda with SendGrid Inbound Parse then send a SMS with Twilio

  1. Setup Sender Authentication with Twilio SendGrid.
  2. Setup Inbound Parse
    • Add MX record to DNS – parse.yourdomain.com --> mx.sendgrid.net
    • Add webhook to SendGrid inbound parse UI per doc above. host in this case == parse.yourdomain.com. Webhook url would be something like https://yourdomain.com/parse-sendgrid.js
  3. Buy a number on the Twilio phone numbers page
  4. Clone this repo
  5. Rename example.config.js to config.js
  6. Add your account sid & auth token to config.js. These are in your Twilio Console.
  7. yarn or npm install
  8. Install Now CLI if you don't have it installed.
  9. Optionally alias a domain or subdomain to now. Every deployment to Now, generates a new domain so aliasing a domain provides a static domain and thus a static URL for your SendGrid webhook to post to.
  10. now

now.json

{
  "version": 2,
  "name": "sendgrid-now-lambda",
  "alias": "yourdomain.com", // Optionally alias a domain - otherwise remove.
  "builds": [
    { "src": "parse-sendgrid.js", "use": "@now/node" }, // lambda endpoint. The code that runs when a email is parsed by SendGrid.
    { "src": "index.html", "use": "@now/static" } // simply serve the static html file. For demonstration only. Does nothing.
  ]
}