Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gchat-link-labels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chat-adapter/gchat": patch
---

Preserve custom link labels in Google Chat text messages by rendering Markdown links with Google Chat's supported `<url|text>` syntax.
4 changes: 2 additions & 2 deletions packages/adapter-gchat/src/markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ describe("GoogleChatFormatConverter", () => {
expect(result).toContain("https://example.com");
});

it("should output 'text (url)' when link text differs", () => {
it("should output Google Chat custom link syntax when link text differs", () => {
const ast = converter.toAst("[click here](https://example.com)");
const result = converter.fromAst(ast);
expect(result).toContain("click here (https://example.com)");
expect(result).toContain("<https://example.com|click here>");
});

it("should handle blockquotes", () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/adapter-gchat/src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,14 @@ export class GoogleChatFormatConverter extends BaseFormatConverter {
}

if (isLinkNode(node)) {
// Google Chat auto-detects links, so we just output the URL
// Google Chat supports custom link labels using <url|text> syntax.
const linkText = getNodeChildren(node)
.map((child) => this.nodeToGChat(child))
.join("");
// If link text matches URL, just output URL
if (linkText === node.url) {
return node.url;
}
// Otherwise output "text (url)"
return `${linkText} (${node.url})`;
return `<${node.url}|${linkText}>`;
}

if (isBlockquoteNode(node)) {
Expand Down
26 changes: 26 additions & 0 deletions packages/integration-tests/src/gchat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,32 @@ describe("Google Chat Integration", () => {
expect(sent.text).toContain("`code`");
});

it("should preserve custom link labels in posted messages", async () => {
chat.onNewMention(async (thread) => {
await thread.post({
markdown: "[Click here](https://example.com)",
});
});

const event = createGoogleChatEvent({
text: `@${GCHAT_BOT_NAME} link test`,
messageName: `${TEST_SPACE_NAME}/messages/msg-001`,
spaceName: TEST_SPACE_NAME,
threadName: TEST_THREAD_NAME,
senderId: "users/user-123",
senderName: "John Doe",
hasBotMention: true,
});

await chat.webhooks.gchat(createGoogleChatWebhookRequest(event), {
waitUntil: tracker.waitUntil,
});
await tracker.waitForAll();

const sent = mockChatApi.sentMessages[0];
expect(sent.text).toBe("<https://example.com|Click here>");
});

it("should pass @mentions through as-is in posted messages", async () => {
chat.onNewMention(async (thread) => {
await thread.post("Hey @john, check this out!");
Expand Down
Loading