Slack Bot - Python slack 发送降价消息

Slack Bot - Python slack send markdown messages

我正在尝试使用 SlackBot 在 slack 中发送降价消息,但我找不到文档,我得到的是:

response = client.chat_postMessage( 
    ...:     channel='#testing-bot', 
    ...:     text="Hello world! <@USerID> \n\n - a \n-b" 
    ...:     
    ...:     )  

我想发送 MArkdown 消息,而不是文本消息 我试过了:

    ...:     channel='#testing-bot', 
    ...:     mkdwn="Hello world! <@UNVD64N02> \n\n - a \n-b" 
    ...:     
    ...:     )  

但是没用。帮助

您需要发送频道 ID(它将是字母数字字符串)而不是频道名称 (#testing-bot)。

更新: 您还可以使用 block kit,它是用于 slack 应用程序的 UI 框架。它带有一个块工具包构建器,可用于块代码的实时查看。为两者添加了以下参考资料。

response = client.chat_postMessage(
    channel="", # channel ID
    text="",
    blocks=[
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "Hello world! <@UNVD64N02> :tada: \n\n - a \n-b"
            }
        }
    ]
)

输出

参考文献: