I want to update (add) responses for a specific intent of a dialogflow agent.
Suppose, there are 3 responses like in the image below, and i want to add 4th response.
I used update_intent
method, but was not able to get it done.
client = dialogflow.IntentsClient()
intent_name = client.intent_path(project_id, intent_id)
intent = client.get_intent(intent_name)
response_list = ['text response']
text = dialogflow.types.Intent.Message.Text(text=response_list)
message = dialogflow.types.Intent.Message(text=text)
intent.messages.extend([message])
response = client.update_intent(intent, language_code='en')
Using above code, my response is added but as a separate text response.
How can i add this as a 4th response?
UPDATE:
I tried adding text field to the Text object of intent.messages but could not find any method to add the text field.
intent.messages[0].text
text: "1st response"
text: "2nd response"
text: "3rd response"
intent.messages[0].text.add()
*** AttributeError: 'Text' object has no attribute 'add'
intent.messages[0].text.append()
*** AttributeError: 'Text' object has no attribute 'append'
intent.messages[0].text = text
*** TypeError: Can't set composite field
intent.messages[0].Text = ''
*** AttributeError: Assignment not allowed (no field "Text" in protocol message object).
This looks like the python client, correct?
The intent.messages
field contains a collection of rich message objects, including Text
objects. The Text
object contains a text
field which is a collection of text responses.
You're adding a new Text
object to intent.messages
, rather than adding a text response to the first Text
object in the existing intent.messages
collection.
It sounds like you should be going through intent.messages
to locate the first Text
object, then add another text value to the text
field in that object. Then calling client.update_intent
with the updates values.
As you note in the comments, you're able to do this with
intent.messages[0].text.text.append(response)