有没有办法更新 Slack 消息中的单个块元素?

Is there a way to update individual block elements in a Slack message?

我正在尝试使用机器人更新 Slack 消息的按钮样式和文本,但我找不到有关更新单个块而不是整个数组的信息。如何只更新 res_but 元素的“文本”和“样式”,同时保留其余消息内容?

编辑: 我忘了说我正在使用 Python3 和 Bolt 来编程这个

@app.action("res_but")
def resolve_toggle(ack, body, client):
    ack()

    resolvebutton_style = body["actions"][0]["style"]

    if(resolvebutton_style == "danger"):
        client.chat_update(
            channel = body["channel"]["id"],
            ts = body["message"]["ts"],

            blocks=[
            {
                "type": "section",
                "text": {
                    "type": "mrkdwn",
                    "text": "*Issue:*\n{}\n*Urgency:*\n{}\n*Posted By*:\n{}\n*When:*\n<!date^{}^Posted {{date_num}} {{time_secs}}|Null Date>\n*Last Update:*\n".format(msg, urgency_val, username, posttimest_int)
                }
            },
            {
                "block_id": "issue_buttons",
                "type": "actions",
                "elements": [
                    {
                        "action_id": "res_but",
                        "type": "button",
                        "text": {
                            "type": "plain_text",
                            "emoji": True,
                            "text": "Resolved"  #issue status changed to resolved
                        },
                        "style": "primary",     #color changed to primary
                        "value": "resolve_but"
                    },
                    {
                        "action_id": "ogmes_but",
                        "type": "button",
                        "text": {
                            "type": "plain_text",
                            "emoji": True,
                            "text": "Original Message"
                        },
                        "value": "og_message"
                    }
                ]
            }
            ]
        )

目前无法更新区块的部分内容。需要更新完整视图。
尽管有一种方法可以保留在 "Input 块中输入的数据:

Preserving input entry
Data entered or selected in input blocks can be preserved while updating views. 
The new view object that you use with views.update should contain 
the same input blocks and elements with identical block_id and action_id values.

https://api.slack.com/surfaces/modals/using#updating_views

我实际上找到了一种更新单个元素的方法。我的问题可能措辞不当,但我更多地是在寻找一种 shorthand 的方式,而不是让大块占用程序中的 space。

消息中的块已被检索并存储在一个名为 new_blocks 的新变量中。 new_blocks 的元素然后用新值更新。然后将块更新为 new_blocks,实施更改。

    @app.action("res_but")
def resolve_toggle(ack, body, client, logger):
    ack()

    resolvebutton_style = body["actions"][0]["style"]

    if(resolvebutton_style == "danger"):
        new_blocks = body["message"]["blocks"] #assign message blocks to new variable
        new_blocks[1]["elements"][0]["style"] = "primary" #change button style
        new_blocks[1]["elements"][0]["text"]["text"] = "Resolved" #change button text


        client.chat_update(
            channel = body["channel"]["id"],
            ts = body["message"]["ts"],
            
            blocks = new_blocks) #update message with block alterations

    else:
        new_blocks = body["message"]["blocks"]
        new_blocks[1]["elements"][0]["style"] = "danger"
        new_blocks[1]["elements"][0]["text"]["text"] = "Unresolved"

        client.chat_update(
            channel = body["channel"]["id"],
            ts = body["message"]["ts"],
            
            blocks = new_blocks)
    body["style"] = 80
    logger.info(body)