每日更新 (Dialogflow)

使用者在手機上訂閱動作的每日更新

如果您的動作每天會為使用者帶來價值,請設定每日更新,提醒使用者使用這項功能。當使用者訂閱動作的每日更新內容時,他們會收到推播通知,只要輕觸一下就能叫用動作的意圖。

使用者受到這些更新的影響如下:

  1. 使用者叫用您設為每日更新的其中一項動作意圖。
  2. 使用者依照提示訂閱每日更新。這個提示會在對話期間發出,或在對話結束時顯示為建議方塊。
  3. 使用者會排定在一天中的哪些時段接收每日動態更新,並向 Google 助理註冊您的更新。
  4. 在每天排定的時間,使用者在行動裝置上收到 Google 助理通知。
  5. 使用者開啟通知時,會叫用您設為每日更新的意圖,並進行互動。

根據預設,當使用者成功結束動作時,每日更新註冊提示會顯示為建議方塊。您也可以新增對話中註冊提示,或提供個人化的使用者更新內容。

應用情境

每日更新是實用的參與度工具,但不應納入每個動作。在決定是否將每日更新訂閱新增到動作時,請考慮以下提示:

  • 請確保每日更新能夠讓使用者每天看到不同的實用資訊。如果輕觸每日更新後每次都顯示相同提示,使用者可能會在幾天內取消訂閱。
  • 當使用者直接跳到每日更新的意圖時,請確保使用者會覺得對話方塊合理。使用者不一定會從對話開始時就開始,因此不應提供太多背景資訊。
  • 提示使用者瞭解動作的優點,再提示使用者註冊每日更新。當使用者針對訂閱選項提供訂閱選項時,您應認為「每天都想要這項內容」呢?
  • 請勿重複提供報名建議,以免讓使用者感到疲乏。在使用者展示訂閱內容後立即提供每日更新訂閱項目,避免在其他情境中重複使用優惠。
  • 在觸發更新意圖後,讓對話保持簡短。大部分的每日更新都應只包含單一回應,而關閉時不需要使用者輸入內容。

設定每日更新

在 Dialogflow 中探索

按一下「繼續」,即可在 Dialogflow 中匯入每日更新範例。接著,請按照下列步驟部署及測試範例:

  1. 輸入虛擬服務專員名稱,並為範例建立新的 Dialogflow 代理程式。
  2. 代理程式匯入完成後,按一下「Go to agent」
  3. 從主要導覽選單中,前往「Fulfillment」
  4. 啟用「Inline Editor」(內嵌編輯器),然後按一下「Deploy」(部署)。編輯器包含程式碼範例。
  5. 在主要導覽選單中,前往「Integrations」(整合),然後按一下「Google Assistant」(Google 助理)
  6. 在出現的互動視窗中,啟用「Auto-preview changes」,按一下「Test」,開啟動作模擬工具。
  7. 在模擬工具中輸入 Talk to my test app 即可測試範例!
繼續

如要設定動作的其中一個每日更新意圖,請按照下列說明操作:

1. 準備更新意圖

將動作的意圖設為觸發意圖。此意圖可以向使用者傳送每日更新;當使用者開啟每日更新通知時,意圖會觸發,而對話也會從該位置繼續對話。

如要在 Dialogflow 中定義觸發意圖,請執行下列操作:

  1. Dialogflow 主控台中,按一下「Integrations」
  2. 按一下「Google Assistant」部分底下的「Integration Settings」
  3. 在「Discovery」>「Implicit 叫用」下方,按一下「Add intent」(新增意圖),然後選取要觸發的意圖 (如果還沒的話)。
  4. 開啟「自動預覽」變更 (如果尚未啟用)。
  5. 點按「關閉」

在 Actions SDK 中,將更新意圖定義為動作套件中的觸發意圖。

2. 啟用更新

如要為觸發意圖啟用每日更新功能,請按照下列步驟操作:

  1. Actions 主控台中,依序前往「Develop」(開發) >「Actions」(動作)
  2. 選取觸發意圖。如果您的意圖並未顯示在清單中,請確認該意圖已設定為觸發意圖,而 Dialogflow 的 Google 助理整合作業已設定為自動預覽變更。
  3. 向下捲動至「User engagement」(使用者參與度) 部分,然後開啟「Would you like to provide day to users」(提供每日更新給使用者)
  4. 輸入「內容標題」
  5. 點按「儲存」

您現在已設定動作,可針對意圖提供每日更新訂閱項目。您現在可以在自己的行動裝置上測試每日更新。

自訂更新註冊 (選用)

除了建議方塊和 Google 助理處理的每日更新註冊流程外,您還可以透過自己的對話方塊和註冊提示,向使用者訂閱每日最新動態。

如需處理選用每日更新功能的完整動作範例,請參閱 Actions on Google 使用者參與度範例 (Node.jsJava)。

