Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Voicemail .wav file attached instead of link #111

Closed
LinuxFanboy opened this issue Sep 5, 2023 · 1 comment
Closed

Voicemail .wav file attached instead of link #111

LinuxFanboy opened this issue Sep 5, 2023 · 1 comment

Comments

@LinuxFanboy
Copy link

Hi,

I would like to know if there is any option that I can use to attach the recorded message instead of link which is default solution.
I saw thanks to this #78 that it's doable probably with axios and some changes in the code... But I'm not sure. I hope we can find a good way to do it. Attaching recording as a file is better for my purpose just because of the access issues.

If you have any snippets, templates or ideas please share 😁

Thanks in advance!

@LinuxFanboy
Copy link
Author

Hi, I found a way to achieve this kind of solution, maybe somebody else will be happy with this, please find below:

1. Add this:

const AWS = require("aws-sdk");
const s3 = new AWS.S3();

2. Modify sendMail with your adaptation:

[
... Rest of the code
return new Promise((s, i) => { ...
]

const bucketName = "<YOUR-BUCKET-NAME>";

// Extract the filename from the preSignedUrl provided in the r object
const filename = r.preSignedUrl.url.split("/").pop().split("?")[0];

const objectKey = "recordings/" + filename;

s3.getObject({ Bucket: bucketName, Key: objectKey }, (err, data) => {
  if (err) {
    console.log("Error fetching the file from S3:", err);
    return i(err);
  }

  mailOptions.attachments = [
    {
      filename: "voicemail.wav",
      content: data.Body,
      contentType: "audio/wav", // Specifying the MIME type
    },
  ];

  this.transporter.sendMail(mailOptions, (e, t) => {
    if (e) {
      console.log("Error while sending email:", e); // Debug log
      return i(e);
    }
    s(t);
  });
});

The file is fetched from S3 Bucket so normally the recording.wav is added to an email as an attachment.

Hope you enjoy it! 😁

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant