الردّ على الملاحظات

مستوى الترميز: مبتدئ
المدة: 15 دقيقة
نوع المشروع: تشغيل آلي من خلال قائمة مخصّصة ومشغّل مستند إلى الحدث

الأهداف

  • فهم ما يفعله الحل.
  • تعرّف على ما تفعله خدمات "برمجة التطبيقات" ضمن الحل.
  • أعِدّ النص البرمجي.
  • شغِّل النص البرمجي.

لمحة عن هذا الحلّ

يمكنك تلقائيًا إنشاء مسودات لردود الرسائل الإلكترونية على الملاحظات من "نماذج Google". يركز هذا الحل على ملاحظات الدورة التدريبية من الطلاب، ولكن يمكنك تطبيقه على أي حالة استخدام تتلقى ملاحظات عنها عبر "نماذج Google".

ردود إرسال النموذج من Gmail

آلية العمل

يثبّت النص البرمجي مشغِّلاً مستندًا إلى الحدث يتم تشغيله في كل مرة يُرسل فيها المستخدم نموذجًا. مع كل عملية إرسال للنموذج، يُنشئ النص البرمجي مسودة رسالة إلكترونية في Gmail. يتم توجيه الرسالة الإلكترونية إلى الشخص الذي أرسل النموذج ويتضمن ردود النموذج ورسالة شكر عامة. يمكنك تعديل البريد الإلكتروني قبل إرساله.

خدمات "برمجة التطبيقات"

يستخدم هذا الحل الخدمات التالية:

  • خدمة النص البرمجي - تثبِّت المشغّل المستند إلى الحدث الذي يتم تنشيطه عندما يُرسل أحد الأشخاص نموذجًا.
  • خدمة جدول البيانات - ترسل ردود النموذج إلى Gmail.
  • خدمة Gmail - تنشئ مسودة الرسالة الإلكترونية باستخدام رسالة الشكر وردود النموذج.

المتطلبات الأساسية

لاستخدام هذا النموذج، ستحتاج إلى المتطلّبات الأساسية التالية:

  • حساب Google (قد تتطلب حسابات Google Workspace موافقة المشرف).
  • متصفح ويب يمكنه الوصول إلى الإنترنت.

إعداد النص البرمجي

انقر على الزر التالي لإنشاء نسخة من نموذج جدول البيانات الردّ على الملاحظات. تم إرفاق مشروع "برمجة تطبيقات Google" لهذا الحل بجدول البيانات.
إنشاء نسخة

تشغيل النص البرمجي

  1. انقر على أداة الرد على نموذج > تفعيل مسودات الردود التلقائية. قد تحتاج إلى تحديث الصفحة حتى تظهر هذه القائمة المخصّصة.
  2. امنح الإذن للنصّ البرمجي عند مطالبتك بذلك. إذا عرضت شاشة طلب الموافقة المتعلّقة ببروتوكول OAuth التحذير، لم يتم التحقّق من هذا التطبيق، يمكنك المتابعة من خلال اختيار إعدادات متقدّمة > الانتقال إلى {Project Name} (غير آمن).

  3. انقر على أداة الرد على النموذج > تفعيل الردود التلقائية مرة أخرى.

  4. انقر على أدوات > إدارة النموذج > الانتقال إلى النموذج المباشر.

  5. املأ النموذج وانقر على إرسال.

  6. افتح Gmail وتحقَّق من المسودات. يجب أن يكون لديك مسودّة جديدة تحتوي على ردّ النموذج.

مراجعة الرمز

لمراجعة رمز برمجة التطبيقات لهذا الحل، انقر على عرض رمز المصدر أدناه:

عرض رمز المصدر

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,
      }
  );
}

المساهمون

أنشأ هذا النموذج "بن كولينز"، وهو معلّم في النطاق benlcollins.com وخبير في المطوّرين لدى Google.

  • يمكنك العثور على "بن" على Twitter من خلال الرابط @benlcollins.
  • قراءة مدونة بن.

تحتفظ Google بهذا النموذج بمساعدة خبراء التطوير في Google.

الخطوات التالية