如要在對話中新增自訂每日更新註冊提示,請按照下列指示操作:

1. 新增註冊提示

如果您想提示使用者訂閱每日最新動態,可在對話中新增對話方塊和建議方塊。請在使用者與更新意圖互動後提供這些提示,讓他們瞭解每日更新的內容。

下列程式碼範例會提示使用者訂閱每日更新,提供每日最低的預期溫度:

Node.js
app.intent('Daily Lowest Temperature', (conv, params) => {
  const today = DAYS[new Date().getDay()];
  const lowestTemperature = lowestTemperatures[today];
  conv.ask(`The lowest temperature for today is ${lowestTemperature}`);
  conv.ask('I can send you daily updates with the lowest temperature' +
    ' of the day. Would you like that?');
  conv.ask(new Suggestions('Send daily updates'));
});
Java
@ForIntent("Daily Lowest Temperature")
public ActionResponse dailyLowestTemperature(ActionRequest request) {
  ResponseBuilder responseBuilder = getResponseBuilder(request);
  Integer lowestTemperature =
      LOWEST_TEMPERATURES.get(LocalDate.now().getDayOfWeek());
  responseBuilder
      .add("The lowest temperature for today is " +  lowestTemperature + " degrees Fahrenheit.")
      .add("I can send you daily updates with the lowest temperature of " +
          "the day. Would you like that?")
      .addSuggestions(new String[] {
          "Send daily updates"
      });
  return responseBuilder.build();
}
Dialogflow JSON

請注意,以下 JSON 說明 Webhook 回應。

{
  "payload": {
    "google": {
      "expectUserResponse": true,
      "richResponse": {
        "items": [
          {
            "simpleResponse": {
              "textToSpeech": "The lowest temperature for today is 75 degrees Fahrenheit"
            }
          },
          {
            "simpleResponse": {
              "textToSpeech": "I can send you daily updates with the lowest temperature of the day. Would you like that?"
            }
          }
        ],
        "suggestions": [
          {
            "title": "Send daily updates"
          }
        ]
      }
    }
  }
}
Actions SDK JSON

請注意,以下 JSON 說明 Webhook 回應。

{
  "expectUserResponse": true,
  "expectedInputs": [
    {
      "possibleIntents": [
        {
          "intent": "actions.intent.TEXT"
        }
      ],
      "inputPrompt": {
        "richInitialPrompt": {
          "items": [
            {
              "simpleResponse": {
                "textToSpeech": "The lowest temperature for today is 75 degrees Fahrenheit"
              }
            },
            {
              "simpleResponse": {
                "textToSpeech": "I can send you daily updates with the lowest temperature of the day. Would you like that?"
              }
            }
          ],
          "suggestions": [
            {
              "title": "Send daily updates"
            }
          ]
        }
      }
    }
  ]
}

2. 處理更新註冊

設定新的意圖,在使用者遵循註冊提示時觸發。在這個新意圖的執行要求中,使用以下參數觸發 actions_intent_CONFIGURE_UPDATES 內建意圖

  • intent:設為您設定的更新意圖。
  • frequency - 設為「DAILY」。

以下程式碼會註冊「每日最低溫度」意圖的每日更新:

Dialogflow Node.js
app.intent('Subscribe to Daily Updates', (conv) => {
  conv.ask(new RegisterUpdate({
    intent: 'Daily Lowest Temperature',
    frequency: 'DAILY',
  }));
});
Actions SDK Node.js
conv.ask(new RegisterUpdate({
  intent: 'Daily Lowest Temperature',
  frequency: 'DAILY',
}));
Dialogflow Java
@ForIntent("Subscribe to Daily Updates")
public ActionResponse subscribeToDailyUpdates(ActionRequest request) {
  ResponseBuilder responseBuilder = getResponseBuilder(request);
  return responseBuilder.add(new RegisterUpdate()
      .setIntent("Daily Lowest Temperature")
      .setFrequency("DAILY"))
      .build();
}
Actions SDK Java
ResponseBuilder responseBuilder = getResponseBuilder(request);
return responseBuilder.add(new RegisterUpdate()
    .setIntent("Daily Lowest Temperature")
    .setFrequency("DAILY"))
    .build();
Dialogflow JSON
{
  "payload": {
    "google": {
      "expectUserResponse": true,
      "systemIntent": {
        "intent": "actions.intent.REGISTER_UPDATE",
        "data": {
          "@type": "type.googleapis.com/google.actions.v2.RegisterUpdateValueSpec",
          "intent": "Daily Lowest Temperature",
          "triggerContext": {
            "timeContext": {
              "frequency": "DAILY"
            }
          }
        }
      }
    }
  }
}
Actions SDK JSON
{
  "expectUserResponse": true,
  "expectedInputs": [
    {
      "possibleIntents": [
        {
          "intent": "actions.intent.REGISTER_UPDATE",
          "inputValueData": {
            "@type": "type.googleapis.com/google.actions.v2.RegisterUpdateValueSpec",
            "intent": "Daily Lowest Temperature",
            "triggerContext": {
              "timeContext": {
                "frequency": "DAILY"
              }
            }
          }
        }
      ]
    }
  ]
}

3. 處理結果

Google 助理會接手您的對話,並引導使用者完成其餘的每日更新設定。註冊完成後,Google 助理會使用參數觸發意圖,指出註冊是否成功。

這個步驟的操作說明會因您使用 Dialogflow 或 Actions SDK 進行開發而異。

Dialogflow

請按照下列步驟建立處理註冊結果的意圖:

  1. Dialogflow 控制台中建立新的意圖。
  2. 新增 actions_intent_REGISTER_UPDATE 事件。
  3. 為意圖啟用 Webhook 執行要求。
  4. 點按「儲存」
在意圖的執行要求中,請查看 registered 參數來取得結果,並據此調整對話。
Dialogflow Node.js
app.intent('Confirm Daily Updates Subscription', (conv, params, registered) => {
  if (registered && registered.status === 'OK') {
    conv.close(`Ok, I'll start giving you daily updates.`);
  } else {
    conv.close(`Ok, I won't give you daily updates.`);
  }
});
Dialogflow Java
@ForIntent("Confirm Daily Updates Subscription")
public ActionResponse confirmDailyUpdatesSubscription(ActionRequest request) {
  ResponseBuilder responseBuilder = getResponseBuilder(request);
  if (request.isUpdateRegistered()) {
    responseBuilder.add("Ok, I'll start giving you daily updates.");
  } else {
    responseBuilder.add("Ok, I won't give you daily updates.");
  }
  return responseBuilder.endConversation().build();
}
Dialogflow JSON
{
  "payload": {
    "google": {
      "expectUserResponse": false,
      "richResponse": {
        "items": [
          {
            "simpleResponse": {
              "textToSpeech": "Ok, I'll start giving you daily updates."
            }
          }
        ]
      }
    }
  }
}
Actions SDK

在執行要求程式碼中,新增 actions.intent.REGISTER.UPDATE 內建意圖的處理方式。請查看 registered 參數來取得結果,並據此調整對話。

Actions SDK Node.js
app.intent('actions.intent.REGISTER_UPDATE', (conv, params, registered) => {
  if (registered && registered.status === 'OK') {
    conv.close(`Ok, I'll start giving you daily updates.`);
  } else {
    conv.close(`Ok, I won't give you daily updates.`);
  }
});
Actions SDK Java
@ForIntent("actions.intent.REGISTER_UPDATE")
public ActionResponse confirmDailyUpdatesSubscription(ActionRequest request) {
  ResponseBuilder responseBuilder = getResponseBuilder(request);
  if (request.isUpdateRegistered()) {
    responseBuilder.add("Ok, I'll start giving you daily updates.");
  } else {
    responseBuilder.add("Ok, I won't give you daily updates.");
  }
  return responseBuilder.endConversation().build();
}
Actions SDK JSON
{
  "expectUserResponse": false,
  "finalResponse": {
    "richResponse": {
      "items": [
        {
          "simpleResponse": {
            "textToSpeech": "Ok, I'll start giving you daily updates."
          }
        }
      ]
    }
  }
}

個人化最新資訊 (選用)

為了個人化您的更新意圖,請在使用者註冊每日更新時新增自訂參數。執行更新意圖時,請參考這些參數,為該使用者自訂每日更新。

這項功能的操作說明會因您使用 Dialogflow 或 Actions SDK 進行開發而有所不同。

Dialogflow

定義 Dialogflow 實體來處理更新項目的自訂參數,然後將參數值做為更新意圖的引數。如要在 Dialogflow 中設定個人化更新功能,請按照下列步驟操作:

  1. Dialogflow 控制台中建立新實體。
  2. 新增一些與您的參數相關的項目和同義詞。
  3. 按一下「儲存」,然後開啟更新意圖。
  4. 在「動作和參數」部分,將 actions.intent.CONFIGURE_UPDATES 設為事件。在同一個區段新增與新實體相同類型的參數。
  5. 開啟處理 CONFIGURE_UPDATES 內建意圖的「更新註冊」意圖。
  6. 在「動作和參數」部分新增必要參數,並將其類型設為先前建立的實體。
  7. 更新註冊意圖的執行要求程式碼,加入含有下列內容的 arguments 物件
    • name - 在 Dialogflow 中設定的參數名稱。
    • textValue - 參數的值。

以下程式碼會讀取參數值,並在更新註冊要求中使用:

