I'm working on a script to programmatically create a bunch of intents. I want to set the input context for these intents to a specific value. I have working code that creates the full intent - but I can't get the parameter for input context to work.
This works (in python), but does not create an input context:
intents_client = dialogflow_v2beta1.IntentsClient.from_service_account_json(PROJECT_JSON)
parent = intents_client.project_agent_path(PROJECT_ID)
training_phrases = []
part1 = dialogflow_v2beta1.types.Intent.TrainingPhrase.Part(text="hello ")
parts = []
parts.append(part1)
training_phrase = dialogflow_v2beta1.types.Intent.TrainingPhrase(parts=parts)
training_phrases.append(training_phrase)
text = dialogflow_v2beta1.types.Intent.Message.Text(text=["say hello"])
message = dialogflow_v2beta1.types.Intent.Message(text=text)
messages = []
messages.append(message)
intent = dialogflow_v2beta1.types.Intent(
display_name='Mike_Hello',
training_phrases=training_phrases,
messages=messages)
response = intents_client.create_intent(parent, intent, language_code=LANGUAGE)
But, when I add the following to my Intent definition:
intent = dialogflow_v2beta1.types.Intent(
display_name='Mike_Hello',
input_context_names=['5000'],
training_phrases=training_phrases,
messages=messages)
(ie - adding the input_context_names
parameter)
The intent creation fails with an error:
Resource name does not match format 'projects/{project_id}/agent/sessions/{session_id}/contexts/{context_id}'
I tried creating a context with a context client and create_context
, but it fails with the same error. The create_context
API seems to me to be more related to creating a context for inputting into detect_intent
, as it wants a live SESSION_ID as input.
I can replace ["5000"]
in the input_context above with 'projects/PROJECT_ID/agent/sessions/-/contexts/5000'
, and I get the same error.
Bug? Or am I missing something?
['projects/PID/agent/sessions/-/contexts/CID']
looks like it should be correct. Two questions: (1) Are you sure it is in a list (the way you write it isn't quite clear what your code actually looks like). (2) Is "5000" the actual name? Have you tried something with a leading letter or no numbers at all? (The docs say that "5000" should be a valid CID, but worth a try.) – Prisoner