In Google Chat cards, you cannot directly append the text input value to a button's URL in real-time. The button's URL is static when the card is rendered.
However, here are two approaches to achieve what you want:
Option 1: Use Card Actions (Recommended)
Instead of opening a link directly, use a card action that captures the text input and then constructs the URL server-side:
{
"sections": [
{
"widgets": [
{
"textParagraph": {
"text": "An alert has been triggered. Click below to investigate."
}
},
{
"textInput": {
"name": "comment",
"label": "Komentarz",
"value": ""
}
},
{
"buttonList": {
"buttons": [
{
"text": "Fill w/ IMG icon",
"type": "FILLED",
"onClick": {
"action": {
"function": "processComment",
"parameters": [
{
"key": "baseUrl",
"value": "https://your-splunk-instance/app/search/search?q="
}
]
}
}
}
]
}
}
]
}
],
"cardActions": [
{
"actionLabel": "Submit",
"onClick": {
"action": {
"function": "processComment"
}
}
}
]
}
Your backend would then:
- Receive the
comment field value
- Construct the full URL:
baseUrl + encodeURIComponent(comment)
- Return an update card with the link or redirect the user
Option 2: Use a Dialog (Interactive)
Create a dialog that opens when the button is clicked:
{
"sections": [
{
"widgets": [
{
"textParagraph": {
"text": "An alert has been triggered. Click below to investigate."
}
},
{
"textInput": {
"name": "comment",
"label": "Komentarz",
"value": ""
}
},
{
"buttonList": {
"buttons": [
{
"text": "Fill w/ IMG icon",
"type": "FILLED",
"onClick": {
"action": {
"function": "openDialog"
}
}
}
]
}
}
]
}
]
}
Option 3: Two-Step Process (Simple)
If you don't have a backend to process actions, use a two-step approach:
{
"sections": [
{
"widgets": [
{
"textParagraph": {
"text": "An alert has been triggered."
}
},
{
"textParagraph": {
"text": "<b>Instructions:</b>\n1. Copy your comment below\n2. Click the button\n3. Paste your comment in the search field"
}
},
{
"textInput": {
"name": "comment",
"label": "Komentarz (copy this)",
"value": ""
}
},
{
"buttonList": {
"buttons": [
{
"text": "Open Splunk Search",
"type": "FILLED",
"onClick": {
"openLink": {
"url": "https://your-splunk-instance/app/search/search"
}
}
}
]
}
}
]
}
]
}
Important Notes:
- Google Chat cards are not dynamic - you can't change the button URL based on text input without server-side processing
- The
onChangeAction in your original code requires a backend function to handle it
- If you're using Splunk alerts without a custom backend, Option 3 is the most practical
Would you like me to help you implement any of these options, or do you have a backend service that can process card actions?