question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to get session id on webhook with action-on-google lib

See original GitHub issue

question is also asked on stackoverflow as well: https://stackoverflow.com/questions/46368359/how-to-get-session-id-on-webhook

I’m making assistant app for google home and mobile assistant

I’m using action-on-google library on webhook which is recommended and handy

in my specific case I want to make userEntity from webhook which requires Session Id but I am unable to get the sessionid on webhook

according to api.ai document it sends Json to webhook like this:

{
                    "lang": "en",
                    "status": {
                        "errorType": "success",
                        "code": 200
                    },
                    "timestamp": "2017-02-09T16:06:01.908Z",
                    "sessionId": "1486656220806" "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": "[]"
                            }
                        }
                    }
                }

and ofcourse it is sending it correctly but on webhook we handover the request object to action-on-google and it returns an object with a bunch of methods like ask, askWithCarousel, askWithList and etc (documented here)

the problem is that there is not method to get conversation id documented then how do i get that session id:

my source code for reference:

/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

/actions/index.ts

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",
    //     "name":"city",
    //      "extend":false,
    //     "entries": [
    //         {
    //             "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'])
    )

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
Canaincommented, May 14, 2018

There isn’t a wrapper build in to retrieve the session for v2 still, but it should be easier to retrieve it from the raw body.

Should be conv.body.session for Dialogflow v2 and conv.body.sessionId for v1.

0reactions
rajnish-kumar-76commented, Jan 14, 2020

conv.body.conversation.conversationId

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to get session id on webhook - Stack Overflow
I'm using action-on-google library on webhook which is ... for your webhook, you should be able to access the sessionId with request.body.
Read more >
Session storage | Conversational Actions - Google Developers
For webhook calls, the state of session storage is passed in an app.handle() request and is stored in the session object. Data stored...
Read more >
SessionInfo | Dialogflow CX - Google Cloud
The unique identifier of the session . This field can be used by the webhook to identify a session. Format: projects/<Project ID>/locations/< ...
Read more >
Getting started with Actions on Google (Practically) - Medium
This is a tutorial for those who need practical hands-on session on ... But one thing to check is the Project ID, to...
Read more >
Build a Webhook for Google Assistant Action - Gitpod
We will be using the action-on-google Node JS library (This client library makes it easy to create Actions for the Google Assistant and ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found