【问题标题】:Unable to respond with basic_card on Actions on Google无法在 Actions on Google 上使用 basic_card 回复
【发布时间】:2017-12-10 15:11:09
【问题描述】:

我正在使用 Api.ai 构建一个应用程序,我需要通过基本卡响应名为 Login 的 Intent。我正在尝试这个没有 webhook 实现。 通过 Api.ai 尝试部分,我的查询返回以下内容:

{
  "id": "bb09aa94-a2d0-48d5-8c7f-62fc688d17b1",
  "timestamp": "2017-07-06T13:19:30.776Z",
  "lang": "en",
  "result": {
"source": "agent",
"resolvedQuery": "login",
"action": "Login",
"actionIncomplete": false,
"parameters": {},
"contexts": [],
"metadata": {
  "intentId": "39842aa0-53c4-4d47-b3b7-61ba0fc6d80c",
  "webhookUsed": "false",
  "webhookForSlotFillingUsed": "false",
  "intentName": "account.login"
},
"fulfillment": {
  "speech": "You should visit http://www.curlpad.com for login.",
  "messages": [
    {
      "type": "basic_card",
      "platform": "google",
      "title": "Login to Curlpad",
      "subtitle": "",
      "formattedText": "Visit this link to login to your account",
      "image": {
        "url": "http://www.curlpad.com/favicons/apple-icon.png"
      },
      "buttons": [
        {
          "title": "Curlpad",
          "openUrlAction": {
            "url": "http://www.curlpad.com"
          }
        }
      ]
    },
    {
      "type": 1,
      "platform": "telegram",
      "title": "Curlpad | Login",
      "subtitle": "Click on login button to continue",
      "imageUrl": "http://www.curlpad.com/favicons/apple-icon.png",
      "buttons": [
        {
          "text": "Login",
          "postback": "http://www.curlpad.com/"
        }
      ]
    },
    {
      "type": 0,
      "speech": "Open this url http://www.curlpad.com"
    }
  ]
},
"score": 1
  },
  "status": {
"code": 200,
"errorType": "success"
  },
  "sessionId": "7ba9cd11-239c-4467-8c3f-2d79d867ba18"
}

电报卡在我的电报机器人上运行良好,但在 Google 上的操作上出现错误。 这是对动作模拟器的回应:

其他查询在该模拟器上运行良好。 任何人都可以帮助完成这项工作吗? 我还有一个意图搜索使用 webhook 实现工作的用户,在返回 basic_card 时我也遇到了同样的问题。

在 api.ai 上尝试的意图响应屏幕截图:

【问题讨论】:

  • 您能否分享您意图的响应部分的屏幕图像,同时选择了默认选项卡和 Google 上的操作选项卡?
  • 我会检查: 1. 您已登录(为了安全起见,请尝试使用隐身模式)。 2. 您在 onsole.api.ai 中启用了该操作 3. 尝试使用 'Test' 从 api.ai 进行检查
  • @IdoGreen 在 Api.ai 测试中,它运行良好。在其他 Intent 的 Actions Simulator 上表现也不错。
  • 我添加了带有默认和操作响应和测试的屏幕截图。
  • 我在 basic_card 中添加了“简单响应”,现在我在 Actions 控制台中收到了一个错误的卡片。 Error Type MalformedResponse expected_inputs[0].input_prompt.rich_initial_prompt.items[1].basic_card.image: 'accessibility_text' is required.

标签: dialogflow-es actions-on-google


【解决方案1】:

如果您不使用 webhook,则需要按照循环执行以下 3 个步骤 在下面的屏幕截图中启用基本卡响应。如果您没有看到“在 GOOGLE 上的操作”选项卡,请单击 + 号添加它。

如果您使用的是 webhook,下面是适用于我的示例代码。您也可以按照下面的 google 文档进行操作。 google basic card documentation

'use strict';

const express = require('express')();
const router = require('express').Router();
const bodyParser = require('body-parser');
const ApiAiApp = require('actions-on-google').ApiAiApp;

express.use(bodyParser.json({type: 'application/json'}));

router.post('/card', (req, res) => {
	const app = new ApiAiApp({request: req, response: res});
	const WELCOME_INTENT = 'input.welcome';

	const actionMap = new Map();
	actionMap.set(WELCOME_INTENT, welcomeIntent);
	app.handleRequest(actionMap);
	
});

function welcomeIntent(app){
	app.ask(app.buildRichResponse()
	// Create a basic card and add it to the rich response
	.addSimpleResponse('Math and prime numbers it is!')
		.addBasicCard(app.buildBasicCard(`42 is an even composite number. It
		 is composed of three distinct prime numbers multiplied together. It
		 has a total of eight divisors. 42 is an abundant number, because the
		 sum of its proper divisors 54 is greater than itself. To count from
		 1 to 42 would take you about twenty-one…`)
		 .setTitle('Math & prime numbers')
		 .addButton('Read more')
		 .setImage('https://example.google.com/42.png', 'Image alternate text')
		)
	);
}

express.use('/example', router);

express.listen('8081', function () {
  console.log('Example app is running')
})

【讨论】:

  • 这个intent没有webhook,所以想直接使用api.ai。
  • 我在顶部添加了一个新部分,向您展示如何在不使用 webhook 的情况下进行操作。请看我的更新。
  • 我在Api.ai中也做了同样的我添加了更多的截图,你可以查看。
  • 如果我启用“使用选项卡中的默认响应作为第一个响应”,我会收到卡片,但它会给出一些验证错误。
  • 你在手机上测试过吗?如果它有效,您可以忽略该错误。它也发生在我身上。这应该只是一个警告。
【解决方案2】:

问题是没有“基本响应”的情况下不支持“基本卡”,因此我们需要先设置“基本响应”或使用默认选项卡中的响应作为第一个响应。

basic_card 必须提供基本回复

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-28
    相关资源
    最近更新 更多