フィードバックへの対応

コーディング レベル: 初級
所要時間: 15 分
プロジェクトの種類: カスタム メニューイベント ドリブン トリガー

目標

  • ソリューションの機能を理解する
  • コンテナ内で Apps Script サービスが 説明します。
  • スクリプトを設定します。
  • スクリプトを実行します。

このソリューションについて

Google フォームからフィードバックに対する返信メールの下書きを自動作成できます。この このソリューションは生徒からのコースのフィードバックに焦点を当てていますが、あらゆるユースケースに適用できます。 Google フォームでフィードバックを受け取ったユースケースの場合です。

Gmail から送信されるフォーム送信の回答

仕組み

このスクリプトは、ユーザーがイベントを送信するたびに実行されるイベント ドリブン トリガーをインストールします。 フォームに入力してください。フォームが送信されるたびに、スクリプトによって Gmail でメールの下書きが作成されます。「 フォームを送信した本人、フォームを含むメールアドレスが記載されていること 一般的なお礼メッセージなどですメールアドレスは、 送信します。

Apps Script サービス

このソリューションでは、次のサービスを使用します。

  • Script サービス - イベント ドリブンをインストールします。 ユーザーがフォームを送信すると発生します
  • スプレッドシート サービス - フォームを送信します。 Gmail に返信できます。
  • Gmail サービス - メールの下書きを作成します。 お礼メッセージやフォームの回答などです

前提条件

このサンプルを使用するには、次の前提条件を満たす必要があります。

  • Google アカウント(Google Workspace アカウントは 管理者の承認が必要です)。
  • インターネットにアクセスできるウェブブラウザ。

スクリプトを設定する

次のボタンをクリックして、フィードバックへの回答のサンプルのコピーを作成します。 表示されます。これに対応する Apps Script プロジェクトでは、 スプレッドシートに添付されます。
コピーを作成

スクリプトを実行する

  1. [フォーム返信ツール] > をクリックします。 返信の下書きの自動作成を有効にする。そのためにはページの更新が必要になることがあります カスタム メニューが表示されます。
  2. プロンプトが表示されたら、スクリプトを承認します。 OAuth 同意画面に [このアプリは確認されていません] という警告が表示された場合は、 [詳細設定] > を選択して続行します {プロジェクト名}(安全でない)に移動します

  3. フォーム返信ツール > [自動を有効にする] をクリックします 返信の下書きを再度クリックします。

  4. [ツール] > [フォームを管理] をクリックします。 > [実際のフォームに移動] をタップします。

  5. フォームに必要事項を記入し、[送信] をクリックします。

  6. Gmail を開いて下書きを確認します。新しい下書きが必要です 次のフォームを使用 レスポンスが返されます。

コードを確認する

このソリューションの Apps Script コードを確認するには、 以下のソースコードを表示します。

ソースコードを表示

コード.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 の教育者である Ben Collins によって作成されました。 Google Developer Expert です

  • Twitter(@benlcollins)で Ben を検索してください。
  • Ben のブログをご覧ください。

このサンプルは、Google Developer Experts のサポートのもと、Google によって管理されています。

次のステップ