[英]How to access request object in the new dialogflow API
In the actions on google request object I have accessToken that I'm setting via account linking 在Google请求对象上的操作中,我具有通过帐户关联设置的accessToken
{
"user": {
"userId": "user_id",
"accessToken": "access_token",
"locale": "en-US",
"lastSeen": "2018-06-05T09:52:35Z",
"userStorage": "{\"data\":{}}"
},
etc
My firebase function allows to look for values in the Firebase database when the intent is triggered. 我的firebase函数允许在触发意图时在Firebase数据库中查找值。
import * as admin from 'firebase-admin'
import * as functions from 'firebase-functions'
import { dialogflow } from 'actions-on-google'
const dialogApp = dialogflow();
dialogApp.intent("request_value", async (conv, {devices}) => {
console.log(devices);
let device_name = devices;
const snapshot = await admin.database().ref(`/system/ecofarmTest/component/${device_name}/data`).orderByChild("timestamp").limitToFirst(1).once('value');
snapshot.forEach(function(childSnapshot) {
console.log("Test child timestamp " + childSnapshot.val().timestamp)
console.log("Test child value " + childSnapshot.val().value)
const value_object = childSnapshot.val();
conv.ask(`The ${device_name} is ${value_object.value}.\nWould you like to check anything else?`);
return;
})
});
export const receiveAssistantRequest = functions.https.onRequest(dialogApp);
Before the API change I new how to access the request object. 在更改API之前,我新增了如何访问请求对象的方法。 But now, how do I access the request object to get the accessToken?
但是现在,如何访问请求对象以获取accessToken?
帐户链接完成后,您可以使用访问您的access_token
conv.user.access.token
我找到了方法:
let access_token = conv.request.user.accessToken
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.