There are some examples online of being able to forward emails to sms using Sendgrid and Twilio - such as here https://www.twilio.com/blog/two-way-email-to-sms-sendgrid-twilio
This uses the Inbound Parse in SendGrid to forward to a Twilio function.
However, is seems that the method function definition in Twilio which was
module.exports = async (req, res) => { }
is now
exports.handler = (context, event, callback) => { }
And functions now cannot accept a content type of form-data which is how SendGrid posts the data on receiving an email.
Is there a way to circumnavigate this issue - or is there a better solution to this issue overall?
The blog post you linked isn't using Twilio Function but another FaaS service. That explains the difference in the signature that you mentioned.
As of now, the limitation that Functions only "understand" the content type application/json
is still current. And as SendGrid's InboundParse only support multipart/form-data
these two technologies cannot directly communicate.
As a workaround, you either need to use another platform to run your backend code, or you need to add an intermediate. Coincidentally, I'm working on a middle component that acts as a proxy between SendGrid and a Twilio Function and converts each request's content type. In case that would be helpful for you, please clone this GitHub repo or make use of the Docker image that is attached to the repo.
git clone https://github.com/IObert/content-type-converter
cd content-type-converter
npm install
npm build
FORWARD_TO=https://<target-host.com> node dist/server.js