ARTICLE DETAIL

资讯详情

深耕网站视觉设计与运营推广的一线实战洞察。

gogcli 实战:`gog chat messages reactions create` 为 Google Chat 消息添加表情回应

gogcli 实战:`gog chat messages reactions create` 为 Google Chat 消息添加表情回应 gogcli 实战gog chat messages reactions create为 Google Chat 消息添加表情回应【免费下载链接】gogcliGoogle Workspace in your terminal.项目地址: https://gitcode.com/GitHub_Trending/gogcl/gogcli本文围绕 gogcliGoogle Workspace in your terminal中的gog chat messages reactions create命令展开讲解如何向一条 Google Chat 消息添加 emoji 回应、消息资源名resource name的两种传法、Workspace 账号限制、dry-run 与 JSON 输出行为并结合仓库源码说明命令的完整执行链路与测试验证方式。读完后你可以将该命令安全地用于人工操作与脚本/Agent 自动化流程。命令概览gog chat messages reactions create的官方描述是Add an emoji reaction to a message为一条消息添加 emoji 回应。它属于gog chat messages reactions命令组完整用法如下摘自 命令参考页gog chat messages reactions (reaction) create (add) message emoji [flags]用法行中的括号表示别名父命令组别名reaction、子命令别名add因此以下三种写法等价gog chat messages reactions create spaces/SPACE1/messages/MSG1 gog chat messages reaction create spaces/SPACE1/messages/MSG1 gog chat messages reactions add spaces/SPACE1/messages/MSG1 此外还有一个更短的快捷命令 gog chat messages reactgog chat messages react message emoji从源码看它只是直接委托给 create 命令执行// internal/cmd/chat_reactions.go func (c *ChatMessagesReactCmd) Run(ctx context.Context, flags *RootFlags) error { cmd : ChatMessagesReactionsCreateCmd{Message: c.Message, Emoji: c.Emoji, Space: c.Space} return cmd.Run(ctx, flags) }命令树位置位置命令说明父命令gog chat messages reactionsManage emoji reactions on a message子命令本文gog chat messages reactions create添加表情回应兄弟命令gog chat messages reactions list列出消息上的所有回应别名ls兄弟命令gog chat messages reactions delete删除某个回应别名remove/rm快捷命令gog chat messages reactcreate 的简写入口上上级gog chat messages消息管理命令组位置参数消息与 emoji命令接收两个位置参数定义见 internal/cmd/chat_reactions.go参数类型说明messagearg消息资源名spaces/.../messages/...或裸消息 IDbare message IDemojiargEmoji 的 Unicode 字符如以及一个命令级 flagFlag类型说明--spacestringSpace 名称。当message传裸 ID 时必填message 的两种传法消息参数支持两种形式其解析规则由 normalizeMessage 实现完整资源名spaces/spaceId/messages/messageId必须恰好 4 段。示例gog chat messages reactions create spaces/AAA/messages/msg1 裸 ID --space只传消息 ID同时用--space指定空间--space可传完整资源名spaces/AAA或裸 IDAAA由 normalizeSpace 归一化。示例gog chat messages reactions create msg1 --space AAA # 等价于 POST spaces/AAA/messages/msg1 上的 reactions 资源仓库测试 chat_reactions_test.go 中的表驱动用例明确了合法/非法边界输入结果spaces/AAA/messages/msg1完整路径原样通过msg1--space spaces/AAA或--space AAA归一化为spaces/AAA/messages/msg1msg1无--space报错required: message (full resource path, or bare ID with --space)spaces/AAA/threads/t1kind 不是 messages报错spaces/AAA/messages/缺 ID或.../msg1/extra多段报错裸 ID 含斜杠如AAA/extra作为 space报错emoji 参数会先经strings.TrimSpace去除首尾空白若结果为空则报required: emoji见 create 命令 Run 方法。它最终被封装成chat.Emoji{Unicode: emoji}结构体随请求体发出测试TestExecute_ChatMessagesReactionsCreate_JSON会真实断言出站 POST body 中emoji.unicode等于所传的。完整 Flags 参考以下 Flags 表完整继承自 官方命令参考页其中大部分是 gogcli 所有认证类命令共享的全局 flagFlag类型默认值说明--access-tokenstringUse provided access token directly (bypasses stored refresh tokens; token expires in ~1h)-a--account--acctstringAccount email, alias, or auto for authenticated Google API commands--clientstringOAuth client name (selects stored credentials token bucket)--colorstringautoColor output: auto|always|never--disable-commandsstringComma-separated list of disabled commands; dot paths allowed-n--dry-run--dryrun--noop--previewboolDo not make changes; print intended actions and exit successfully--enable-commandsstringComma-separated list of enabled command prefixes; dot paths allowed (restricts CLI)--enable-commands-exactstringComma-separated list of exact enabled commands; dot paths allowed and parent commands do not enable children-y--force--assume-yes--yesboolSkip confirmations for destructive commands--gmail-no-sendboolfalseBlock Gmail send operations (agent safety)-h--helpkong.helpFlagShow context-sensitive help.--homestringOverride gogcli config/data/state/cache root (equivalent to GOG_HOME)-j--json--machineboolfalseOutput JSON to stdout (best for scripting)--no-input--non-interactive--noninteractiveboolNever prompt; fail instead (useful for CI)-p--plain--tsvboolfalseOutput stable, parseable text to stdout (TSV; no colors)--quota-projectstringGoogle Cloud project to bill for API usage (sent as X-Goog-User-Project; some APIs require it with --access-token or ADC)--readonlyboolfalseBlock mutating API requests at runtime; auth add also requests read-only OAuth scopes--results-onlyboolIn JSON mode, emit only the primary result (drops envelope fields like nextPageToken)--select--pick--projectstringIn JSON mode, select comma-separated fields (best-effort; supports dot paths). Desire path: use --fields for most commands.--spacestringSpace name (required when message is a bare ID)-v--verboseboolEnable verbose logging--versionkong.VersionFlagPrint version and exit--wrap-untrustedboolfalseIn JSON/raw output, wrap fetched text fields in external untrusted-content markers对写脚本的读者最常用的是-a/--account多账号环境下指定使用哪个已登录账号邮箱、别名或auto-n/--dry-run只打印将要执行的操作而不真正调用 API适合让 Agent 先预览变更-j/--json输出 JSON便于管道处理配合--results-only可去掉nextPageToken等信封字段-p/--plain输出无颜色的 TSV 稳定文本--readonly运行时拦截一切变更类 API 请求——对本命令这类写操作相当于硬保险--space本命令特有的参数用于裸 ID 场景见上文。执行流程与源码实现命令的核心逻辑位于 ChatMessagesReactionsCreateCmd.Run执行顺序如下参数归一化normalizeMessage(c.Space, c.Message)把message/--space解析为标准资源名失败即返回 usage 错误退出码 2不会建立任何 API 连接。emoji 校验TrimSpace后为空则报required: emoji。dry-run 拦截调用dryRunExit(ctx, flags, chat.messages.reactions.create, {...})实现见 internal/cmd/dryrun.go。若带-n此时打印操作名chat.messages.reactions.create及message、emoji两个字段后直接成功退出。账号解析requireAccount(flags)解析-a指定的账号随后requireWorkspaceAccount(account)校验账号类型见下一节。发起 API 调用通过chatService(ctx, account)构造 Google Chat API v1 客户端构造chat.Reaction{Emoji: chat.Emoji{Unicode: emoji}}调用svc.Spaces.Messages.Reactions.Create(message, reaction).Context(ctx).Do()完成添加。结果输出JSON 模式输出{reaction: 服务端返回的 Reaction 资源}文本模式输出一行 TSVresourceTABreaction 资源名reaction 资源名形如spaces/AAA/messages/msg1/reactions/r1。从源码结构看该命令的 API 面非常克制只发送emoji.unicode一个字段不做任何确认交互回应属于低风险可撤销操作——配合兄弟命令 delete 即可撤销因此-y/--force在此命令上并不起实际作用。Workspace 账号限制Google Chat 是企业产品因此该命令要求登录账号必须是 Google Workspace非消费级账号。实现见 requireWorkspaceAccountfunc requireWorkspaceAccount(account string) error { if isConsumerAccount(account) { return usage(chat requires a Google Workspace account (non-gmail.com)) } return nil }其中 isConsumerAccount 通过账号邮箱的域名单独判断gmail.com与googlemail.com视为消费级账号并直接拒绝。对应的集成测试TestExecute_ChatMessagesReactionsCreate_ConsumerBlocked验证了用usergmail.com执行该命令会失败且错误信息包含Workspace同时断言不会真正创建 Chat 服务客户端。注意该校验发生在参数归一化、dry-run 之后、API 调用之前也就是说-n --dry-run加一个消费级账号仍可正常预览但真实执行会被拦截。输出格式文本模式默认成功时输出一行 TSV第二列为新建 reaction 的资源名resource spaces/AAA/messages/msg1/reactions/r1JSON 模式-j/--json输出形如测试断言见 chat_reactions_test.go{ reaction: { name: spaces/AAA/messages/msg1/reactions/r1, emoji: {unicode: } } }reaction.name即可直接作为 delete 命令 的入参方便在脚本里实现“加回应 → 校验 → 撤销”的闭环。典型用法组合# 1) 完整资源名添加回应 gog chat messages reactions create spaces/AAA/messages/msg1 # 2) 裸 ID --space gog chat messages reactions create msg1 --space AAA # 3) dry-run 预览不产生任何变更 gog chat messages reactions create msg1 --space AAA -n # 4) JSON 输出取出 reaction 资源名用于后续删除 RID$(gog -j chat messages reactions create msg1 --space AAA \ | jq -r .reaction.name) # 5) 列出该消息当前的全部回应配合 --json 可程序化处理 gog chat messages reactions list spaces/AAA/messages/msg1测试验证该命令的行为由 internal/cmd/chat_reactions_test.go 中的 httptest 假服务端到端覆盖关键用例包括TestExecute_ChatMessagesReactionsCreate_JSON断言出站请求为POST .../reactions、body 中emoji.unicode 且 stdout 可解析为含/reactions/资源名的reaction对象TestExecute_ChatMessagesReactionsCreate_BareIDWithSpace断言msg1--space AAA最终请求路径包含spaces/AAA/messages/msg1TestExecute_ChatMessagesReactionsCreate_InvalidMessageFailsBeforeDryRun非法 message/space 在退出码 2 上失败且不建立Chat 服务客户端校验先于网络TestExecute_ChatMessagesReact_Shorthand验证gog chat messages react快捷命令发送的 HTTP 路径与 emoji 均正确TestExecute_ChatMessagesReactionsCreate_ConsumerBlocked验证消费级账号被拦截。延伸阅读gog chat messages reactions回应管理命令组总览list/deletegog chat messagesChat 消息完整命令族gog chat spaces list、gog chat threads list获取 space/消息资源名的来源命令命令索引全部gog命令参考参考页由gog schema --json生成并通过make docs-commands维护见参考页头部说明命令树变化时以仓库实际--help输出为准。【免费下载链接】gogcliGoogle Workspace in your terminal.项目地址: https://gitcode.com/GitHub_Trending/gogcl/gogcli创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表