I have a google form survey that I send to my app members. I want to include a way for them to create a custom Instagram story post that I'd auto-generate based on their input and email to them to post. The template I use to auto-generate it is a google doc with a placeholder where I plug in their custom input.
My script currently is able to send them the post as a PDF, but that's really frustrating to post on an Instagram story (if not impossible - I spent 20 mins trying to do it).
Is it possible to have the file send as a jpg or png? Or to add a step converting the PDF to a jpg or png?
function onSubmit(e) {
const rg = e.range;
const sh = rg.getSheet();
//Get all the form submitted data
//Note: This data is dependent on the headers. If headers, are changed update these as well.
const Email = e.namedValues["What's your email address?"][0];
const Name = e.namedValues["What's your name?"][0];
const Text = e.namedValues["If you want to make a custom Instagram story sharing what your experience was like, feel free to drop your text here!"][0];
//Build a new story from the template
//Folder ID (save destination) and file IDs (template ID + new doc ID)
const StoryFolderID = '1ghiNSWwkUS7WJ5wwnEON5g0-zRueYlfd';
const StoryFolder = DriveApp.getFolderById(StoryFolderID);
const TemplateFileID = '1IJ-i8VeazzmWlxyjyXXKHCLrA3pT1fgu4Zy_m74OgHc';
const newFilename = 'Story -' + TemplateFileID;
//Make a copy of the template file
const newTemplateFileID = DriveApp.getFileById(TemplateFileID).makeCopy(newFilename, StoryFolder).getId();;
//Get the body into a variable
var document = DocumentApp.openById(newTemplateFileID);
var body = document.getBody();
//Replace all the {{ }} text in the story body
body.replaceText('{{text}}', Text);
document.saveAndClose();
// define email variables
var subject = 'Instagram Story';
var img = DriveApp.getFileById("1d2jofSzEsxuUUEw5g-B684AKMALqyy-b").getBlob();
var msgHtml =
"Hi " + Name + "!" + "<br/>" + "<br/>" +
"Please find your custom story image attached." ;
var attachment = DriveApp.getFileById(newTemplateFileID);
//send email with the file
GmailApp.sendEmail(Email, subject, msgHtml, {htmlBody: msgHtml, inlineImages: {sampleImage: img}, attachments: [attachment.getAs(MimeType.PDF)]});
}