【问题标题】:Google Action not deployingGoogle Action 未部署
【发布时间】:2020-09-14 19:15:11
【问题描述】:

我正在尝试在 Google Action 云功能中播放简单的音频流。它不会部署,因为它说代码中有错误,但它没有说在哪里。这是我的代码(请注意 *** cmets 中的替代方案 - 令人困惑,因为我不确定我应该使用哪个,已经看到了!

const { conversation } = require('@assistant/conversation');
const functions = require('firebase-functions');
const { MediaObject, SimpleResponse } = require('actions-on-google');

const app = actionssdk() // *** or 'const app = conversation()' ?
app.handle("playStream", conv => { // *** or 'app.intent(...' ?
    conv.ask(new SimpleResponse("Playing stream"));
    conv.ask(new MediaObject({
        name: 'My stream',
        url: 'https://stream.redacted.url',
        description: 'The stream',
        icon: new Image({
            url: 'https://image.redacted.url', alt: 'Media icon',
        }),
    }));
});

exports.ActionsOnGoogleFulfillment = functions.https.onRequest(app);

【问题讨论】:

    标签: actions-on-google google-assistant-sdk google-home


    【解决方案1】:

    您似乎混合使用了actions-on-google@assistant/conversation 库。您应该只使用其中一种,具体取决于您使用的平台。

    如果您使用的是原始 Actions SDK,则应使用actions-on-google。如果您使用的是新的 Actions SDK 或 Actions Builder,则应使用@assistant/conversation

    区别不同,但会导致问题。 actionssdk 有一个intent 方法,但没有一个handle 方法,反之亦然conversation。这可能会导致语法错误。还要确保您已导入所有内容,包括 Image

    const functions = require('firebase-functions')
    const {
      conversation,
      Media,
      Image,
    } = require('@assistant/conversation')
    
    const app = conversation()
    app.handle("playStream", conv => {
        conv.add("Playing stream");
        conv.add(new Media({
          mediaObjects: [{
            name: 'Media name',
            description: 'Media description',
            url: 'https://actions.google.com/sounds/v1/cartoon/cartoon_boing.ogg',
            image: {
              large: new Image({
                url: 'https://image.redacted.url',
                alt: 'Media icon',
              }),
            }
          }],
          mediaType: 'AUDIO',
          optionalMediaControls: ['PAUSED', 'STOPPED']
      }));
    })
    
    exports.ActionsOnGoogleFulfillment = functions.https.onRequest(app)
    

    如果这仍然不起作用,您应该添加您在尝试部署时看到的错误。

    【讨论】:

    • 进度,它现在正在构建,但失败并显示“无响应” - 在日志中,我收到“TypeError: conv.ask is not a function”
    • 啊,那是我的错。它也被重命名为 conv.add 而不是 conv.ask
    • 现在我得到“TypeError: MediaObject is not a constructor\n at app.handle.conv”
    • 似乎the way to compose Media 也发生了变化。我已经更新了我的示例。
    • 有效!感谢您的所有帮助尼克
    猜你喜欢
    • 2020-04-18
    • 2013-09-23
    • 2021-02-13
    • 1970-01-01
    • 1970-01-01
    • 2023-02-14
    • 1970-01-01
    • 1970-01-01
    • 2017-05-08
    相关资源
    最近更新 更多