附件在以下代码中不起作用,也不是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
Run Code Online (Sandbox Code Playgroud)
response_type只有在生成消息以响应斜杠命令或消息按钮操作调用时,才能设置该字段.它不能直接设置chat.postMessage,因为目标用户上没有显示该短暂消息的上下文.
另一个怪癖chat.postMessage是,它目前不接受像传入webhooks那样的JSON.相反,您需要发送application/x-www-form-urlencoded各种POST参数.即使是奇怪的,该attachments字段实际上并不是作为一串JSON发送的,而是URL编码成一个参数.
还有一个提示,使用chat.postMessage和其他写入方法,您应该使用HTTP POST而不是GET.
| 归档时间: |
|
| 查看次数: |
2478 次 |
| 最近记录: |