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

วิธีการทำงาน
สคริปต์จะติดตั้งทริกเกอร์ที่ขับเคลื่อนด้วยเหตุการณ์ซึ่งจะทํางานทุกครั้งที่ผู้ใช้ส่งแบบฟอร์ม
เมื่อมีการส่งแบบฟอร์มแต่ละครั้ง สคริปต์จะสร้างอีเมลฉบับร่างใน Gmail
อีเมลจะส่งถึงผู้ที่ส่งแบบฟอร์มและมีคำตอบของแบบฟอร์ม
และข้อความขอบคุณทั่วไป คุณแก้ไขอีเมลก่อนส่งได้
บริการ Apps Script
โซลูชันนี้ใช้บริการต่อไปนี้
- บริการสคริปต์ - ติดตั้งทริกเกอร์ที่ขับเคลื่อนด้วยเหตุการณ์
ซึ่งจะเริ่มทำงานเมื่อมีผู้ส่งแบบฟอร์ม
- บริการสเปรดชีต - ส่งคำตอบของแบบฟอร์ม
ไปยัง Gmail
- บริการ Gmail - สร้างอีเมลฉบับร่างพร้อมข้อความขอบคุณและคำตอบในแบบฟอร์ม
ข้อกำหนดเบื้องต้น
หากต้องการใช้ตัวอย่างนี้ คุณต้องมีข้อกำหนดเบื้องต้นต่อไปนี้
- บัญชี Google (บัญชี Google Workspace อาจต้อง
ได้รับการอนุมัติจากผู้ดูแลระบบ)
- เว็บเบราว์เซอร์ที่มีสิทธิ์เข้าถึงอินเทอร์เน็ต
ตั้งค่าสคริปต์
คลิกปุ่มต่อไปนี้เพื่อทำสำเนาสเปรดชีตตัวอย่างตอบกลับความคิดเห็น
โปรเจ็กต์ Apps Script สำหรับโซลูชันนี้
แนบมากับสเปรดชีต
ทำสำเนา
เรียกใช้สคริปต์
- คลิกเครื่องมือตอบกลับแบบฟอร์ม >
เปิดใช้การตอบกลับแบบร่างอัตโนมัติ คุณอาจต้องรีเฟรชหน้าเว็บเพื่อให้เมนูที่กำหนดเองนี้ปรากฏ
ให้สิทธิ์สคริปต์เมื่อได้รับข้อความแจ้ง
หากหน้าจอคำยินยอมของ OAuth แสดงคำเตือนว่า แอปนี้ยังไม่ได้รับการยืนยัน
ให้ดำเนินการต่อโดยเลือกขั้นสูง >
ไปที่ {ชื่อโปรเจ็กต์} (ไม่ปลอดภัย)
คลิกเครื่องมือตอบกลับแบบฟอร์ม > เปิดใช้การตอบกลับแบบร่างอัตโนมัติอีกครั้ง
คลิกเครื่องมือ > จัดการแบบฟอร์ม
> ไปที่แบบฟอร์มที่ใช้งานจริง
กรอกข้อมูลในแบบฟอร์ม และคลิกส่ง
เปิด Gmail แล้วตรวจสอบฉบับร่าง คุณควรมีฉบับร่างใหม่
พร้อมแบบฟอร์ม
คำตอบ
ตรวจสอบโค้ด
หากต้องการตรวจสอบโค้ด Apps Script สำหรับโซลูชันนี้ ให้คลิกดูซอร์สโค้ดด้านล่าง
ผู้ร่วมให้ข้อมูล
ตัวอย่างนี้สร้างโดย Ben Collins นักการศึกษาที่ benlcollins.com
และผู้เชี่ยวชาญด้านการพัฒนาของ Google
ตัวอย่างนี้ได้รับการดูแลโดย Google โดยได้รับความช่วยเหลือจาก Google Developer Expert
ขั้นตอนถัดไป
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 UTC"],[[["\u003cp\u003eThis solution automatically creates draft email replies to Google Forms feedback using an event-driven trigger.\u003c/p\u003e\n"],["\u003cp\u003eThe script uses the Script, Spreadsheet, and Gmail services to install the trigger, retrieve form data, and create draft emails, respectively.\u003c/p\u003e\n"],["\u003cp\u003eSetting up involves making a copy of the provided spreadsheet and enabling auto draft replies via the custom menu.\u003c/p\u003e\n"],["\u003cp\u003eTo run the script, enable replies, fill out and submit the form, then check your Gmail drafts for the automatically generated draft email containing the form responses.\u003c/p\u003e\n"]]],[],null,["# Respond to feedback\n\n**Coding level** : Beginner \n\n**Duration** : 15 minutes \n\n**Project type** : Automation with a [custom menu](/apps-script/guides/menus) and\nan [event-driven trigger](/apps-script/guides/triggers/installable#event-driven_triggers)\n\nObjectives\n----------\n\n- Understand what the solution does.\n- Understand what the Apps Script services do within the solution.\n- Set up the script.\n- Run the script.\n\nAbout this solution\n-------------------\n\nAutomatically create draft email replies to feedback from Google Forms. This\nsolution focuses on course feedback from students, but you can apply it to any\nuse case for which you receive feedback via Google Forms.\n\n### How it works\n\nThe script installs an event-driven trigger that runs each time a user submits a\nform. With each form submission, the script creates an email draft in Gmail. The\nemail is addressed to the person who submitted the form and includes the form\nresponses and a generic thank-you message. You can edit the email before you\nsend it.\n\n### Apps Script services\n\nThis solution uses the following services:\n\n- [Script service](/apps-script/reference/script)--Installs the event-driven trigger that fires when someone submits a form.\n- [Spreadsheet service](/apps-script/reference/spreadsheet)--Sends the form responses to Gmail.\n- [Gmail service](/apps-script/reference/gmail)--Creates the email draft with the thank-you message and form responses.\n\nPrerequisites\n-------------\n\nTo use this sample, you need the following prerequisites:\n\n- A Google Account (Google Workspace accounts might require administrator approval).\n- A web browser with access to the internet.\n\nSet up the script\n-----------------\n\nClick the following button to make a copy of the **Respond to feedback** sample\nspreadsheet. The Apps Script project for this\nsolution is attached to the spreadsheet.\n\n[Make a copy](https://docs.google.com/spreadsheets/d/18cHBZp8iCICnoqECeSqMWbem3XJdIQnLd9xyVEAI1JM/copy)\n\nRun the script\n--------------\n\n1. Click **Form reply tool** \\\u003e **Enable auto draft replies**. You might need to refresh the page for this custom menu to appear.\n2. When prompted, authorize the script.\n If the OAuth consent screen displays the warning, **This app isn't verified** ,\n continue by selecting **Advanced** \\\u003e\n **Go to {Project Name} (unsafe)**.\n\n3. Click **Form reply tool** \\\u003e **Enable auto\n draft replies** again.\n\n4. Click **Tools** \\\u003e **Manage form**\n \\\u003e **Go to live form**.\n\n5. Fill out the form and click **Submit**.\n\n6. Open Gmail and check your drafts. You should have a new draft\n with the form\n response.\n\nReview the code\n---------------\n\nTo review the Apps Script code for this solution, click\n**View source code** below: \n\n#### View source code\n\n### Code.gs\n\n\u003cbr /\u003e\n\nsolutions/automations/course-feedback-response/Code.js \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/solutions/automations/course-feedback-response/Code.js) \n\n```javascript\n// To learn how to use this script, refer to the documentation:\n// https://developers.google.com/apps-script/samples/automations/course-feedback-response\n\n/*\nCopyright 2022 Google LLC\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n https://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\n/**\n * Creates custom menu for user to run scripts.\n */\nfunction onOpen() {\n let ui = SpreadsheetApp.getUi();\n ui.createMenu('Form Reply Tool')\n .addItem('Enable auto draft replies', 'installTrigger')\n .addToUi();\n}\n\n/**\n * Installs a trigger on the Spreadsheet for when a Form response is submitted.\n */\nfunction installTrigger() {\n ScriptApp.newTrigger('onFormSubmit')\n .forSpreadsheet(SpreadsheetApp.getActive())\n .onFormSubmit()\n .create();\n}\n\n/**\n * Creates a draft email for every response on a form\n *\n * @param {Object} event - Form submit event\n */\nfunction onFormSubmit(e) {\n let responses = e.namedValues;\n\n // parse form response data\n let timestamp = responses.Timestamp[0];\n let email = responses['Email address'][0].trim();\n\n // create email body\n let emailBody = createEmailBody(responses);\n\n // create draft email\n createDraft(timestamp, email, emailBody);\n}\n\n/**\n * Creates email body and includes feedback from Google Form.\n *\n * @param {string} responses - The form response data\n * @return {string} - The email body as an HTML string\n */\nfunction createEmailBody(responses) {\n // parse form response data\n let name = responses.Name[0].trim();\n let industry = responses['What industry do you work in?'][0];\n let source = responses['How did you find out about this course?'][0];\n let rating = responses['On a scale of 1 - 5 how would you rate this course?'][0];\n let productFeedback = responses['What could be different to make it a 5 rating?'][0];\n let otherFeedback = responses['Any other feedback?'][0];\n\n // create email body\n let htmlBody = 'Hi ' + name + ',\u003cbr\u003e\u003cbr\u003e' +\n 'Thanks for responding to our course feedback questionnaire.\u003cbr\u003e\u003cbr\u003e' +\n 'It\\'s really useful to us to help improve this course.\u003cbr\u003e\u003cbr\u003e' +\n 'Have a great day!\u003cbr\u003e\u003cbr\u003e' +\n 'Thanks,\u003cbr\u003e' +\n 'Course Team\u003cbr\u003e\u003cbr\u003e' +\n '****************************************************************\u003cbr\u003e\u003cbr\u003e' +\n '\u003ci\u003eYour feedback:\u003cbr\u003e\u003cbr\u003e' +\n 'What industry do you work in?\u003cbr\u003e\u003cbr\u003e' +\n industry + '\u003cbr\u003e\u003cbr\u003e' +\n 'How did you find out about this course?\u003cbr\u003e\u003cbr\u003e' +\n source + '\u003cbr\u003e\u003cbr\u003e' +\n 'On a scale of 1 - 5 how would you rate this course?\u003cbr\u003e\u003cbr\u003e' +\n rating + '\u003cbr\u003e\u003cbr\u003e' +\n 'What could be different to make it a 5 rating?\u003cbr\u003e\u003cbr\u003e' +\n productFeedback + '\u003cbr\u003e\u003cbr\u003e' +\n 'Any other feedback?\u003cbr\u003e\u003cbr\u003e' +\n otherFeedback + '\u003cbr\u003e\u003cbr\u003e\u003c/i\u003e';\n\n return htmlBody;\n}\n\n/**\n * Create a draft email with the feedback\n *\n * @param {string} timestamp Timestamp for the form response\n * @param {string} email Email address from the form response\n * @param {string} emailBody The email body as an HTML string\n */\nfunction createDraft(timestamp, email, emailBody) {\n console.log('draft email create process started');\n\n // create subject line\n let subjectLine = 'Thanks for your course feedback! ' + timestamp;\n\n // create draft email\n GmailApp.createDraft(\n email,\n subjectLine,\n '',\n {\n htmlBody: emailBody,\n }\n );\n}\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nContributors\n------------\n\nThis sample was created by Ben Collins, Educator at [benlcollins.com](https://www.benlcollins.com/)\nand Google Developer Expert.\n\n- Find Ben on Twitter [@benlcollins](https://twitter.com/benlcollins).\n- Read Ben's [blog](https://www.benlcollins.com/).\n\nThis sample is maintained by Google with the help of Google Developer Experts.\n\nNext steps\n----------\n\n- [Event-driven triggers](/apps-script/guides/triggers/installable#event-driven_triggers)\n- [Custom menus in Google Workspace](/apps-script/guides/menus)"]]