【发布时间】:2018-02-20 15:26:13
【问题描述】:
如何使用 python 创建函数来实现?
building fulfillments 的文档使用 Node.js 和 Firebase Cloud Function for fulfillment hosting。此处使用Actions SDK。
下面的示例代码只是调用应用程序并模仿用户说的第一个语音。
'use strict';
const ActionsSdkApp = require('actions-on-google').ActionsSdkApp;
const functions = require('firebase-functions');
exports.analizeInput= (req, res) => {
const app = new ActionsSdkApp({request: req, response: res});
// Create functions to handle requests here
function handleMainIntent() {
let inputPrompt = app.buildInputPrompt(false, 'This is <app-name>');
app.ask(inputPrompt);
}
function handleTextIntent() {
app.tell("you said, " + app.getRawInput());
}
let actionMap = new Map();
actionMap.set(app.StandardIntents.MAIN, handleMainIntent);
actionMap.set(app.StandardIntents.TEXT, handleTextIntent);
app.handleRequest(actionMap);
}
代码在 fullments 端点中使用 Node.js 语言。也可以使用其他语言。但是,没有关于如何使用其他语言设置履行端点的可用资源。我想知道如何使用python创建一个像上面这样简单的。
from flask import Flask
from flask import jsonify
app = Flask(__name__)
@app.route('/')
def hello_world():
//I do not know where to use this JSON (this is the app.ask() in Node.js)
data = {
"conversationToken": "",
"expectUserResponse": true,
"expectedInputs": [{
"inputPrompt": {
"richInitialPrompt": {
"items": [{
"simpleResponse": {
"textToSpeech": "Howdy! I can tell you fun facts about almost any number, like 42. What do you have in mind?",
"displayText": "Howdy! I can tell you fun facts about almost any number. What do you have in mind?"
}
}],
"suggestions": []
}
},
"possibleIntents": [{
"intent": "actions.intent.TEXT"
}]
}]
}
return jsonify(data)
if __name__ == '__main__':
app.run()
这是我使用 Heroku 设置和部署的简单 REST 端点。据我了解,如果使用的语言不是“示例代码”部分here 中所见的 Node.js,则使用 JSON。但是,我被困在如何处理请求、给出响应以及设置与 Google 助理相关的意图上。我也不知道将文档中建议的 JSON 放在哪里。我什至不知道如何开始。如果您能抢先一步,我将不胜感激。
谢谢
【问题讨论】:
-
我不知道如何回答这个问题。我确实知道如何使用本地托管的 Node 为您设置一个开发环境,这样您就可以在 Google 平台上的 Action 和一个琐碎的 Action 之间监视 JSON 有效负载的 POST。如果您认为有帮助,我会发布答案。在其他人用 Python 解释这笔交易之前,您可以看看这个developers.google.com/actions/reference/rest/…
-
@WilliamDePalo 我想你可以帮助我,虽然我不能确定多少。我感谢您的帮助。我有兴趣查看平台和操作本身之间的有效负载。这可能有助于我了解他们的联系。
标签: python heroku flask actions-on-google