How do I retrieve the Twilio fax PDF and attach it to an email using Node.js inside a Twilio function?












0















Is there any way I can use Twilio's serverless options to retrieve a PDF that was faxed earlier and attach it to an email?



I've learned how to do this in PHP in WordPress on my own personal web server by looking at examples. Here's a snippet of WordPress PHP code that retrieves a PDF that was faxed using Twilio and then sends an email with the PDF as an attachment:



<?php
$mediaurl = $_GET["MediaUrl"];
$path = '/some/path/on/your/web/server/where/to/save/the/PDF';
$attachment = $filename = $path . $_GET["FaxSid"] . '.pdf';
require_once('wp-load.php');
$response = wp_remote_get( $mediaurl, array( 'timeout' => '300', 'stream' => true, 'filename' => $filename ) );
wp_mail( 'somebody@somewhere.com', 'You have a fax', 'See attached PDF', 'From: <someone@someplace.com>', $attachment );
?>


In case someone is learning about these things, I have the above code saved in a twilio-fax-receive.php file on my web server. And to run it every time a fax comes in, I have a TwiML Bin set up on Twilio -- I called it receive-fax -- with this code in it:



<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Receive action="https://www.somewhere.com/twilio-fax-receive.php" method="GET"/>
</Response>


Then, on the "Configure" page for the fax number that receives faxes, I selected TwiML where it says "A FAX COMES IN" and then selected my receive-fax TwiML Bin.



But back to my issue.



Can I replicate that using Node.js inside a Twilio function? Or some other way using only Twilio, without my own web server? Is there a way to get the contents of the PDF, encode it with base64 and attach to an email using SendGrid or some other service on the fly in Node.js?



Does anybody have a working example? I've tried a lot of things I found on the Web that involved request.get and got.stream and pipe and Buffer and fs, but to no avail...



I am not a developer, and I think I am in way over my head. Your help would be very much appreciated.










