Session 如何在webhook上获取会话id
我正在为google home和Android mobile assistant制作助手应用程序 我正在使用webhook上的库,这是推荐的,而且很方便 在我的特定情况下,我想从webhook创建一个会话Id,但我无法在webhook上获取会话Id 据了解,它将Json发送到webhook,如下所示:Session 如何在webhook上获取会话id,session,bots,actions-on-google,api-ai,Session,Bots,Actions On Google,Api Ai,我正在为google home和Android mobile assistant制作助手应用程序 我正在使用webhook上的库,这是推荐的,而且很方便 在我的特定情况下,我想从webhook创建一个会话Id,但我无法在webhook上获取会话Id 据了解,它将Json发送到webhook,如下所示: { "lang": "en", "status": { "errorType": "success", "code": 200 },
{
"lang": "en",
"status": {
"errorType": "success",
"code": 200
},
"timestamp": "2017-02-09T16:06:01.908Z",
"sessionId": "1486656220806" <<<<<<<<======here is session id
"result": {
"parameters": {
"city": "Rome",
"name": "Ana"
},
"contexts": [],
"resolvedQuery": "my name is Ana and I live in Rome",
"source": "agent",
"score": 1.0,
"speech": "",
"fulfillment": {
"messages": [
{
"speech": "Hi Ana! Nice to meet you!",
"type": 0
}
],
"speech": "Hi Ana! Nice to meet you!"
},
"actionIncomplete": false,
"action": "greetings",
"metadata": {
"intentId": "9f41ef7c-82fa-42a7-9a30-49a93e2c14d0",
"webhookForSlotFillingUsed": "false",
"intentName": "greetings",
"webhookUsed": "true"
}
},
"id": "ab30d214-f4bb-4cdd-ae36-31caac7a6693",
"originalRequest": {
"source": "google",
"data": {
"inputs": [
{
"raw_inputs": [
{
"query": "my name is Ana and I live in Rome",
"input_type": 2
}
],
"intent": "assistant.intent.action.TEXT",
"arguments": [
{
"text_value": "my name is Ana and I live in Rome",
"raw_text": "my name is Ana and I live in Rome",
"name": "text"
}
]
}
],
"user": {
"user_id": "PuQndWs1OMjUYwVJMYqwJv0/KT8satJHAUQGiGPDQ7A="
},
"conversation": {
"conversation_id": "1486656220806",
"type": 2,
"conversation_token": "[]"
}
}
}
}
/actions/index.ts
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';
import { Request, Response } from "express"; //interfaces
const ActionsSdkApp = require('actions-on-google').ApiAiAssistant;
import db from '../db';
// API.AI Action names
import {
inputWelcome
} from './actions'
const WELCOME_INTENT = 'input.welcome';
export const webhook = functions.https.onRequest(async (request: Request, response: Response) => {
console.log("request.body: ", request.body);
console.log("request.body.sessionId: ", request.body.sessionId);
const app = new ActionsSdkApp({ request: request, response: response });
let actionMap = new Map();
actionMap.set(WELCOME_INTENT, inputWelcome);
app.handleRequest(actionMap);
})//end of webhook http trigger
import * as request from 'request';
export function inputWelcome(app: any) {
//I WANT SESSION ID HERE
console.log("app.conversation(): ", app.conversation());
console.log("app.AppRequest: ", app.AppRequest);
console.log("app.AppRequest.conversation: ", app.AppRequest.conversation);
console.log("app.AppRequest(): ", app.AppRequest());
console.log("app.AppRequest().conversation: ", app.AppRequest().conversation);
console.log("app.getUser().accessToken;: ", app.getUser().accessToken)
const accessToken = app.getUser().accessToken;
// MAKE USER ENTITY WITH THESE DATA:
// {
// "sessionId": "current conversation id here",
// "entities": [
// {
// "name": "option1",
// "entries": [
// {
// "value": "option1",
// "synonyms": [
// "first",
// "option one"
// ]
// }
// ]
// },
// {
// "name": "option2",
// "entries": [
// {
// "value": "option2",
// "synonyms": [
// "second one",
// "second option"
// ]
// }
// ]
// },
// {
// "name": "option3",
// "entries": [
// {
// "value": "option3",
// "synonyms": [
// "third one",
// "third option"
// ]
// }
// ]
// },
// {
// "name": "help",
// "entries": [
// {
// "value": "help",
// "synonyms": [
// "help",
// "need help",
// "ditn't get",
// "need support"
// ]
// }
// ]
// }
// ]
// }
//
// AND THEN ASK THE USER WITH SUGGESTION CHIPS
app.ask(app.buildRichResponse()
.addSimpleResponse({
speech: `Hi you can start with these things`,
displayText: `Hi you can start with these things`
})
.addSuggestions(['option1', 'option2', 'option3', 'Help'])
)
}
支持人士说: 嗨 感谢您对谷歌行动的兴趣。如果您正在使用 nodejs对于您的webhook,您应该能够访问sessionId 使用request.body.sessionId。可以将该值存储在变量中 并在函数的后续阶段使用它 问候 Jean Charles,谷歌支持团队的行动
您是否在google node js客户端库上使用操作?是的,在google上使用操作您可能会遇到API.AI sessionID来自GAC对话ID的问题,也许你是通过API.AI UI而不是GAC模拟器进行测试。我正在使用GAC模拟器进行测试。目前,当使用客户端库时,无法获得
seSSIONID
。是的,但你使用的是TypeScript,而不是一般的Javascript库。我已经完成了测试,它在TypeScript中为我工作,但仍在寻找一个干净的脚本解决方案