Dialogflow Node.js
app.intent('setup_update', (conv) => {
  conv.ask(new RegisterUpdate({
    intent: 'update_of_the_day',
    arguments: [
      {
        name: 'category',
        textValue: 'Daily_lowest_temperature',
      },
    ],
    frequency: 'DAILY',
  }));
});
Dialogflow Java
@ForIntent("setup_update")
public ActionResponse setupUpdate2(ActionRequest request) {
  List<Argument> args =
      Arrays.asList(
          new Argument()
              .setName("category")
              .setTextValue(request.getParameter("category").toString()));
  return getResponseBuilder(request)
      .add(new RegisterUpdate().setIntent("intent_name").setArguments(args).setFrequency("DAILY"))
      .build();
}
Dialogflow JSON
{
  "payload": {
    "google": {
      "expectUserResponse": true,
      "richResponse": {
        "items": [
          {
            "simpleResponse": {
              "textToSpeech": "PLACEHOLDER"
            }
          }
        ]
      },
      "userStorage": "{\"data\":{}}",
      "systemIntent": {
        "intent": "actions.intent.REGISTER_UPDATE",
        "data": {
          "@type": "type.googleapis.com/google.actions.v2.RegisterUpdateValueSpec",
          "intent": "update_of_the_day",
          "arguments": [
            {
              "name": "category",
              "textValue": "Daily_lowest_temperature"
            }
          ],
          "triggerContext": {
            "timeContext": {
              "frequency": "DAILY"
            }
          }
        }
      }
    }
  },
  "outputContexts": [
    {
      "name": "/contexts/_actions_on_google",
      "lifespanCount": 99,
      "parameters": {
        "data": "{}"
      }
    }
  ]
}
Actions SDK

透過意圖執行要求向使用者要求其他資訊,然後將該資訊做為更新意圖的引數。如要在 Actions SDK 中設定個人化更新,請按照下列步驟操作:

  1. 提示使用者您想用來提供個人化服務的資訊。
  2. 在處理 CONFIGURE UPDATES 的「更新註冊」意圖的執行要求程式碼中,加入含有下列內容的 arguments 物件
    • name:引數名稱。
    • textValue - 要做為引數傳送的使用者資訊。

下列程式碼會傳送含有更新註冊要求的引數:

Actions SDK Node.js
app.intent('actions.intent.TEXT', (conv) => {
  if (conv.input.raw === 'Send daily') {
    conv.ask(new RegisterUpdate({
      intent: 'update_of_the_day',
      arguments: [
        {
          name: 'category',
          textValue: 'Daily_lowest_temperature',
        },
      ],
      frequency: 'DAILY',
    }));
  }
});
Actions SDK Java
@ForIntent("actions.intent.CONFIGURE_UPDATES")
public ActionResponse configureUpdatesActionsSdk(ActionRequest request) {
  List<Argument> args =
      Arrays.asList(
          new Argument()
              .setName("category")
              .setTextValue(request.getParameter("category").toString()));
  return getResponseBuilder(request)
      .add(new RegisterUpdate().setIntent("intent_name").setArguments(args).setFrequency("DAILY"))
      .build();
}

@ForIntent("actions.intent.TEXT")
public ActionResponse text(ActionRequest request) {
  ResponseBuilder rb = getResponseBuilder(request);
  String input = request.getRawInput().getQuery();
  if (input.equals("DAILY_NOTIFICATION_SUGGESTION")) {
    rb.add("For which category do you want to receive daily updates?");
  } else {
    rb.add("Sorry, I didn't get that. Please try again later").endConversation();
  }
  return rb.build();
}
Actions SDK JSON
{
  "expectUserResponse": true,
  "expectedInputs": [
    {
      "inputPrompt": {
        "richInitialPrompt": {
          "items": [
            {
              "simpleResponse": {
                "textToSpeech": "PLACEHOLDER"
              }
            }
          ]
        }
      },
      "possibleIntents": [
        {
          "intent": "actions.intent.REGISTER_UPDATE",
          "inputValueData": {
            "@type": "type.googleapis.com/google.actions.v2.RegisterUpdateValueSpec",
            "intent": "update_of_the_day",
            "arguments": [
              {
                "name": "category",
                "textValue": "Daily_lowest_temperature"
              }
            ],
            "triggerContext": {
              "timeContext": {
                "frequency": "DAILY"
              }
            }
          }
        }
      ]
    }
  ],
  "conversationToken": "{\"data\":{}}",
  "userStorage": "{\"data\":{}}"
}

當使用者叫用每日更新時,更新意圖現在會加入引數,其中包含使用者在註冊期間提供的值。這些值可用來為每位使用者提供個人化的更新體驗。

測試每日更新

在行動裝置上使用 Google 助理測試每日更新,方法是使用建立動作時所用的 Google 帳戶。請叫用動作並訂閱每日更新,然後在更新時間附近查看裝置的通知。