【发布时间】:2018-09-20 04:43:19
【问题描述】:
我正在构建一个简单的机器人来定期生成图表作为图像并通过 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'
)
但是当我尝试对文件上传执行相同操作时,图像发送正确,但显示的是我的名字,而不是指定的机器人名称:
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',
)
查看files.upload, 的松弛 API 文档,username 似乎不可用。
如何使用机器人名称发送 files.upload 图像?
【问题讨论】:
-
@monkut 你在哪里将机器人消息代码包含在你的 django 项目中是在 views.py 中吗
-
我在 aws lambda 的独立函数中使用了它。如果使用 django,我可能会在我的应用目录中创建一个
functions.py并将其放在那里。 -
实际上我不得不发送给 slack 中的特定用户我该怎么做
-
@monkut 如果您不介意,请查看此问题一次stackoverflow.com/questions/61723283/… 我的朋友请帮忙