Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dialogflow - how to get session id?

First of all, I'm a noob with dialogflow and web services. I'm trying to integrate a dialogflow agent I just created and integrate it with my app on my local computer. I was able to get project_id and all other important information but no matter where I look, no one seems to talk about where they get session ids from. Here is the audio-to-text code that I'm using that was forked from api.ai github page:

import os
import dialogflow_v2 as dialogflow
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "My Google Credential"
project_id = 'project id'
session_id = "this i don't know where to get"
audio_file_path = 'my wave file directory name'
language_code = 'en'

def detect_intent_audio(project_id, session_id, audio_file_path,
                        language_code):
    """Returns the result of detect intent with an audio file as input.

    Using the same `session_id` between requests allows continuation
    of the conversaion."""

    session_client = dialogflow.SessionsClient()

    # Note: hard coding audio_encoding and sample_rate_hertz for simplicity.
    audio_encoding = dialogflow.enums.AudioEncoding.AUDIO_ENCODING_LINEAR_16
    sample_rate_hertz = 44100

    session = session_client.session_path(project_id, session_id)
    print('Session path: {}\n'.format(session))

    with open(audio_file_path, 'rb') as audio_file:
        input_audio = audio_file.read()

    audio_config = dialogflow.types.InputAudioConfig(
        audio_encoding=audio_encoding, language_code=language_code,
        sample_rate_hertz=sample_rate_hertz)
    query_input = dialogflow.types.QueryInput(audio_config=audio_config)

    response = session_client.detect_intent(
        session=session, query_input=query_input,
        input_audio=input_audio)

    print('=' * 20)
    print('Query text: {}'.format(response.query_result.query_text))
    print('Detected intent: {} (confidence: {})\n'.format(
        response.query_result.intent.display_name,
        response.query_result.intent_detection_confidence))
    print('Fulfillment text: {}\n'.format(
        response.query_result.fulfillment_text))

detect_intent_audio(project_id, session_id, audio_file_path,
                        language_code)

I enabled webhook and linked the webhook to heroku, but still I don't see where I can get this session ID. Can someone help me?

like image 405
Phillip1982 Avatar asked Aug 16 '18 01:08

Phillip1982


People also ask

What is Session ID in Dialogflow?

A session ID is a string of at most 36 bytes in size. Your system is responsible for generating unique session IDs. They can be random numbers, hashed end-user identifiers, or any other values that are convenient for you to generate.

How can I get Dialogflow Project ID?

Go into the Dialogflow agent's settings and check the Project ID associated with the agent. The GCP Project configured in the gcloud CLI should match the agent's Project ID.

How long does a Dialogflow session last?

All session data, including session entities, is stored by Dialogflow for 20 minutes.

How do I view Dialogflow logs?

Viewing Cloud logs Once you enable Cloud logging for an agent, you can browse these logs using the Cloud Logs Explorer. You can also access all of the logs for an agent by clicking the Open logs link in the agent's general settings.


1 Answers

On the link, https://dialogflow.com/docs/reference/api-v2/rest/v2/projects.agent.sessions/detectIntent , it is stated under the HTTP request session path parameters that "It's up to the API caller to choose an appropriate session ID. It can be a random number or some type of user identifier (preferably hashed). The length of the session ID must not exceed 36 bytes."

like image 79
saffetgokcensen Avatar answered Sep 20 '22 17:09

saffetgokcensen