No, without a backend service, you cannot dynamically append user-entered text input values to a button’s URL in Google Chat cards. Here’s why:
Technical Limitation
Google Chat cards are static JSON payloads sent once from Splunk. The button URL is fixed at the time the alert is triggered. There is no way to:
- Capture user input from the chat card
- Modify the button’s URL in real-time
- Redirect to a new URL with the appended comment
Closest Workaround (Static URL Parameters)
If you know the comment/parameter at the time the alert is triggered in Splunk, you can pre-append it to the URL. For example:
Splunk SPL Code
spl
| eval comment="predefined_comment" # This is static and known when the alert is created
| eval encoded_comment=replace(comment, " ", "%20")
| eval payload="{
\"sections\": [
{
\"widgets\": [
{
\"textParagraph\": {
\"text\": \"An alert has been triggered. Click below to investigate.\"
}
},
{
\"buttonList\": {
\"buttons\": [
{
\"text\": \"Fill w/ IMG icon\",
\"type\": \"FILLED\",
\"onClick\": {
\"openLink\": {
\"url\": \"https://your-splunk-instance/app/search/search?q=your-search-query&comment=\" . encoded_comment . \"\"
}
}
}
]
}
},
{
\"textInput\": {
\"name\": \"comment\",
\"label\": \"Komentarz\",
\"value\": \"" . comment . "\" # Pre-fill the input with the static value
}
}
]
}
]
}"
Result
- The button URL will include
comment=predefined_comment
- The text input will be pre-filled with
predefined_comment
- The user can edit the input, but the button URL will not update
If You Need Dynamic URLs
You must use a backend service to:
- Receive the user-entered comment from Google Chat
- Construct the URL with the comment
- Return a new card or redirect the user
This requires:
- A server (e.g., AWS Lambda, Google Cloud Functions) to handle card interactions
- A webhook to process Google Chat’s
onChangeAction or onClick events
Without a backend, dynamic URLs based on user input are impossible. Let me know if you’d like guidance on setting up a lightweight backend! 😊