我创建了一个我认为对某个社区有很大价值的行动。问题是我使用URL和APIKey访问API。它工作得很好,但是每个用户都有自己唯一的URL和APIKey。
我是否可以为每位用户设置和使用个性化设置?最好将这些值放在他们自己的谷歌帐户上,其中操作可以访问这些值,但我不能。
我能想到的唯一另一个选择就是简单地共享我的代码,进行自定义,但我认为谷歌还不支持私人助理。
答案 0 :(得分:1)
If you are just looking to store simple data for a user, you can use user storage which persists a JSON object for a user.
function simpleResponse(conv) {
conv.user.storage.count = 1;
conv.ask(new SimpleResponse({
speech: 'Howdy! I can tell you fun facts about ' +
'almost any number, like 42. What do you have in mind?',
text: 'Howdy! I can tell you fun facts about almost any ' +
'number. What do you have in mind?',
}));
}
If you are looking to use Firebase, as indicated in your tags, you can generate a unique ID for each user and save that ID into user storage. Afterwards, you can use that key as a way to look up the data in your database.
conv.user.storage.firebaseKey = '123';
firebase.database().ref('/data/123').once('value').then((snapshot) => {
let data = snapshot.val().myData;
});
答案 1 :(得分:1)
我得到了它的工作。我就是这样做的。反馈仍然是受欢迎的。
const parameters = request.body.queryResult.parameters;
function setKey(agent) {
conv.user.storage.apiKey = parameters.APIKey;
conv.ask('Ok, saving ' + parameters.APIKey);
agent.add(conv);
}
function getKey(agent) {
agent.add(`Your current key is ` + conv.user.storage.apiKey);
}