dialogflow - how to get session id?
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."
Phillip1982
Updated on June 26, 2022Comments
-
Phillip1982 about 2 years
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?
-
Phillip1982 over 5 yearsI found out later that session id can be any string. Thank you though!
-
Gino over 4 yearsHi, i'm looking for this, i do not want to create a session id but access to the session id from javascript dialogflow V2
-
saffetgokcensen over 4 years@Gino You can try the following: exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => { const agent = new WebhookClient({ request, response }); console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers)); console.log('Dialogflow Request body: ' + JSON.stringify(request.body)); var session_id = request.body.session; var session_id_array = session_id.split("/"); session_id = session_id_array[session_id_array.length - 1];