fix: imessage dm replies and error details (#935)
This commit is contained in:
@@ -180,7 +180,17 @@ export class IMessageRpcClient {
|
||||
this.pending.delete(key);
|
||||
|
||||
if (parsed.error) {
|
||||
const msg = parsed.error.message ?? "imsg rpc error";
|
||||
const baseMessage = parsed.error.message ?? "imsg rpc error";
|
||||
const details = parsed.error.data;
|
||||
const code = parsed.error.code;
|
||||
const suffixes = [] as string[];
|
||||
if (typeof code === "number") suffixes.push(`code=${code}`);
|
||||
if (details !== undefined) {
|
||||
const detailText =
|
||||
typeof details === "string" ? details : JSON.stringify(details, null, 2);
|
||||
if (detailText) suffixes.push(detailText);
|
||||
}
|
||||
const msg = suffixes.length > 0 ? `${baseMessage}: ${suffixes.join(" ")}` : baseMessage;
|
||||
pending.reject(new Error(msg));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ beforeEach(() => {
|
||||
});
|
||||
|
||||
describe("monitorIMessageProvider", () => {
|
||||
it("updates last route with chat_id for direct messages", async () => {
|
||||
it("updates last route with sender handle for direct messages", async () => {
|
||||
replyMock.mockResolvedValueOnce({ text: "ok" });
|
||||
const run = monitorIMessageProvider();
|
||||
await waitForSubscribe();
|
||||
@@ -118,7 +118,7 @@ describe("monitorIMessageProvider", () => {
|
||||
expect(updateLastRouteMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
channel: "imessage",
|
||||
to: "chat_id:7",
|
||||
to: "+15550004444",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -296,7 +296,7 @@ export async function monitorIMessageProvider(opts: MonitorIMessageOpts = {}): P
|
||||
});
|
||||
}
|
||||
|
||||
const imessageTo = chatTarget || `imessage:${sender}`;
|
||||
const imessageTo = (isGroup ? chatTarget : undefined) || `imessage:${sender}`;
|
||||
const ctxPayload = {
|
||||
Body: combinedBody,
|
||||
RawBody: bodyText,
|
||||
@@ -329,7 +329,7 @@ export async function monitorIMessageProvider(opts: MonitorIMessageOpts = {}): P
|
||||
const storePath = resolveStorePath(sessionCfg?.store, {
|
||||
agentId: route.agentId,
|
||||
});
|
||||
const to = chatTarget || sender;
|
||||
const to = (isGroup ? chatTarget : undefined) || sender;
|
||||
if (to) {
|
||||
await updateLastRoute({
|
||||
storePath,
|
||||
|
||||
Reference in New Issue
Block a user