我正在为 Google 测试 Actions,所以我创建了一些简单的Sinatra应用程序,它看起来像:
require 'sinatra'
require 'json'
post '/google_assistant_api' do
content_type :json
case intent_name
when "input_welcome"
decorated_response
when "Recipe name"
basic_card
end
end
private
def decorated_response
{
source: "test source",
speech: "speech",
display_text: "something"
}.to_json
end
def intent_name
parsed_request["queryResult"]["intent"]["displayName"]
end
def parsed_request
@parsed_request ||= JSON.parse(request.body.read)
end
def basic_card
{
"fulfillmentText": "ACTIONS_ON_GOOGLE",
"fulfillmentMessages": [
{
"platform": "PLATFORM_UNSPECIFIED",
"text": {
"text": [
"string text"
]
},
"image": {
"imageUri": "https://avatars3.githubusercontent.com/u/119195?
s=400&v=4"
},
"basicCard": {
"title": "title string",
"subtitle": "subtitle",
"formattedText": "formatted text",
"image": {
"imageUri": "https://avatars3.githubusercontent.com/u/119195"
},
"buttons": []
}
}
],
"source": "source string"
}.to_json
end
请注意,我正在使用 API 的 V2 并使用谷歌助手进行测试:
我尝试了许多其他基于https://gist.github.com/manniru/f52af230669bd3ed2e69ffe4a76ab309的响应格式,但没有成功。我不断得到:
Sorry! there was no response from the Agent. Please try later.
有没有人幸运地尝试过非 nodejs 响应?我将不胜感激任何示例响应,因为简单的响应似乎有效,但是至于basic card
我没有运气。