share|improve this question





























    0















    Is there any way I can use Twilio's serverless options to retrieve a PDF that was faxed earlier and attach it to an email?



    I've learned how to do this in PHP in WordPress on my own personal web server by looking at examples. Here's a snippet of WordPress PHP code that retrieves a PDF that was faxed using Twilio and then sends an email with the PDF as an attachment:



    <?php
    $mediaurl = $_GET["MediaUrl"];
    $path = '/some/path/on/your/web/server/where/to/save/the/PDF';
    $attachment = $filename = $path . $_GET["FaxSid"] . '.pdf';
    require_once('wp-load.php');
    $response = wp_remote_get( $mediaurl, array( 'timeout' => '300', 'stream' => true, 'filename' => $filename ) );
    wp_mail( 'somebody@somewhere.com', 'You have a fax', 'See attached PDF', 'From: <someone@someplace.com>', $attachment );
    ?>


    In case someone is learning about these things, I have the above code saved in a twilio-fax-receive.php file on my web server. And to run it every time a fax comes in, I have a TwiML Bin set up on Twilio -- I called it receive-fax -- with this code in it:



    <?xml version="1.0" encoding="UTF-8"?>
    <Response>
    <Receive action="https://www.somewhere.com/twilio-fax-receive.php" method="GET"/>
    </Response>


    Then, on the "Configure" page for the fax number that receives faxes, I selected TwiML where it says "A FAX COMES IN" and then selected my receive-fax TwiML Bin.



    But back to my issue.



    Can I replicate that using Node.js inside a Twilio function? Or some other way using only Twilio, without my own web server? Is there a way to get the contents of the PDF, encode it with base64 and attach to an email using SendGrid or some other service on the fly in Node.js?



    Does anybody have a working example? I've tried a lot of things I found on the Web that involved request.get and got.stream and pipe and Buffer and fs, but to no avail...



    I am not a developer, and I think I am in way over my head. Your help would be very much appreciated.










    share|improve this question



























      0












      0








      0


      1






      Is there any way I can use Twilio's serverless options to retrieve a PDF that was faxed earlier and attach it to an email?



      I've learned how to do this in PHP in WordPress on my own personal web server by looking at examples. Here's a snippet of WordPress PHP code that retrieves a PDF that was faxed using Twilio and then sends an email with the PDF as an attachment:



      <?php
      $mediaurl = $_GET["MediaUrl"];
      $path = '/some/path/on/your/web/server/where/to/save/the/PDF';
      $attachment = $filename = $path . $_GET["FaxSid"] . '.pdf';
      require_once('wp-load.php');
      $response = wp_remote_get( $mediaurl, array( 'timeout' => '300', 'stream' => true, 'filename' => $filename ) );
      wp_mail( 'somebody@somewhere.com', 'You have a fax', 'See attached PDF', 'From: <someone@someplace.com>', $attachment );
      ?>


      In case someone is learning about these things, I have the above code saved in a twilio-fax-receive.php file on my web server. And to run it every time a fax comes in, I have a TwiML Bin set up on Twilio -- I called it receive-fax -- with this code in it:



      <?xml version="1.0" encoding="UTF-8"?>
      <Response>
      <Receive action="https://www.somewhere.com/twilio-fax-receive.php" method="GET"/>
      </Response>


      Then, on the "Configure" page for the fax number that receives faxes, I selected TwiML where it says "A FAX COMES IN" and then selected my receive-fax TwiML Bin.



      But back to my issue.



      Can I replicate that using Node.js inside a Twilio function? Or some other way using only Twilio, without my own web server? Is there a way to get the contents of the PDF, encode it with base64 and attach to an email using SendGrid or some other service on the fly in Node.js?



      Does anybody have a working example? I've tried a lot of things I found on the Web that involved request.get and got.stream and pipe and Buffer and fs, but to no avail...



      I am not a developer, and I think I am in way over my head. Your help would be very much appreciated.










      share|improve this question
















      Is there any way I can use Twilio's serverless options to retrieve a PDF that was faxed earlier and attach it to an email?



      I've learned how to do this in PHP in WordPress on my own personal web server by looking at examples. Here's a snippet of WordPress PHP code that retrieves a PDF that was faxed using Twilio and then sends an email with the PDF as an attachment:



      <?php
      $mediaurl = $_GET["MediaUrl"];
      $path = '/some/path/on/your/web/server/where/to/save/the/PDF';
      $attachment = $filename = $path . $_GET["FaxSid"] . '.pdf';
      require_once('wp-load.php');
      $response = wp_remote_get( $mediaurl, array( 'timeout' => '300', 'stream' => true, 'filename' => $filename ) );
      wp_mail( 'somebody@somewhere.com', 'You have a fax', 'See attached PDF', 'From: <someone@someplace.com>', $attachment );
      ?>


      In case someone is learning about these things, I have the above code saved in a twilio-fax-receive.php file on my web server. And to run it every time a fax comes in, I have a TwiML Bin set up on Twilio -- I called it receive-fax -- with this code in it:



      <?xml version="1.0" encoding="UTF-8"?>
      <Response>
      <Receive action="https://www.somewhere.com/twilio-fax-receive.php" method="GET"/>
      </Response>


      Then, on the "Configure" page for the fax number that receives faxes, I selected TwiML where it says "A FAX COMES IN" and then selected my receive-fax TwiML Bin.



      But back to my issue.



      Can I replicate that using Node.js inside a Twilio function? Or some other way using only Twilio, without my own web server? Is there a way to get the contents of the PDF, encode it with base64 and attach to an email using SendGrid or some other service on the fly in Node.js?



      Does anybody have a working example? I've tried a lot of things I found on the Web that involved request.get and got.stream and pipe and Buffer and fs, but to no avail...



      I am not a developer, and I think I am in way over my head. Your help would be very much appreciated.







      node.js twilio twilio-api






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 25 '18 at 23:49







      sbloom

















      asked Nov 22 '18 at 7:57









      sbloomsbloom

      32




      32
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Twilio developer evangelist here.



          Yes, you can replicate this using Node.js in a Twilio Function. Here's how using SendGrid to send the email:




          1. Add request to your Runtime dependencies. I used version 2.88.0

          2. Add the following environment variables to your Functions config:



            • TO_EMAIL_ADDRESS: the email address you want to deliver faxes to.


            • FROM_EMAIL_ADDRESS: the email address you want to receive faxes from.


            • SENDGRID_API_KEY: Your SendGrid API key



          3. Save the config section


          4. Create a new function and add the following code:



            const request = require('request');

            exports.handler = function(context, event, callback) {
            const faxUrl = event.MediaUrl;

            const email = {
            personalizations: [{ to: [{ email: context.TO_EMAIL_ADDRESS }] }],
            from: { email: context.FROM_EMAIL_ADDRESS },
            subject: `New fax from ${event.From}`,
            content: [
            {
            type: 'text/plain',
            value: 'Your fax is attached.'
            }
            ],
            attachments:
            };

            request.get({ uri: faxUrl, encoding: null }, (error, response, body) => {
            if (!error && response.statusCode == 200) {
            email.attachments.push({
            content: body.toString('base64'),
            filename: `${event.FaxSid}.pdf`,
            type: response.headers['content-type']
            });
            }
            request.post(
            {
            uri: 'https://api.sendgrid.com/v3/mail/send',
            body: email,
            auth: {
            bearer: context.SENDGRID_API_KEY
            },
            json: true
            },
            (error, response, body) => {
            if (error) {
            return callback(error);
            } else {
            if (response.statusCode === 202) {
            return callback(null, new Twilio.twiml.VoiceResponse());
            } else {
            return callback(body);
            }
            }
            }
            );
            });
            };


          5. Give the Function a path and save it.


          6. Add the path as the action attribute to your <Receive> element in your TwiML bin.

          7. Send in the fax and watch it arrive in your inbox.


          Let me know if this works for you, I'll write up how the code works in more detail when I get the time.






          share|improve this answer


























          • Wow!! Thank you Phil! I will give it a try and report back.

            – sbloom
            Nov 24 '18 at 5:36













          • Works like a charm! The email.attachments.push was genious - I don't think I've seen this in any of the examples I've looked at before. There is return callback(err) in the request.post block -- is that a typo that should be return callback(error)? I would love to know what return callback(null, new Twilio.twiml.VoiceResponse()) is for. If you ever get time to explain how this all works, that would definitely be awesome. Thank you again, @philnash!

            – sbloom
            Nov 25 '18 at 22:27











          • Glad it works! I will write this up at some point, but you we’re right about the err typo. Otherwise returning a new Twilio.twiml.VoiceResponse() will just send an empty XML <Response/> to Twilio to let them know everything was ok.

            – philnash
            Nov 25 '18 at 22:30











          • BTW, I adapted your entire code and made the function URL my statusCallback from within another function. That way, after I send a fax, the recepient gets the fax as per usual and I also get an email with the fax transmission details and the attached PDF as it was faxed by Twilio. Lawyers wanted this level of detail for their cases. My next step is to look into secure transmissions - i.e., probably, deleting the fax everywhere that's publicly accessible immediately after successful delivery.

            – sbloom
            Nov 25 '18 at 22:38











          • Just saw your comment re typo and VoiceResponse. Makes sense. Thank you.

            – sbloom
            Nov 25 '18 at 22:39











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426243%2fhow-do-i-retrieve-the-twilio-fax-pdf-and-attach-it-to-an-email-using-node-js-ins%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Twilio developer evangelist here.



          Yes, you can replicate this using Node.js in a Twilio Function. Here's how using SendGrid to send the email:




          1. Add request to your Runtime dependencies. I used version 2.88.0

          2. Add the following environment variables to your Functions config:



            • TO_EMAIL_ADDRESS: the email address you want to deliver faxes to.


            • FROM_EMAIL_ADDRESS: the email address you want to receive faxes from.


            • SENDGRID_API_KEY: Your SendGrid API key



          3. Save the config section


          4. Create a new function and add the following code:



            const request = require('request');

            exports.handler = function(context, event, callback) {
            const faxUrl = event.MediaUrl;

            const email = {
            personalizations: [{ to: [{ email: context.TO_EMAIL_ADDRESS }] }],
            from: { email: context.FROM_EMAIL_ADDRESS },
            subject: `New fax from ${event.From}`,
            content: [
            {
            type: 'text/plain',
            value: 'Your fax is attached.'
            }
            ],
            attachments:
            };

            request.get({ uri: faxUrl, encoding: null }, (error, response, body) => {
            if (!error && response.statusCode == 200) {
            email.attachments.push({
            content: body.toString('base64'),
            filename: `${event.FaxSid}.pdf`,
            type: response.headers['content-type']
            });
            }
            request.post(
            {
            uri: 'https://api.sendgrid.com/v3/mail/send',
            body: email,
            auth: {
            bearer: context.SENDGRID_API_KEY
            },
            json: true
            },
            (error, response, body) => {
            if (error) {
            return callback(error);
            } else {
            if (response.statusCode === 202) {
            return callback(null, new Twilio.twiml.VoiceResponse());
            } else {
            return callback(body);
            }
            }
            }
            );
            });
            };


          5. Give the Function a path and save it.


          6. Add the path as the action attribute to your <Receive> element in your TwiML bin.

          7. Send in the fax and watch it arrive in your inbox.


          Let me know if this works for you, I'll write up how the code works in more detail when I get the time.






          share|improve this answer


























          • Wow!! Thank you Phil! I will give it a try and report back.

            – sbloom
            Nov 24 '18 at 5:36













          • Works like a charm! The email.attachments.push was genious - I don't think I've seen this in any of the examples I've looked at before. There is return callback(err) in the request.post block -- is that a typo that should be return callback(error)? I would love to know what return callback(null, new Twilio.twiml.VoiceResponse()) is for. If you ever get time to explain how this all works, that would definitely be awesome. Thank you again, @philnash!

            – sbloom
            Nov 25 '18 at 22:27











          • Glad it works! I will write this up at some point, but you we’re right about the err typo. Otherwise returning a new Twilio.twiml.VoiceResponse() will just send an empty XML <Response/> to Twilio to let them know everything was ok.

            – philnash
            Nov 25 '18 at 22:30











          • BTW, I adapted your entire code and made the function URL my statusCallback from within another function. That way, after I send a fax, the recepient gets the fax as per usual and I also get an email with the fax transmission details and the attached PDF as it was faxed by Twilio. Lawyers wanted this level of detail for their cases. My next step is to look into secure transmissions - i.e., probably, deleting the fax everywhere that's publicly accessible immediately after successful delivery.

            – sbloom
            Nov 25 '18 at 22:38











          • Just saw your comment re typo and VoiceResponse. Makes sense. Thank you.

            – sbloom
            Nov 25 '18 at 22:39
















          0














          Twilio developer evangelist here.



          Yes, you can replicate this using Node.js in a Twilio Function. Here's how using SendGrid to send the email:




          1. Add request to your Runtime dependencies. I used version 2.88.0

          2. Add the following environment variables to your Functions config:



            • TO_EMAIL_ADDRESS: the email address you want to deliver faxes to.


            • FROM_EMAIL_ADDRESS: the email address you want to receive faxes from.


            • SENDGRID_API_KEY: Your SendGrid API key



          3. Save the config section


          4. Create a new function and add the following code:



            const request = require('request');

            exports.handler = function(context, event, callback) {
            const faxUrl = event.MediaUrl;

            const email = {
            personalizations: [{ to: [{ email: context.TO_EMAIL_ADDRESS }] }],
            from: { email: context.FROM_EMAIL_ADDRESS },
            subject: `New fax from ${event.From}`,
            content: [
            {
            type: 'text/plain',
            value: 'Your fax is attached.'
            }
            ],
            attachments:
            };

            request.get({ uri: faxUrl, encoding: null }, (error, response, body) => {
            if (!error && response.statusCode == 200) {
            email.attachments.push({
            content: body.toString('base64'),
            filename: `${event.FaxSid}.pdf`,
            type: response.headers['content-type']
            });
            }
            request.post(
            {
            uri: 'https://api.sendgrid.com/v3/mail/send',
            body: email,
            auth: {
            bearer: context.SENDGRID_API_KEY
            },
            json: true
            },
            (error, response, body) => {
            if (error) {
            return callback(error);
            } else {
            if (response.statusCode === 202) {
            return callback(null, new Twilio.twiml.VoiceResponse());
            } else {
            return callback(body);
            }
            }
            }
            );
            });
            };


          5. Give the Function a path and save it.


          6. Add the path as the action attribute to your <Receive> element in your TwiML bin.

          7. Send in the fax and watch it arrive in your inbox.


          Let me know if this works for you, I'll write up how the code works in more detail when I get the time.






          share|improve this answer


























          • Wow!! Thank you Phil! I will give it a try and report back.

            – sbloom
            Nov 24 '18 at 5:36













          • Works like a charm! The email.attachments.push was genious - I don't think I've seen this in any of the examples I've looked at before. There is return callback(err) in the request.post block -- is that a typo that should be return callback(error)? I would love to know what return callback(null, new Twilio.twiml.VoiceResponse()) is for. If you ever get time to explain how this all works, that would definitely be awesome. Thank you again, @philnash!

            – sbloom
            Nov 25 '18 at 22:27











          • Glad it works! I will write this up at some point, but you we’re right about the err typo. Otherwise returning a new Twilio.twiml.VoiceResponse() will just send an empty XML <Response/> to Twilio to let them know everything was ok.

            – philnash
            Nov 25 '18 at 22:30











          • BTW, I adapted your entire code and made the function URL my statusCallback from within another function. That way, after I send a fax, the recepient gets the fax as per usual and I also get an email with the fax transmission details and the attached PDF as it was faxed by Twilio. Lawyers wanted this level of detail for their cases. My next step is to look into secure transmissions - i.e., probably, deleting the fax everywhere that's publicly accessible immediately after successful delivery.

            – sbloom
            Nov 25 '18 at 22:38











          • Just saw your comment re typo and VoiceResponse. Makes sense. Thank you.

            – sbloom
            Nov 25 '18 at 22:39














          0












          0








          0







          Twilio developer evangelist here.



          Yes, you can replicate this using Node.js in a Twilio Function. Here's how using SendGrid to send the email:




          1. Add request to your Runtime dependencies. I used version 2.88.0

          2. Add the following environment variables to your Functions config:



            • TO_EMAIL_ADDRESS: the email address you want to deliver faxes to.


            • FROM_EMAIL_ADDRESS: the email address you want to receive faxes from.


            • SENDGRID_API_KEY: Your SendGrid API key



          3. Save the config section


          4. Create a new function and add the following code:



            const request = require('request');

            exports.handler = function(context, event, callback) {
            const faxUrl = event.MediaUrl;

            const email = {
            personalizations: [{ to: [{ email: context.TO_EMAIL_ADDRESS }] }],
            from: { email: context.FROM_EMAIL_ADDRESS },
            subject: `New fax from ${event.From}`,
            content: [
            {
            type: 'text/plain',
            value: 'Your fax is attached.'
            }
            ],
            attachments:
            };

            request.get({ uri: faxUrl, encoding: null }, (error, response, body) => {
            if (!error && response.statusCode == 200) {
            email.attachments.push({
            content: body.toString('base64'),
            filename: `${event.FaxSid}.pdf`,
            type: response.headers['content-type']
            });
            }
            request.post(
            {
            uri: 'https://api.sendgrid.com/v3/mail/send',
            body: email,
            auth: {
            bearer: context.SENDGRID_API_KEY
            },
            json: true
            },
            (error, response, body) => {
            if (error) {
            return callback(error);
            } else {
            if (response.statusCode === 202) {
            return callback(null, new Twilio.twiml.VoiceResponse());
            } else {
            return callback(body);
            }
            }
            }
            );
            });
            };


          5. Give the Function a path and save it.


          6. Add the path as the action attribute to your <Receive> element in your TwiML bin.

          7. Send in the fax and watch it arrive in your inbox.


          Let me know if this works for you, I'll write up how the code works in more detail when I get the time.






          share|improve this answer















          Twilio developer evangelist here.



          Yes, you can replicate this using Node.js in a Twilio Function. Here's how using SendGrid to send the email:




          1. Add request to your Runtime dependencies. I used version 2.88.0

          2. Add the following environment variables to your Functions config:



            • TO_EMAIL_ADDRESS: the email address you want to deliver faxes to.


            • FROM_EMAIL_ADDRESS: the email address you want to receive faxes from.


            • SENDGRID_API_KEY: Your SendGrid API key



          3. Save the config section


          4. Create a new function and add the following code:



            const request = require('request');

            exports.handler = function(context, event, callback) {
            const faxUrl = event.MediaUrl;

            const email = {
            personalizations: [{ to: [{ email: context.TO_EMAIL_ADDRESS }] }],
            from: { email: context.FROM_EMAIL_ADDRESS },
            subject: `New fax from ${event.From}`,
            content: [
            {
            type: 'text/plain',
            value: 'Your fax is attached.'
            }
            ],
            attachments:
            };

            request.get({ uri: faxUrl, encoding: null }, (error, response, body) => {
            if (!error && response.statusCode == 200) {
            email.attachments.push({
            content: body.toString('base64'),
            filename: `${event.FaxSid}.pdf`,
            type: response.headers['content-type']
            });
            }
            request.post(
            {
            uri: 'https://api.sendgrid.com/v3/mail/send',
            body: email,
            auth: {
            bearer: context.SENDGRID_API_KEY
            },
            json: true
            },
            (error, response, body) => {
            if (error) {
            return callback(error);
            } else {
            if (response.statusCode === 202) {
            return callback(null, new Twilio.twiml.VoiceResponse());
            } else {
            return callback(body);
            }
            }
            }
            );
            });
            };


          5. Give the Function a path and save it.


          6. Add the path as the action attribute to your <Receive> element in your TwiML bin.

          7. Send in the fax and watch it arrive in your inbox.


          Let me know if this works for you, I'll write up how the code works in more detail when I get the time.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 25 '18 at 22:28

























          answered Nov 23 '18 at 5:36









          philnashphilnash

          38.3k93554




          38.3k93554













          • Wow!! Thank you Phil! I will give it a try and report back.

            – sbloom
            Nov 24 '18 at 5:36













          • Works like a charm! The email.attachments.push was genious - I don't think I've seen this in any of the examples I've looked at before. There is return callback(err) in the request.post block -- is that a typo that should be return callback(error)? I would love to know what return callback(null, new Twilio.twiml.VoiceResponse()) is for. If you ever get time to explain how this all works, that would definitely be awesome. Thank you again, @philnash!

            – sbloom
            Nov 25 '18 at 22:27











          • Glad it works! I will write this up at some point, but you we’re right about the err typo. Otherwise returning a new Twilio.twiml.VoiceResponse() will just send an empty XML <Response/> to Twilio to let them know everything was ok.

            – philnash
            Nov 25 '18 at 22:30











          • BTW, I adapted your entire code and made the function URL my statusCallback from within another function. That way, after I send a fax, the recepient gets the fax as per usual and I also get an email with the fax transmission details and the attached PDF as it was faxed by Twilio. Lawyers wanted this level of detail for their cases. My next step is to look into secure transmissions - i.e., probably, deleting the fax everywhere that's publicly accessible immediately after successful delivery.

            – sbloom
            Nov 25 '18 at 22:38











          • Just saw your comment re typo and VoiceResponse. Makes sense. Thank you.

            – sbloom
            Nov 25 '18 at 22:39



















          • Wow!! Thank you Phil! I will give it a try and report back.

            – sbloom
            Nov 24 '18 at 5:36













          • Works like a charm! The email.attachments.push was genious - I don't think I've seen this in any of the examples I've looked at before. There is return callback(err) in the request.post block -- is that a typo that should be return callback(error)? I would love to know what return callback(null, new Twilio.twiml.VoiceResponse()) is for. If you ever get time to explain how this all works, that would definitely be awesome. Thank you again, @philnash!

            – sbloom
            Nov 25 '18 at 22:27











          • Glad it works! I will write this up at some point, but you we’re right about the err typo. Otherwise returning a new Twilio.twiml.VoiceResponse() will just send an empty XML <Response/> to Twilio to let them know everything was ok.

            – philnash
            Nov 25 '18 at 22:30











          • BTW, I adapted your entire code and made the function URL my statusCallback from within another function. That way, after I send a fax, the recepient gets the fax as per usual and I also get an email with the fax transmission details and the attached PDF as it was faxed by Twilio. Lawyers wanted this level of detail for their cases. My next step is to look into secure transmissions - i.e., probably, deleting the fax everywhere that's publicly accessible immediately after successful delivery.

            – sbloom
            Nov 25 '18 at 22:38











          • Just saw your comment re typo and VoiceResponse. Makes sense. Thank you.

            – sbloom
            Nov 25 '18 at 22:39

















          Wow!! Thank you Phil! I will give it a try and report back.

          – sbloom
          Nov 24 '18 at 5:36







          Wow!! Thank you Phil! I will give it a try and report back.

          – sbloom
          Nov 24 '18 at 5:36















          Works like a charm! The email.attachments.push was genious - I don't think I've seen this in any of the examples I've looked at before. There is return callback(err) in the request.post block -- is that a typo that should be return callback(error)? I would love to know what return callback(null, new Twilio.twiml.VoiceResponse()) is for. If you ever get time to explain how this all works, that would definitely be awesome. Thank you again, @philnash!

          – sbloom
          Nov 25 '18 at 22:27





          Works like a charm! The email.attachments.push was genious - I don't think I've seen this in any of the examples I've looked at before. There is return callback(err) in the request.post block -- is that a typo that should be return callback(error)? I would love to know what return callback(null, new Twilio.twiml.VoiceResponse()) is for. If you ever get time to explain how this all works, that would definitely be awesome. Thank you again, @philnash!

          – sbloom
          Nov 25 '18 at 22:27













          Glad it works! I will write this up at some point, but you we’re right about the err typo. Otherwise returning a new Twilio.twiml.VoiceResponse() will just send an empty XML <Response/> to Twilio to let them know everything was ok.

          – philnash
          Nov 25 '18 at 22:30





          Glad it works! I will write this up at some point, but you we’re right about the err typo. Otherwise returning a new Twilio.twiml.VoiceResponse() will just send an empty XML <Response/> to Twilio to let them know everything was ok.

          – philnash
          Nov 25 '18 at 22:30













          BTW, I adapted your entire code and made the function URL my statusCallback from within another function. That way, after I send a fax, the recepient gets the fax as per usual and I also get an email with the fax transmission details and the attached PDF as it was faxed by Twilio. Lawyers wanted this level of detail for their cases. My next step is to look into secure transmissions - i.e., probably, deleting the fax everywhere that's publicly accessible immediately after successful delivery.

          – sbloom
          Nov 25 '18 at 22:38





          BTW, I adapted your entire code and made the function URL my statusCallback from within another function. That way, after I send a fax, the recepient gets the fax as per usual and I also get an email with the fax transmission details and the attached PDF as it was faxed by Twilio. Lawyers wanted this level of detail for their cases. My next step is to look into secure transmissions - i.e., probably, deleting the fax everywhere that's publicly accessible immediately after successful delivery.

          – sbloom
          Nov 25 '18 at 22:38













          Just saw your comment re typo and VoiceResponse. Makes sense. Thank you.

          – sbloom
          Nov 25 '18 at 22:39





          Just saw your comment re typo and VoiceResponse. Makes sense. Thank you.

          – sbloom
          Nov 25 '18 at 22:39




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426243%2fhow-do-i-retrieve-the-twilio-fax-pdf-and-attach-it-to-an-email-using-node-js-ins%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          RAC Tourist Trophy