{"id":13574782,"url":"https://github.com/CatchZeng/feishu","last_synced_at":"2025-04-04T18:32:08.345Z","repository":{"id":44847062,"uuid":"377350801","full_name":"CatchZeng/feishu","owner":"CatchZeng","description":"feishu 是飞书机器人的 go 实现。支持 Docker、Jenkinsfile、命令行模式，module 模式；支持加签安全设置、链式语法创建消息；支持文本（text）、富文本（post）、图片（image）、群名片（share_chat）、消息卡片（interactive）消息类型。","archived":false,"fork":false,"pushed_at":"2022-09-04T11:26:19.000Z","size":66,"stargazers_count":90,"open_issues_count":4,"forks_count":19,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-05T10:44:38.490Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CatchZeng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-16T02:42:47.000Z","updated_at":"2024-10-25T03:05:18.000Z","dependencies_parsed_at":"2022-08-24T12:10:11.402Z","dependency_job_id":null,"html_url":"https://github.com/CatchZeng/feishu","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CatchZeng%2Ffeishu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CatchZeng%2Ffeishu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CatchZeng%2Ffeishu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CatchZeng%2Ffeishu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CatchZeng","download_url":"https://codeload.github.com/CatchZeng/feishu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247229686,"owners_count":20905097,"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":[],"created_at":"2024-08-01T15:00:54.664Z","updated_at":"2025-04-04T18:32:07.973Z","avatar_url":"https://github.com/CatchZeng.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# feishu\n\n![Go](https://github.com/CatchZeng/feishu/workflows/Go/badge.svg)\n[![codecov](https://codecov.io/gh/CatchZeng/feishu/branch/master/graph/badge.svg)](https://codecov.io/gh/CatchZeng/feishu)\n[![Go Report Card](https://goreportcard.com/badge/github.com/CatchZeng/feishu)](https://goreportcard.com/report/github.com/CatchZeng/feishu)\n[![Release](https://img.shields.io/github/release/CatchZeng/feishu.svg)](https://github.com/CatchZeng/feishu/releases)\n[![GoDoc](https://godoc.org/github.com/CatchZeng/feishu?status.svg)](https://pkg.go.dev/github.com/CatchZeng/feishu?tab=doc)\n\n\u003e feishu 是飞书机器人的 go 实现。支持 **Docker、Jenkinsfile、命令行模式，module 模式**；支持**加签**安全设置，支持**链式语法**创建消息；支持**文本（text）、富文本（post）、图片（image）、群名片（share_chat）、消息卡片（interactive）** 消息类型。\n\n\u003e 注：使用钉钉（DingTalk）的小伙伴，可以使用[钉钉（DingTalk）版](https://github.com/CatchZeng/dingtalk)。\n\n## 文档\n\n[飞书文档](https://www.feishu.cn/hc/zh-CN/articles/360024984973)\n\n## 特性\n\n- [x] 支持[Docker](https://github.com/CatchZeng/feishu#Docker)\n\n- [x] 支持[Jenkinsfile](https://github.com/CatchZeng/feishu#Jenkinsfile)\n\n- [x] 支持[module](https://github.com/CatchZeng/feishu#%E4%BD%9C%E4%B8%BA-module)\n\n- [x] 支持[命令行模式](https://github.com/CatchZeng/feishu#%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%B7%A5%E5%85%B7)\n\n- [x] 支持[配置文件](https://github.com/CatchZeng/feishu#%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6)\n\n- [x] 支持[环境变量](https://github.com/CatchZeng/feishu#%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F)\n\n- [x] 支持加签\n\n\u003cimg src=\"https://p6-hera.byteimg.com/tos-cn-i-jbbdkfciu3/fb5e1dd375684dd2b9b6037d86f862b0~tplv-jbbdkfciu3-image:0:0.image\" width = 50% /\u003e\n\n- [x] 文本（text）消息\n\n\u003cimg src=\"https://p1-hera.byteimg.com/tos-cn-i-jbbdkfciu3/c9c86efea1754e269dbdc5517b4d958a~tplv-jbbdkfciu3-image:0:0.image\" width = 50% /\u003e\n\n- [x] 富文本（post）消息\n\n\u003cimg src=\"https://p3-hera.byteimg.com/tos-cn-i-jbbdkfciu3/661d8ee4446c47bca5ac61bfb2ef1a6f~tplv-jbbdkfciu3-image:0:0.image\" width = 50% /\u003e\n\n- [x] 图片（image）消息\n\n\u003cimg src=\"https://p1-hera.byteimg.com/tos-cn-i-jbbdkfciu3/5607aa65324e4e14bd94192ba81fe0b3~tplv-jbbdkfciu3-image:0:0.image\" width = 50% /\u003e\n\n- [x] 群名片（share_chat）消息\n\n\u003cimg src=\"https://p9-hera.byteimg.com/tos-cn-i-jbbdkfciu3/ba60b1c2835a4950926bb86687e183a8~tplv-jbbdkfciu3-image:0:0.image\" width = 50% /\u003e\n\n- [x] 消息卡片（interactive）消息\n\n\u003cimg src=\"https://p6-hera.byteimg.com/tos-cn-i-jbbdkfciu3/4bf5072377cf4c02990ce28731634e6a~tplv-jbbdkfciu3-image:0:0.image\" width = 50% /\u003e\n\n## 安装\n\n## Docker 安装\n\n```shell\ndocker pull catchzeng/feishu\n```\n\n### 二进制安装\n\n到 [releases](https://github.com/CatchZeng/feishu/releases/) 下载相应平台的二进制可执行文件，然后加入到 PATH 环境变量即可。\n\n### go install 安装\n\n```sh\n# Go 1.16+\ngo install github.com/CatchZeng/feishu@v1.3.2\n\n# Go version \u003c 1.16\ngo get -u github.com/CatchZeng/feishu@v1.3.2\n```\n\n## 使用方法\n\n### 配置文件\n\n可以在 `$/HOME/.feishu` 下创建 `config.yaml` 填入 `access_token` 和 `secret` 默认值。\n\n```yaml\naccess_token: \"6cxxxx80-xxxx-49e2-ac86-7f378xxxx960\"\nsecret: \"k6usknqxxxxazNxxxx443d\"\n```\n\n### 环境变量\n\n```sh\n$ export ACCESS_TOKEN=\"6cxxxx80-xxxx-49e2-ac86-7f378xxxx960\"\n$ export SECRET=\"k6usknqxxxxazNxxxx443d\"\n$ feishu post -i 测试 -e 测试信息 -r https://makeblock.com/ -f 链接文本 -a all\n```\n\n你也可以为环境变量设置一个**前缀**\n\n```sh\n$ export FEISHU_ENV_PREFIX=\"FEISHU_\"\n$ export FEISHU_ACCESS_TOKEN=\"6cxxxx80-xxxx-49e2-ac86-7f378xxxx960\"\n$ export FEISHU_SECRET=\"k6usknqxxxxazNxxxx443d\"\n$ feishu post -i 测试 -e 测试信息 -r https://makeblock.com/ -f 链接文本 -a all\n```\n\n### Docker\n\n```shell\ndocker run catchzeng/feishu feishu text -t 6cxxxx80-xxxx-49e2-ac86-7f378xxxx960 -s k6usknqxxxxazNxxxx443d -e \"docker test\"\n```\n\n### Jenkinsfile\n\n```shell\npipeline {\n    agent {\n        docker {\n            image 'catchzeng/feishu'\n        }\n    }\n    environment {\n        FEISHU_TOKEN = '6cxxxx80-xxxx-49e2-ac86-7f378xxxx960'\n        FEISHU_SECRET = 'k6usknqxxxxazNxxxx443d'\n    }\n    stages {\n        stage('notify') {\n            steps {\n                sh 'feishu post -t ${FEISHU_TOKEN} -s ${FEISHU_SECRET} -i 标题 -e 信息 -r https://makeoptim.com/ -f 链接文本 -a all'\n            }\n        }\n    }\n}\n```\n\n\u003e 注：post 有两种用法，除了像上面使用一堆参数外，还可以使用 `post` 参数，直接将 [post json string](https://open.feishu.cn/document/ukTMukTMukTM/uMDMxEjLzATMx4yMwETM#1b8abd5d) 传入，做到更灵活的配置。如下所示：\n\n```shell\n$ post='{\n  \"zh_cn\": {\n    \"title\": \"项目更新通知\",\n    \"content\": [\n      [\n        {\n          \"tag\": \"text\",\n          \"text\": \"项目有更新: \"\n        },\n        {\n          \"tag\": \"a\",\n          \"text\": \"请查看\",\n          \"href\": \"http://www.example.com/\"\n        }\n      ]\n    ]\n  }\n}\n'\n$ feishu post -t 6cxxxx80-xxxx-49e2-ac86-7f378xxxx960 -s k6usknqxxxxazNxxxx443d -p $post\n```\n\n### 作为 module\n\n```\ngo get github.com/CatchZeng/feishu\n```\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\n\t\"github.com/CatchZeng/feishu/pkg/feishu\"\n)\n\nfunc main() {\n\ttoken := \"6cxxxx80-xxxx-49e2-ac86-7f378xxxx960\"\n\tsecret := \"k6usknqxxxxazNxxxx443d\"\n\n\tclient := feishu.NewClient(token, secret)\n\n\ttext := feishu.NewText(\"文本\")\n\ta := feishu.NewA(\"链接\", \"https://www.baidu.com/\")\n\tat := feishu.NewAT(\"all\")\n\tline := []feishu.PostItem{text, a, at}\n\tmsg := feishu.NewPostMessage()\n\tmsg.SetZHTitle(\"测试富文本 @all\").\n\t\tAppendZHContent(line)\n\n\treq, resp, err := client.Send(msg)\n\tif err != nil {\n\t\tlog.Print(err)\n\t\treturn\n\t}\n\tlog.Print(resp)\n}\n```\n\n### 命令行工具\n\n#### Demo\n\n##### Post\n\n```sh\nfeishu post -t 6cxxxx80-xxxx-49e2-ac86-7f378xxxx960 -s k6usknqxxxxazNxxxx443d -i 标题 -e 信息 -r https://makeoptim.com/ -f 链接文本 -a all\n```\n\n```sh\n❯ feishu post -t 6cxxxx80-xxxx-49e2-ac86-7f378xxxx960 -s k6usknqxxxxazNxxxx443d -i 标题 -e 信息 -r https://makeoptim.com/ -f 链接文本 -a all -D\n{\"content\":{\"post\":{\"zh_cn\":{\"content\":[[{\"tag\":\"text\",\"text\":\"信息\"},{\"tag\":\"a\",\"text\":\"链接文本\",\"href\":\"https://makeoptim.com/\"},{\"tag\":\"at\",\"user_id\":\"all\"}]],\"title\":\"标题\"}}},\"msg_type\":\"post\",\"sign\":\"HR7kQhgapScmp/2bfLWdYmC7C6pUV3C/pQUiS3OQDIA=\",\"timestamp\":\"1642561080\"}\n```\n\n\u003e -D 参数：打印发送的消息内容\n\n##### Interactive\n\n```shell\n$ card='{\n  \"config\": {\n    \"wide_screen_mode\": true,\n    \"enable_forward\": true\n  },\n  \"elements\": [\n    {\n      \"tag\": \"div\",\n      \"text\": {\n        \"content\": \"**西湖**，位于浙江省杭州市西湖区龙井路1号，杭州市区西部，景区总面积49平方千米，汇水面积为21.22平方千米，湖面面积为6.38平方千米。\",\n        \"tag\": \"lark_md\"\n      }\n    },\n    {\n      \"actions\": [\n        {\n          \"tag\": \"button\",\n          \"text\": {\n            \"content\": \"更多景点介绍 :玫瑰:\",\n            \"tag\": \"lark_md\"\n          },\n          \"url\": \"https://www.example.com\",\n          \"type\": \"default\",\n          \"value\": {}\n        }\n      ],\n      \"tag\": \"action\"\n    }\n  ],\n  \"header\": {\n    \"title\": {\n      \"content\": \"今日旅游推荐\",\n      \"tag\": \"plain_text\"\n    }\n  }\n}\n'\n$ feishu interactive -t 6cxxxx80-xxxx-49e2-ac86-7f378xxxx960 -s k6usknqxxxxazNxxxx443d -c $card\n```\n\n\u003e 注：`card` 可以使用[飞书可视化搭建工具 cardbuilder](https://open.feishu.cn/tool/cardbuilder?from=custom_bot_doc) 自动生成。\n\n#### Help\n\n```shell\n$ feishu -h\nfeishu is a command line tool for feishu robot\n\nUsage:\n  feishu [command]\n\nAvailable Commands:\n  help        Help about any command\n  image       send image message with feishu robot\n  interactive send interactive message with feishu robot\n  post        send post message with feishu robot\n  shareChat   send shareChat message with feishu robot\n  text        send text message with feishu robot\n  version     feishu version\n\nFlags:\n  -t, --access_token string   access_token\n  -D, --debug                 debug\n  -h, --help                  help for feishu\n  -s, --secret string         secret\n\nUse \"feishu [command] --help\" for more information about a command.\n```\n\n## Stargazers\n\n[![Stargazers over time](https://starchart.cc/CatchZeng/feishu.svg)](https://starchart.cc/CatchZeng/feishu)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCatchZeng%2Ffeishu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCatchZeng%2Ffeishu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCatchZeng%2Ffeishu/lists"}