首页 > 解决方案 > 有没有办法更新 Slack 消息中的单个块元素?

问题描述

我正在尝试使用机器人更新 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"
                    }
                ]
            }
            ]
        )

标签: pythonjsonslackslack-apislack-block-kit

解决方案


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

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


推荐阅读