Interact with Zulip chat platform via REST API and Python client. Use when you need to read messages from streams/topics, send messages to channels or users, manage DM conversations, list users, or integrate with Zulip organizations for team communication workflows.
与 Zulip 聊天平台交互,实现团队沟通。
bash
pip install zulip
创建 ~/.config/zulip/zuliprc:
ini
[api]
email=bot@example.zulipchat.com
key=在此处填写您的API密钥
site=https://example.zulipchat.com
从 Zulip 管理面板(设置 → 机器人)获取凭证。
bash
python scripts/zulip_client.py streams
scripts/zulip_client.py 提供常用操作:
列出频道:
bash
python scripts/zulip_client.py streams
python scripts/zulip_client.py streams --json
读取消息:
bash
注意: 频道名称可能包含看起来像名称一部分的描述。使用 --stream-id 进行明确标识。
发送消息:
bash
列出用户:
bash
python scripts/zulip_client.py users
python scripts/zulip_client.py users --json
python
import zulip
client = zulip.Client(config_file=~/.config/zulip/zuliprc)
bash
python
def getlatestmessages(client, streamname, lastseen_id=None):
narrow = [{operator: stream, operand: stream_name}]
if lastseenid:
# 仅获取上次查看后的消息
request = {
anchor: lastseenid,
num_before: 0,
num_after: 100,
narrow: narrow
}
else:
# 获取最近消息
request = {
anchor: newest,
num_before: 20,
num_after: 0,
narrow: narrow
}
result = client.get_messages(request)
return result[messages]
python
def replytomessage(client, originalmessage, replytext):
在原始消息所在的同一频道/话题中回复。
client.send_message({
type: stream,
to: originalmessage[displayrecipient],
topic: original_message[subject],
content: reply_text
})
python
def search_messages(client, keyword, stream=None):
narrow = [{operator: search, operand: keyword}]
if stream:
narrow.append({operator: stream, operand: stream})
result = client.get_messages({
anchor: newest,
num_before: 50,
num_after: 0,
narrow: narrow
})
return result[messages]
python
def getuserid(client, email):
通过邮箱地址查找用户ID。
result = client.get_members()
for user in result[members]:
if user[email] == email:
return user[user_id]
return None
Zulip 使用 Markdown:
python
with open(file.pdf, rb) as f:
result = client.upload_file(f)
file_url = result[uri]
python
完整 API 文档、端点和示例请参见 references/api-quick-reference.md。
找不到配置文件:
身份验证失败:
消息数组为空:
速率限制错误:
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 zulip-1775919302 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 zulip-1775919302 技能
skillhub install zulip-1775919302
文件大小: 6.26 KB | 发布时间: 2026-4-12 12:06