docs/examples/webhooks-docker/README.md
This is an example project for using a Docker container as a Twilio SendGrid inbound parse email webhooks and event webhooks
mkdir <project>cd <project>git clone https://github.com/sendgrid/sendgrid-nodejs.gitcp -R sendgrid-nodejs/examples/inbound-parse-docker/* .rm -rf sendgrid-nodejs/docker-compose builddocker-compose updocker-compose up --buildngrok http 3000https ngrok entry.NOTE: ngrok has a "replay" feature so you don't have to keep sending emails to yourself. You can access that when ngrok is running at http://127.0.0.1:4040/inspect/http
At the moment, the app.js only prints data to the console. You can extend this project by adding more business logic to the /parse_webhook or /event_webhook routes, contained in the routes/inbound-parse.js and routes/events.js.
The routes/inbound-parse.js route uses the express-formidable middleware to process the form data sent by Twilio SendGrid's Inbound Parse Webhook.
The events are available in the /parse_webhook route in the req.fields object. The app.js contains logging statements for the elements that are available to you. It may be useful to review the example-webhook-payload.txt for what the form data looks like when extending this application.
Attachments: express-formidable automatically decodes and stores the images to the /tmp directory in the container. This is configurable by passing a configuration object to the middleware:
app.use(formidable({
encoding: 'utf-8',
uploadDir: '/my/dir',
multiples: true, // req.files to be arrays of files
});
The routes/events.js route receives data in JSON format.
Additionally, the docker-compose has a volume mapping commented out if you'd prefer to store them in persistent storage outside of the container.
imagePullPolicy: IfNotPresent to pull from a local registry on the dev machine running Kubernetes as part of Docker. If you were deploying to Google Cloud, for example, you should disable that option.kubectl is used to deploy. You should already have a working kubectl context. From the root of the project execute: kubectl apply -f k8s/inbound-parse.ymlSee LICENSE