Best you can do is use the solution above, but if you don’t want to define the sentences in the actions but in the domain instead, you can get the domain as a JSON (dictionary) in a custom action using the domain
variable.
So to get the responses for utter_goodbye
, you can do this:
goodbyes = domain['responses']['utter_goodbye']
goodbyes = filter(lambda x: 'text' in x and len(x['text']) > 0, goodbyes)
goodbyes = map(lambda x: x['text'], goodbyes)
The first line will get you the responses for utter_goodbye
as a dict
, like in the domain. For example:
responses:
utter_greet:
- text: "Hey! How are you?"
buttons:
- title: "great"
payload: "/mood_great"
- title: "super sad"
payload: "/mood_sad"
- text: "Hello! What's up?"
channel: "slack"
- image: "https://i.imgur.com/nGF1K8f.jpg"
- text: "Hey! Nice to see you again! How are you?"
condition:
- type: slot
name: logged_in
value: true
{
"responses": {
"utter_greet": [
{
"text": "Hey! How are you?",
"buttons": [
{
"title": "great",
"payload": "/mood_great"
},
{
"title": "super sad",
"payload": "/mood_sad"
}
]
},
{
"text": "Hello! What's up?",
"channel": "slack"
},
{
"image": "https://i.imgur.com/nGF1K8f.jpg"
},
{
"text": "Hey! Nice to see you again! How are you?",
"condition": [
{
"type": "slot",
"name": "logged_in",
"value": true
}
]
}
]
}
}
What the first line is retrieving is the list inside utter_greet
.
The second line will remove any element that does not have a “text” key, so the image-only response will be gone and the list will be:
[
{
"text": "Hey! How are you?",
"buttons": [
{
"title": "great",
"payload": "/mood_great"
},
{
"title": "super sad",
"payload": "/mood_sad"
}
]
},
{
"text": "Hello! What's up?",
"channel": "slack"
},
{
"text": "Hey! Nice to see you again! How are you?",
"condition": [
{
"type": "slot",
"name": "logged_in",
"value": true
}
]
}
]
Finally, the third line will only keep the “text” element of each object:
[
"Hey! How are you?",
"Hello! What's up?",
"Hey! Nice to see you again! How are you?"
]
Of course, you can choose how to filter and map the array, but you get the idea.