ตอบกลับความคิดเห็น

ระดับการเขียนโค้ด: มือใหม่
ระยะเวลา: 15 นาที
ประเภทโปรเจ็กต์: การทำงานอัตโนมัติที่มีเมนูที่กำหนดเองและทริกเกอร์ที่ขับเคลื่อนด้วยเหตุการณ์

วัตถุประสงค์

  • ทำความเข้าใจโซลูชันที่ใช้
  • ทำความเข้าใจหน้าที่ของบริการ Apps Script ในโซลูชัน
  • ตั้งค่าสคริปต์
  • เรียกใช้สคริปต์

เกี่ยวกับโซลูชันนี้

สร้างอีเมลตอบกลับฉบับร่างเพื่อตอบกลับความคิดเห็นจาก Google ฟอร์มโดยอัตโนมัติ โซลูชันนี้จะมุ่งเน้นไปที่ความคิดเห็นเกี่ยวกับหลักสูตรจากนักเรียน แต่คุณสามารถนำไปใช้กับกรณีการใช้งานใดก็ได้ที่คุณได้รับความคิดเห็นผ่านทาง Google ฟอร์ม

การตอบกลับการส่งแบบฟอร์มที่ส่งจาก Gmail

วิธีการทำงาน

สคริปต์จะติดตั้งทริกเกอร์ที่ขับเคลื่อนด้วยเหตุการณ์ซึ่งจะทำงานทุกครั้งที่ผู้ใช้ส่งแบบฟอร์ม สคริปต์จะสร้างอีเมลฉบับร่างใน Gmail ทุกครั้งที่ส่งแบบฟอร์มแต่ละครั้ง อีเมลนี้จะส่งถึงผู้ที่ส่งแบบฟอร์ม พร้อมการตอบกลับแบบฟอร์มและข้อความขอบคุณทั่วไป คุณสามารถแก้ไขอีเมลก่อนส่ง

บริการ Apps Script

โซลูชันนี้ใช้บริการต่อไปนี้

  • บริการสคริปต์ - ติดตั้งทริกเกอร์ที่ขับเคลื่อนด้วยเหตุการณ์ซึ่งเริ่มทำงานเมื่อมีคนส่งแบบฟอร์ม
  • บริการสเปรดชีต ส่งแบบฟอร์มตอบกลับไปยัง Gmail
  • บริการ Gmail - สร้างร่างอีเมลที่มีข้อความขอบคุณและคำตอบในแบบฟอร์ม

ข้อกำหนดเบื้องต้น

หากต้องการใช้ตัวอย่างนี้ คุณต้องมีข้อกำหนดเบื้องต้นต่อไปนี้

  • บัญชี Google (บัญชี Google Workspace อาจต้องได้รับการอนุมัติจากผู้ดูแลระบบ)
  • เว็บเบราว์เซอร์ที่มีการเชื่อมต่ออินเทอร์เน็ต

ตั้งค่าสคริปต์

คลิกปุ่มต่อไปนี้เพื่อทำสำเนาสเปรดชีตตัวอย่างตอบกลับความคิดเห็น โปรเจ็กต์ Apps Script สำหรับโซลูชันนี้จะแนบไปกับสเปรดชีต
ทำสำเนา

เรียกใช้สคริปต์

  1. คลิกเครื่องมือตอบแบบฟอร์ม > เปิดใช้การตอบกลับฉบับร่างอัตโนมัติ คุณอาจต้องรีเฟรชหน้าเว็บ เพื่อให้เมนูที่กำหนดเองนี้ปรากฏขึ้น
  2. เมื่อได้รับข้อความแจ้ง ให้ให้สิทธิ์สคริปต์ หากหน้าจอความยินยอมของ OAuth แสดงคำเตือน แอปนี้ไม่ได้รับการยืนยัน ให้ดำเนินการต่อโดยเลือกขั้นสูง > ไปที่ {Project Name} (ไม่ปลอดภัย)

  3. คลิกเครื่องมือตอบแบบฟอร์ม > เปิดใช้การตอบกลับฉบับร่างอัตโนมัติอีกครั้ง

  4. คลิกเครื่องมือ > จัดการแบบฟอร์ม > ไปที่แบบฟอร์มที่ใช้งานอยู่

  5. กรอกข้อมูลในแบบฟอร์ม และคลิกส่ง

  6. เปิด Gmail และตรวจสอบข้อความร่าง คุณควรมีฉบับร่างใหม่ที่มีการตอบกลับแบบฟอร์ม

