You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

寻求Google Assistant通知现成示例(Dialogflow开发者需求)

Google Assistant Notification Ready-to-Use Examples

Hey there! Since you've already built an app with Dialogflow and have both a Google Home and mobile Google Assistant, let's dive into ready-to-use notification examples you can implement and test right away to see how Google Action notifications work in practice.

1. Minimal Text Notification (Quick to Deploy)

This is a basic example that sends a simple text notification after a short delay—perfect for testing the core notification flow:

  1. Head to your Dialogflow agent's Fulfillment tab and ensure Cloud Functions for Firebase is enabled.
  2. Replace the default fulfillment code with this snippet:
const functions = require('firebase-functions');
const { dialogflow, Suggestions } = require('actions-on-google');

const app = dialogflow({ debug: true });

// Intent to trigger notification setup
app.intent('Initiate Test Notification', (conv) => {
  // Verify user has granted notification permissions
  if (conv.user.verificationStatus !== 'VERIFIED') {
    return conv.ask('Could you please verify your Google account first? That way I can send you notifications.');
  }

  conv.ask('Got it! I\'ll send you a test notification in 1 minute. Keep an eye on your Assistant.');
  
  // Schedule the notification
  setTimeout(() => {
    conv.close({
      notification: {
        title: 'Test Notification',
        text: 'Hey, this is your first test notification from your Dialogflow app!'
      }
    });
  }, 60000);
});

exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
  1. In your Action Console, go to Features > Notifications to enable notifications, set a default title, and upload an icon (optional but recommended).
  2. Test it by saying something like "Hey Google, talk to [your app name] and send me a test notification" on your Google Home or mobile Assistant. Wait a minute, and you'll receive the notification—on mobile it'll show up in your Assistant feed, and Google Home will announce it when idle.

2. Rich Notification with Image & Action Button

If you want to see how more engaging notifications work, use this example to send a notification with an image and a clickable button (mobile-only for the button; Google Home will still announce the text):

Update your fulfillment code with this intent:

app.intent('Send Rich Test Notification', (conv) => {
  if (conv.user.verificationStatus !== 'VERIFIED') {
    return conv.ask('Let\'s get you verified first so I can send you rich notifications.');
  }

  conv.ask('Sending a fancy notification your way in 30 seconds!');
  
  setTimeout(() => {
    conv.close({
      notification: {
        title: 'Rich Test Notification',
        text: 'Check out this image and tap the button to learn more!',
        image: {
          url: 'https://picsum.photos/200/200', // Use any public image URL
          alt: 'Sample Notification Image'
        },
        actions: [
          {
            title: 'View More',
            type: 'URL',
            url: 'https://example.com' // Replace with a URL of your choice
          }
        ]
      }
    });
  }, 30000);
});

Add this intent to your Dialogflow agent, then trigger it with a phrase like "Hey Google, ask [your app name] to send a rich notification". On mobile, you'll see the image and button, while Google Home will read the notification text aloud.

Quick Notes for Testing

  • Make sure you've linked your Google account to your Dialogflow app and granted notification permissions when prompted.
  • For Google Home, notifications are only announced if the device isn't actively in use (e.g., playing music).
  • You can adjust the delay in the setTimeout function to make the notification arrive faster for testing.

内容的提问来源于stack exchange,提问作者Inzamam Malik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:24:22