【问题标题】:Slack bot adds new line on message after XX charsSlack 机器人在 XX 字符后在消息上添加新行
【发布时间】:2019-10-22 13:57:16
【问题描述】:

我目前正在开发一个简单的 slack 机器人,它将每天发布一条消息,其中包含如下所示的文本列表。

问题是列表中第二项的新行不是我添加的。就像机器人的消息以 XX 字符为上限。如果我复制机​​器人发送的消息并在频道中发送相同的消息,效果很好,那么就没有像下面的示例那样添加换行符。

有人知道为什么会这样吗?

机器人的消息:

•  1 day     This is a rather short message
•  1 day     This is a longer message that will automatically get cut
when I reach some unknown length.
•  4 days    This is working due to it is a short message.

如果我复制机​​器人发送的文本并在同一频道中发送:

•  1 day     This is a rather short message
•  1 day     This is a longer message that will automatically get cut when I reach some unknown length.
•  4 days    This is working due to it is a short message.

slack web 客户端是从我的应用程序发送的代码

msg = [ {'type': 'section', 'text': 
        {'type': 'mrkdwn', 'text': "First a greeting message"}  
    }, 
    {'type': 'divider'}, 
    {'type': 'section', 'text': 
        {'type': 'mrkdwn', 'text': '•  1 day     This is a rather short message \n •  1 day     This is a longer message that will automatically get cut when I reach some unknown length, but if I reply the same msg it will be fine \n •  4 days    This is working due to it is a short message.'}
    }
]
slack_client.chat_postMessage(channel=channel, blocks=msg)

【问题讨论】:

  • 如果您希望人们帮助您解决问题,请将您应用的相关代码添加到问题中。
  • 更新了发送到 slack web 客户端的描述。

标签: python-3.x slack slack-api


【解决方案1】:

可能与 https://github.com/jenkinsci/slack-plugin/issues/592 相关 - 从 Jenkins 发送时我得到相同的行为。该插件具有formatAsText 的属性。检查插件代码,尤其是StandardSlackService.java 可能会帮助您找到所需的内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-12
    • 2021-03-26
    • 1970-01-01
    • 2018-12-05
    • 2016-11-20
    • 2016-10-20
    相关资源
    最近更新 更多