Skip to content

Instantly share code, notes, and snippets.

@szhu
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szhu/32511d45050e9053bf1e to your computer and use it in GitHub Desktop.
Save szhu/32511d45050e9053bf1e to your computer and use it in GitHub Desktop.
// Source:
// https://sites.google.com/a/steegle.com/steegle/websites/google-sites-howtos/apps-script-contact-us-form-email
function nl_to_br(input_string){
return input_string.replace(/(\r\n|\r|\n){2,}/g,'<br />&nbsp;<br />\n').replace(/(\r\n|\r|\n)/g,'<br />\n');
}
function onFormSubmit(e) {
var recipient = 'trigger@recipe.ifttt.com';
var timestamp = e.values[0];
var confession = e.values[1];
var subject = "#confessions"; // CHANGE THIS HASHTAG IF YOU WANT
var textBody = nl_to_br(confession);
var advancedArgs = {};
MailApp.sendEmail(recipient, subject, textBody, advancedArgs);
}

Here's how this setup works:

  1. Someone submits the form.
  2. It gets added to the Google Spreadsheet and triggers a Google Apps Script.
  3. The script sends an email to trigger@recipe.ifttt.com on your behalf.
  4. IFTTT will recieve this email from you and post on your Facebook page.

tl;dr: form → spreadsheet → Apps Script trigger → email → IFTTT → Facebook page

To set up:

  1. Make sure your Google Form feeds into a Google spreadsheet.
  2. In the spreadsheet, go to: Tools » Script Editor.
  3. In the Script Editor window, paste in the contents of confessions-ifttt-bridge.js.
  4. Go to Resources » Current Project's Triggers.
  5. Add a trigger for: onFormSubmit, from spreadsheet, on form submit.
  6. Go to IFTTT.com and make an account if you don't have one.
  7. Go add one of these recipes: For posting to a page: https://ifttt.com/recipes/266435
    For posting to a profile: https://ifttt.com/recipes/309536
  8. When you activate the Email channel on IFTTT, make sure you use the email address tied with the Google account where you set up the App Script trigger (doesn't have to be the same account that owns the spreadsheet). If they don't match, you can edit your Email channel config here: https://ifttt.com/email

Finished all that? You should be good to go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment