mon*_*kut 5 python slack-api slack
我正在构建一个简单的机器人,定期生成图表作为图像,并通过 python slackclient包发布到 slack。
我已经成功使用以下代码发送了一条机器人消息:
def post_message_to_channel(self, channel_id, message=DEFAULT_TEST_MESSAGE):
sc = SlackClient(TOKEN)
sc.api_call(
"chat.postMessage",
channel=channel_id,
username='mybot',
text='test text message'
)
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试对文件上传执行相同操作时,图像已正确发送,但它显示我的名字,而不是指定的机器人名称:
def post_image_to_channel(self, channel_name, filepath, tile='Test Upload'):
sc = SlackClient(TOKEN)
with open(filepath, 'rb') as file_content:
sc.api_call(
"files.upload",
channels=channel_id,
file=file_content,
title=tile,
username='mybot',
)
Run Code Online (Sandbox Code Playgroud)
查看files.upload 的 slack API 文档,似乎username不可用。
如何使用机器人名称发送files.upload图像?
| 归档时间: |
|
| 查看次数: |
13191 次 |
| 最近记录: |