ตรวจสอบโค้ด

หากต้องการตรวจสอบโค้ด Apps Script สำหรับโซลูชันนี้ ให้คลิกดูซอร์สโค้ดด้านล่าง

ดูซอร์สโค้ด

Code.gs

solutions/automations/course-feedback-response/Code.js
// To learn how to use this script, refer to the documentation:
// https://developers.google.com/apps-script/samples/automations/course-feedback-response

/*
Copyright 2022 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/**
 * Creates custom menu for user to run scripts.
 */
function onOpen() {
  let ui = SpreadsheetApp.getUi();
  ui.createMenu('Form Reply Tool')
      .addItem('Enable auto draft replies', 'installTrigger')
      .addToUi();
}

/**
 * Installs a trigger on the Spreadsheet for when a Form response is submitted.
 */
function installTrigger() {
  ScriptApp.newTrigger('onFormSubmit')
      .forSpreadsheet(SpreadsheetApp.getActive())
      .onFormSubmit()
      .create();
}

/**
 * Creates a draft email for every response on a form
 *
 * @param {Object} event - Form submit event
 */
function onFormSubmit(e) {
  let responses = e.namedValues;

  // parse form response data
  let timestamp = responses.Timestamp[0];
  let email = responses['Email address'][0].trim();

  // create email body
  let emailBody = createEmailBody(responses);

  // create draft email
  createDraft(timestamp, email, emailBody);
}

/**
 * Creates email body and includes feedback from Google Form.
 *
 * @param {string} responses - The form response data
 * @return {string} - The email body as an HTML string
 */
function createEmailBody(responses) {
  // parse form response data
  let name = responses.Name[0].trim();
  let industry = responses['What industry do you work in?'][0];
  let source = responses['How did you find out about this course?'][0];
  let rating = responses['On a scale of 1 - 5 how would you rate this course?'][0];
  let productFeedback = responses['What could be different to make it a 5 rating?'][0];
  let otherFeedback = responses['Any other feedback?'][0];

  // create email body
  let htmlBody = 'Hi ' + name + ',<br><br>' +
    'Thanks for responding to our course feedback questionnaire.<br><br>' +
      'It\'s really useful to us to help improve this course.<br><br>' +
        'Have a great day!<br><br>' +
          'Thanks,<br>' +
            'Course Team<br><br>' +
              '****************************************************************<br><br>' +
                '<i>Your feedback:<br><br>' +
                  'What industry do you work in?<br><br>' +
                    industry + '<br><br>' +
                      'How did you find out about this course?<br><br>' +
                        source + '<br><br>' +
                          'On a scale of 1 - 5 how would you rate this course?<br><br>' +
                            rating + '<br><br>' +
                              'What could be different to make it a 5 rating?<br><br>' +
                                productFeedback + '<br><br>' +
                                  'Any other feedback?<br><br>' +
                                    otherFeedback + '<br><br></i>';

  return htmlBody;
}

/**
 * Create a draft email with the feedback
 *
 * @param {string} timestamp Timestamp for the form response
 * @param {string} email Email address from the form response
 * @param {string} emailBody The email body as an HTML string
 */
function createDraft(timestamp, email, emailBody) {
  console.log('draft email create process started');

  // create subject line
  let subjectLine = 'Thanks for your course feedback! ' + timestamp;

  // create draft email
  GmailApp.createDraft(
      email,
      subjectLine,
      '',
      {
        htmlBody: emailBody,
      }
  );
}

ผู้ร่วมให้ข้อมูล

ตัวอย่างนี้จัดทำโดย Ben Collins นักการศึกษาที่ benlcollins.com และผู้เชี่ยวชาญสำหรับนักพัฒนาซอฟต์แวร์ของ Google

ตัวอย่างนี้ดูแลโดย Google ด้วยความช่วยเหลือจากผู้เชี่ยวชาญด้านนักพัฒนาซอฟต์แวร์ของ Google

ขั้นตอนถัดไป