python - 尝试在 python-slackclient 中使用@channel、@here 和@user

标签 python slack slack-api

我尝试使用@channel、@here 和@user 发送消息,但它们都是以文本形式发送的。

enter image description here

这是代码....

import os
from slack import WebClient
from slack.errors import SlackApiError

client = WebClient(token='xoxb-**************************')

try:
    response = client.chat_postMessage(
        channel='#prueba',
        text="@channel Hello world!",
        as_user=False)
    assert response["message"]["text"] == "Hello world!"
except SlackApiError as e:
    # You will get a SlackApiError if "ok" is False
    assert e.response["ok"] is False
    assert e.response["error"]  # str like 'invalid_auth', 'channel_not_found'
    print(f"Got an error: {e.response['error']}")

我都读过 PythonSlackclient DocsAPI Docs ,但我找不到广播我的消息或如何提及某人的选项。

最佳答案

您需要将代码更改为

response = client.chat_postMessage(
    channel='#prueba',
    text="<!channel> Hello world!",
    as_user=False)
assert response["message"]["text"] == "@channel Hello world!"

Slack API 拥有最好的文档之一,可以开始链接用户 read this

关于python - 尝试在 python-slackclient 中使用@channel、@here 和@user,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62706429/

相关文章:

python - 如何使用 file.upload 和 requests 将文件上传到 slack

javascript - 向 oauth.access url 发送请求后松弛错误 "invalid_code"

python - 有没有一种简单的方法来列出所有采用稀疏训练输入的 sklearn 实现?

Python - 打开 pdf 文件到特定页面/部分

python - 对导入语法感到困惑

azure - Microsoft Bot Framework 和 Slack - 测试时始终返回 Forbidden

javascript - 如何制作超过 5 个输入的松弛对话? Node 松弛API

Python包版本标准

node.js - 在 Microsoft Bot 构建器 node.js 中处理由 Slack 中的提示生成的先前按钮的输入时出现问题

slack-api - Slack static_select 避免在更改时调用后端