hackforla / 311-data

Empowering Neighborhood Associations to improve the analysis of their initiatives using 311 data
https://hackforla.github.io/311-data/
GNU General Public License v3.0
60 stars 60 forks source link

Complete contact form functionality with Google Form #1780

Open Skydodle opened 6 days ago

Skydodle commented 6 days ago

Overview

We need to complete the contact form functionality so that users may submit their feedbacks/ concerns as a Github issue on our repo using the form.

More Info

We will integrate Google Form on the Contact Page and replace the current form. Access token would be store in Apps Script project. Users would also receive a confirmation email after feedback submission.

Action Items

Update 06-27-24: Removing EmailJS from implementation due to EmailJS API restricts request from non-browser environment like Google Apps Script. We will be using an Google Form Extension to send confirmation email instead.

Resources/Instructions

Script to put in Apps Script

function onFormSubmit(e) {
  const formResponse = e.response; // Use the FormResponse object
  const itemResponses = formResponse.getItemResponses(); // Get all item responses

  // Extract responses using the correct indices
  const fullName = itemResponses[0].getResponse(); // Full Name
  const email = itemResponses[1].getResponse(); // Email
  const neighborhoodAssociation = itemResponses[2].getResponse() || 'Not provided'; // Neighborhood Association
  const message = itemResponses[3].getResponse(); // Message

  // Construct title and body for GitHub issue
  const title = `Feedback from ${fullName} (${email})`;
  const body = `**Full Name:** ${fullName}\n**Email:** ${email}\n**Neighborhood Association:** ${neighborhoodAssociation}\n**Message:**\n${message}`;

  // GitHub API configuration
  const GITHUB_ORG = 'hackforla'; // Replace with your organization name
  const GITHUB_REPO = '311-data'; // Replace with the repository name
  const GITHUB_TOKEN = PropertiesService.getScriptProperties().getProperty('GITHUB_TOKEN');

  const url = `https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/issues`;
  const payload = {
    'title': title,
    'body': body
  };

  const options = {
    'method': 'post',
    'contentType': 'application/json',
    'headers': {
      'Authorization': `token ${GITHUB_TOKEN}`
    },
    'payload': JSON.stringify(payload)
  };

  // Sending the request to create the GitHub issue
  const response = UrlFetchApp.fetch(url, options);
  Logger.log(response.getContentText());
}

function setUpTrigger() {
  const form = FormApp.getActiveForm();
  ScriptApp.newTrigger('onFormSubmit')
           .forForm(form)
           .onFormSubmit()
           .create();
}
ryanfchase commented 6 days ago

Approving as a repurpose of this ticket, replacing Google Apps Script instead of OctokitJS: https://github.com/hackforla/311-data/issues/1682

ryanfchase commented 6 days ago

This ticket is ready to be picked up (aka resumed by @Skydodle)

Skydodle commented 4 days ago

ETA: Friday 6/28 Availability: M-F

Skydodle commented 3 days ago

The Google Form is embeded on the Contact Page. Both features of posting to Github issue and send email confirmation are completed. Just waiting on the bot account to be created and provide me with the access token. Thanks.

ryanfchase commented 2 days ago

@Skydodle we were able to move forward with creating the bot. It has read/write permissions for 311-Data and 311-Data-Write teams.

Bot Info

Accessing the Personal Access Token