fix(bluebubbles): recover outbound message IDs and include sender metadata

This commit is contained in:
Tyler Yust
2026-02-17 11:12:09 -08:00
parent 98962ed81d
commit e1015a5197
5 changed files with 375 additions and 15 deletions

View File

@@ -10,6 +10,14 @@ function parseInboundMetaPayload(text: string): Record<string, unknown> {
return JSON.parse(match[1]) as Record<string, unknown>;
}
function parseConversationInfoPayload(text: string): Record<string, unknown> {
const match = text.match(/Conversation info \(untrusted metadata\):\n```json\n([\s\S]*?)\n```/);
if (!match?.[1]) {
throw new Error("missing conversation info json block");
}
return JSON.parse(match[1]) as Record<string, unknown>;
}
describe("buildInboundMetaSystemPrompt", () => {
it("includes trusted message and routing ids for tool actions", () => {
const prompt = buildInboundMetaSystemPrompt({
@@ -127,4 +135,24 @@ describe("buildInboundUserContextPrefix", () => {
expect(text).toContain("Conversation info (untrusted metadata):");
expect(text).toContain('"conversation_label": "ops-room"');
});
it("includes sender identifier in conversation info", () => {
const text = buildInboundUserContextPrefix({
ChatType: "direct",
SenderE164: " +15551234567 ",
} as TemplateContext);
const conversationInfo = parseConversationInfoPayload(text);
expect(conversationInfo["sender"]).toBe("+15551234567");
});
it("falls back to SenderId when sender phone is missing", () => {
const text = buildInboundUserContextPrefix({
ChatType: "direct",
SenderId: " user@example.com ",
} as TemplateContext);
const conversationInfo = parseConversationInfoPayload(text);
expect(conversationInfo["sender"]).toBe("user@example.com");
});
});

View File

@@ -62,6 +62,7 @@ export function buildInboundUserContextPrefix(ctx: TemplateContext): string {
const conversationInfo = {
conversation_label: isDirect ? undefined : safeTrim(ctx.ConversationLabel),
sender: safeTrim(ctx.SenderE164) ?? safeTrim(ctx.SenderId) ?? safeTrim(ctx.SenderUsername),
group_subject: safeTrim(ctx.GroupSubject),
group_channel: safeTrim(ctx.GroupChannel),
group_space: safeTrim(ctx.GroupSpace),