{"id":20284191,"url":"https://github.com/tbbatbb/weworkbot","last_synced_at":"2025-04-11T08:24:32.743Z","repository":{"id":240669087,"uuid":"799737775","full_name":"tbbatbb/WeWorkBot","owner":"tbbatbb","description":"用于企业微信自建应用的机器人代码库，实现消息回复、消息推送等功能。","archived":false,"fork":false,"pushed_at":"2024-05-22T01:00:31.000Z","size":45,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-22T01:03:57.246Z","etag":null,"topics":["chatbot","pypi-package","qiye-wechat","qiyeweixin","wechat","wechat-bot","wework","wework-app","wework-bot","wxwork"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tbbatbb.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-13T02:00:56.000Z","updated_at":"2024-05-22T01:00:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"1d5e5add-464c-4421-80f5-b3d83a5468b3","html_url":"https://github.com/tbbatbb/WeWorkBot","commit_stats":null,"previous_names":["tbbatbb/weworkbot"],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbbatbb%2FWeWorkBot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbbatbb%2FWeWorkBot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbbatbb%2FWeWorkBot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbbatbb%2FWeWorkBot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tbbatbb","download_url":"https://codeload.github.com/tbbatbb/WeWorkBot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248361084,"owners_count":21090814,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatbot","pypi-package","qiye-wechat","qiyeweixin","wechat","wechat-bot","wework","wework-app","wework-bot","wxwork"],"created_at":"2024-11-14T14:18:40.802Z","updated_at":"2025-04-11T08:24:32.728Z","avatar_url":"https://github.com/tbbatbb.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WeWorkBot\r\n\r\n为企业微信自建应用构建的机器人，能够实现对各种类型消息的被动回复和主动发送。\r\n\r\n现支持：\r\n- 接收处理文本(`text`)、图片(`image`)、语音(`voice`)、视频(`video`)、位置(`location`)和链接(`link`)等消息类型；\r\n- 以文本(`text`)、图片(`image`)、语音(`voice`)、视频(`video`)、图文(`news`)等消息类型进行被动回复；\r\n- 以文本(`text`)、图片(`image`)、语音(`voice`)、视频(`video`)、Markdown(`markdown`)、图文(`mpnews`)、图文(`news`)、文本卡片(`textcard`)、文件(`file`)等消息类型主动发送应用消息；\r\n- 文件素材管理，包括上传临时文件、上传图片、异步上传文件、下载文件等;\r\n- 发起群聊、更改群聊信息、获取群聊会话、向群聊发送应用消息等功能（具体限制请参考[官方文档](https://developer.work.weixin.qq.com/document/path/90244)）；\r\n\r\n\r\n## 依赖\r\n\r\n依赖的库不多，可以参考`requirements.txt`。\r\n\r\n## 安装\r\n\r\n**目前支持`Python \u003e= 3.9`，其余版本未经测试。**\r\n\r\nPython库现已发布，可以通过`pip install wwbot`进行安装。\r\n\r\n## 示例代码\r\n\r\n如下示例代码展示`WeWorkBot`的简单使用。该示例展示了如何回复**文本类型**(`text`)的消息：\r\n```python\r\nfrom flask import Flask\r\nfrom wwbot import WWBot\r\nfrom wwbot.msg import Message, TextMessage\r\n\r\n# 注册一个文本消息的事件监听\r\n@WWBot.on(WWBot.TEXT)\r\ndef text_handler(msg:TextMessage) -\u003e Message:\r\n    '''\r\n    msg参数代表接收到的消息被解析后的实例\r\n    '''\r\n    # 从消息中提取消息内容字段\r\n    # 关于接收到的消息格式具体定义，参考 https://developer.work.weixin.qq.com/document/path/90239\r\n    msg_content:str = msg.content\r\n    # 作为示例，直接使用接收到的消息作为回复，相当于一个 echo bot\r\n    return TextMessage(msg.from_username, msg.to_username, msg.agent_id, msg_content)\r\n\r\n# WeWorkBot运行在Flask框架之上\r\napp:Flask = Flask('WWBot')\r\n# 企业ID \r\ncorp_id:str = 'corp_id'\r\n# 企业自建应用的secret 可以创建自建应用后在应用详情页面查看\r\ncorp_secret:str = 'corp_secret'\r\n# 自建应用启用API接收消息时，配置的“Token”参数\r\ntoken:str = 'token'\r\n# 自建应用启用API接收消息时，配置的“EncodingAESKey”参数\r\naes_key:bytes = base64.b64decode('aes_key')\r\n# 接收消息回调时的url path部分\r\ncallback_path:str = '/wwbot'\r\n\r\n# 配置机器人\r\nWWBot.config(app, corp_id, corp_secret, token, aes_key, callback_path=callback_path)\r\n\r\nif __name__ == '__main__':\r\n    app.run('0.0.0.0', 31221)\r\n```\r\n更加完整的例子请参考`exampls/echo_bot.py`。\r\n\r\n## TODO List\r\n\r\n- [x] 将“接口验证”和“消息接收”的url部分合并，不需要两次注册\r\n- [x] 实现临时资源上传，从而能够发送任意语音或是视频等多媒体消息\r\n- [x] 支持更多的应用消息类型\r\n- [x] 将消息的定义和转换变得更加优雅\r\n- [x] 创建成python库。现在这个方式，不够优雅\r\n- [x] ~~完善Doc和Readme，包括获取corp_id等参数的方法~~(不写了，懒。总共也就几个接口，根本不够写)\r\n\r\n## 说明\r\n\r\n代码随缘更新，主要看有没有空。一般会在周末更新比较频繁。","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbbatbb%2Fweworkbot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftbbatbb%2Fweworkbot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbbatbb%2Fweworkbot/lists"}