dialogflow - 如何获取会话 ID?

dialogflow - how to get session id?

首先,我是一个 dialogflow 和 web 服务的菜鸟。我正在尝试集成我刚刚创建的 dialogflow 代理并将其与本地计算机上的应用程序集成。我能够获得 project_id 和所有其他重要信息,但无论我在哪里看,似乎都没有人谈论他们从哪里获得会话 ID。这是我正在使用的音频到文本代码,它是从 api.ai github 页面分叉出来的:

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)

我启用了 webhook 并将 webhook 链接到 heroku,但我仍然看不到从哪里可以获得此会话 ID。有人可以帮助我吗?

在 link 上, https://dialogflow.com/docs/reference/api-v2/rest/v2/projects.agent.sessions/detectIntent ,在 HTTP 请求会话路径参数下说明 "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."