未显示Sack API&Quot;附件 [英] Slack API "attachments" not showing

查看:0
本文介绍了未显示Sack API&Quot;附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

附件在以下代码中不起作用,response_type也不能正常显示。我也尝试过使用Python的Slack客户端,但发生了完全相同的事情。

def send_message(channel_id, text):
    params = {
        "token" : token, 
        "username" : "NEW BOT",
        "channel" : channel_id,
        "text" : text,
        "response_type": "ephemeral",
        "attachments": [{ "text":"This is some text" }]
    }

    headers = {'content-type': 'application/json'}
    slack_api = 'https://slack.com/api/chat.postMessage'
    requests.get(slack_api, json=params, headers=headers)
    return

@app.route('/', methods=['GET', 'POST'])
def main():
    if sc.rtm_connect():
        sc.rtm_read()
        text = request.args.get("text")
        channel_id = request.args.get("channel_id")
        send_message(channel_id, text)
        return Response(), 200

推荐答案

response_type字段只能在生成响应斜杠命令或消息按钮操作调用的消息时设置。不能使用chat.postMessage直接设置,因为没有要为其显示该临时消息的目标用户的上下文。

chat.postMessage的另一个奇怪之处在于,它目前不像传入的WebHook那样接受JSON。相反,您需要发送application/x-www-form-urlencoded类型的POST参数。更奇怪是,attachments字段实际上不是作为JSON字符串发送的,而是以URL编码的形式发送到参数中。

还有一个提示,对于chat.postMessage和其他写入方法,您应该使用HTTP POST而不是GET。

这篇关于未显示Sack API&Quot;附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