You're right that we can use onChangeAction to update the card when the text input changes, but there's an important limitation: Google Chat cards don't support dynamically updating a button's URL based on input field values in the same card. The onChangeAction is primarily for validation and updating other parts of the card, not for modifying button URLs.
However, we can create a workaround that might suit your needs. Here's how we can structure the card:
{
"sections": [
{
"widgets": [
{
"textParagraph": {
"text": "An alert has been triggered. Click below to investigate."
}
},
{
"textInput": {
"name": "comment",
"label": "Comment",
"validation": {
"inputType": "TEXT"
},
"onChangeAction": {
"function": "updateButtonUrl",
"parameters": [
{
"key": "comment",
"value": "{{comment}}"
}
]
}
}
},
{
"buttonList": {
"buttons": [
{
"text": "View in Splunk",
"type": "FILLED",
"onClick": {
"openLink": {
"url": "https://your-splunk-instance/app/search/search?q=your-search-query&comment="
}
}
}
]
}
}
]
}
]
}
Important notes about this approach:
-
The onChangeAction can trigger a function in your backend that would need to:
- Receive the updated comment value
- Generate a new card with the updated URL
- Return this new card to Google Chat
-
The actual URL won't update dynamically in the same card - you would need to send a new card with the updated URL.
-
For a complete solution, you would need to implement the updateButtonUrl function on your backend that would:
- Receive the comment value
- Construct the full URL with the comment parameter
- Return a new card with the updated button URL
Here's what a complete implementation might look like with a backend function:
{
"sections": [
{
"widgets": [
{
"textParagraph": {
"text": "An alert has been triggered. Click below to investigate."
}
},
{
"textInput": {
"name": "comment",
"label": "Comment",
"validation": {
"inputType": "TEXT"
},
"onChangeAction": {
"function": "updateButtonUrl",
"parameters": [
{
"key": "comment",
"value": "{{comment}}"
}
],
"loadIndicator": "LOAD_INDICATOR_SPINNER"
}
}
},
{
"buttonList": {
"buttons": [
{
"text": "View in Splunk",
"type": "FILLED",
"onClick": {
"openLink": {
"url": "https://your-splunk-instance/app/search/search?q=your-search-query&comment="
}
}
}
]
}
}
]
}
]
}