简体   繁体   English

如何在新的dialogflow API中访问请求对象

[英]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.

相关问题 如何在没有 Cloud Functions 的情况下从 iOS (Swift) 向 Dialogflow V2 API 发送请求? - How to send request from iOS (Swift) to Dialogflow V2 API without Cloud Functions? 如何在Dialogflow Webhook中返回对会话的API响应 - How to return API response to conversation in Dialogflow Webhook 在没有firebase的情况下,如何在dialogflow实现中向其他服务发出http请求? - How to make a http request to other service in dialogflow fulfillment without firebase? 无法在DialogFlow和Google动作中发出API请求。 尚未设定回应 - Can't make a API request in DialogFlow and actions-on-google. No response has been set 在现有令牌过期后,如何使用 firebase 刷新令牌请求新的访问令牌? - How can I request a new access token after the existing token expires with the firebase refresh token? 如何使用api通过http get请求访问Firebase数据库数据 - How to access Firebase database data through http get request by using api 如何访问对象的数据? - How to access to the data of an object? 如何将 Python 与 Dialogflow 聊天机器人连接起来 - How to connect Python with Dialogflow Chatbot Dialogflow api调用有效,但是chatbot关闭 - Dialogflow api call works, but chatbot shuts off 如何通过Dialogflow中的内联编辑器将Dialogflow连接到Cloud Firestore? - How to connect Dialogflow to Cloud Firestore via the Inline Editor in Dialogflow?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM