fix(googlechat): space events response and thread context
Two fixes for Google Chat reliability:
1. Space Events Response (Fixes 'Can't handle app response' error):
- Return proper JSON response for non-MESSAGE events in groups
- Handles ADDED_TO_SPACE, REMOVED_FROM_SPACE, etc.
- Previously returned empty '{}' which caused errors
2. Thread Reply Context (Adds missing context):
- Add threadReply field to GoogleChatMessage type
- Add quotedMessageMetadata field for quoted messages
- Pass IsThreadReply and QuotedMessageId to agent context
- Agent now knows when a message is a reply vs root message
Both fixes improve Google Chat reliability and agent context awareness.
This commit is contained in:
parent
560d31b0ff
commit
d7ede3cd68
@ -264,6 +264,19 @@ export async function handleGoogleChatWebhookRequest(
|
||||
}
|
||||
|
||||
selected.statusSink?.({ lastInboundAt: Date.now() });
|
||||
|
||||
// For synchronous responses in spaces, handle non-MESSAGE events immediately
|
||||
const evtType = (event.type ?? (event as { eventType?: string }).eventType)?.toUpperCase();
|
||||
const isGroup = event.space?.type?.toUpperCase() !== "DM";
|
||||
|
||||
// For non-MESSAGE events in groups (like ADDED_TO_SPACE), return an acknowledgment
|
||||
if (isGroup && evtType !== "MESSAGE") {
|
||||
res.statusCode = 200;
|
||||
res.setHeader("Content-Type", "application/json");
|
||||
res.end(JSON.stringify({ text: "Hello! I'm ready to help. 🦞" }));
|
||||
return true;
|
||||
}
|
||||
|
||||
processGoogleChatEvent(event, selected).catch((err) => {
|
||||
selected?.runtime.error?.(
|
||||
`[${selected.account.accountId}] Google Chat webhook failed: ${String(err)}`,
|
||||
@ -642,6 +655,9 @@ async function processMessageWithPipeline(params: {
|
||||
GroupSystemPrompt: isGroup ? groupSystemPrompt : undefined,
|
||||
OriginatingChannel: "googlechat",
|
||||
OriginatingTo: `googlechat:${spaceId}`,
|
||||
// Thread reply context
|
||||
IsThreadReply: message.threadReply,
|
||||
QuotedMessageId: message.quotedMessageMetadata?.name,
|
||||
});
|
||||
|
||||
void core.channel.session
|
||||
|
||||
@ -47,6 +47,11 @@ export type GoogleChatAnnotation = {
|
||||
customEmojiMetadata?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export type GoogleChatQuotedMessageMetadata = {
|
||||
name?: string;
|
||||
lastUpdateTime?: string;
|
||||
};
|
||||
|
||||
export type GoogleChatMessage = {
|
||||
name?: string;
|
||||
text?: string;
|
||||
@ -55,6 +60,10 @@ export type GoogleChatMessage = {
|
||||
thread?: GoogleChatThread;
|
||||
attachment?: GoogleChatAttachment[];
|
||||
annotations?: GoogleChatAnnotation[];
|
||||
/** True if this message is a reply in a thread */
|
||||
threadReply?: boolean;
|
||||
/** Metadata about the quoted/original message being replied to */
|
||||
quotedMessageMetadata?: GoogleChatQuotedMessageMetadata;
|
||||
};
|
||||
|
||||
export type GoogleChatEvent = {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user