← Commit history

chat send: --json emits the created message as JSON instead of the human line

Drew Owens ·9a3e31f5a5 · ·parent d77587a
Catch-up of Kyle Bergstedt's commit 577c58d (2026-10-19) from GitHub adom-inc/adom-google main, which was never published to the wiki. Additive: --json on chat send was previously an argparse error. Applied verbatim; the parser hunk was re-applied by hand over this PR's chat dm change.
1 file changed +10−1
bin/adom-google+10−1
@@ -1247,6 +1247,14 @@ def cmd_chat_send(a):     msg = _chat(cfg, f"{space}/messages", method="POST", body=body, params=params or None)     uri = sp.get("spaceUri", "")     who = (msg.get("sender") or {}).get("displayName") or "you"+    if getattr(a, "json", False):+        # Machine-readable envelope: the message as Chat returned it, plus the resolved+        # space/label/uri. (An agent piping `--json` into json.load got the human line+        # and a JSONDecodeError, then could not tell whether the post landed — 2026-10-19.)+        out = dict(msg)+        out.update({"space": space, "label": label, "spaceUri": uri, "posted": True})+        print(json.dumps(out, indent=2, ensure_ascii=False))+        return     print(msg.get("name", "") + (f"  ·  {uri}" if uri else ""))     sys.stderr.write(f"→ posted to {label} as {who}" + (f" · {uri}" if uri else "") + "\n") @@ -2481,6 +2489,7 @@ CHAT (Google Chat — posts as YOU, your own identity, no attribution prefix;   adom-google chat send --to <space-id|email> "<text>" post a message (email auto-resolves DM)       "<text>" may be '-' (stdin) or '@file'; --thread <key> replies in a thread   adom-google chat read --from <space-id|email> [--limit N] [--json]   recent messages+  adom-google chat send --to <space-id|email> "text" [--thread K] [--attach P]... [--json]  API (generic passthrough — hit ANY Google API with your token; the "whole board"):   adom-google api <url> [-X METHOD] [-d '<json>'|@file] [-q k=v ...] [--raw]@@ -2950,7 +2959,7 @@ def main():     ch = sub.add_parser("chat"); chx = ch.add_subparsers(dest="sub")     x = chx.add_parser("spaces"); x.add_argument("--json", action="store_true"); x.set_defaults(fn=cmd_chat_spaces)     x = chx.add_parser("dm", help="resolve the 1:1 DM space with a person (email, or a name looked up in your Workspace domain directory)"); x.add_argument("email", metavar="email|name", help="an email, or a name resolved ONLY through your own Workspace domain directory: a unique exact first-name / full-name / email-local-part match, or a single result; anything else is an ERROR listing the candidates"); x.add_argument("--json", action="store_true"); x.set_defaults(fn=cmd_chat_dm)-    x = chx.add_parser("send"); x.add_argument("--to", required=True, help="spaces/XXX id OR an email (auto-resolves the DM)"); x.add_argument("text", nargs="?", default="", help="message text, or '-' for stdin, or '@file' (optional when --attach is used)"); x.add_argument("--thread", help="threadKey for a threaded reply"); x.add_argument("--attach", action="append", metavar="PATH", help="attach a local file (image/video/PDF/any); repeatable"); x.add_argument("--no-agent-marker", action="store_true", help="don't stamp clientAssignedMessageId=client-agent-*"); x.set_defaults(fn=cmd_chat_send)+    x = chx.add_parser("send"); x.add_argument("--to", required=True, help="spaces/XXX id OR an email (auto-resolves the DM)"); x.add_argument("text", nargs="?", default="", help="message text, or '-' for stdin, or '@file' (optional when --attach is used)"); x.add_argument("--thread", help="threadKey for a threaded reply"); x.add_argument("--attach", action="append", metavar="PATH", help="attach a local file (image/video/PDF/any); repeatable"); x.add_argument("--no-agent-marker", action="store_true", help="don't stamp clientAssignedMessageId=client-agent-*"); x.add_argument("--json", action="store_true", help="print the created message as JSON (name, createTime, text, space, spaceUri, posted)"); x.set_defaults(fn=cmd_chat_send)     x = chx.add_parser("read"); x.add_argument("--from", dest="frm", required=True, help="spaces/XXX id OR an email"); x.add_argument("--limit", type=int, default=20); x.add_argument("--json", action="store_true"); x.set_defaults(fn=cmd_chat_read)      # Calendar (issue #662)