mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-29 02:41:07 +00:00
fix(msteams): normalize memory store conversation ids
This commit is contained in:
@@ -126,6 +126,25 @@ describe("msteams conversation store (fs)", () => {
|
||||
});
|
||||
|
||||
describe("msteams conversation store (memory)", () => {
|
||||
it("normalizes conversation ids the same way as the fs store", async () => {
|
||||
const store = createMSTeamsConversationStoreMemory();
|
||||
|
||||
await store.upsert("conv-norm;messageid=123", {
|
||||
conversation: { id: "conv-norm" },
|
||||
channelId: "msteams",
|
||||
serviceUrl: "https://service.example.com",
|
||||
user: { id: "u1" },
|
||||
});
|
||||
|
||||
await expect(store.get("conv-norm")).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
conversation: { id: "conv-norm" },
|
||||
}),
|
||||
);
|
||||
await expect(store.remove("conv-norm")).resolves.toBe(true);
|
||||
await expect(store.get("conv-norm;messageid=123")).resolves.toBeNull();
|
||||
});
|
||||
|
||||
it("upserts, lists, removes, and resolves users by both AAD and Bot Framework ids", async () => {
|
||||
const store = createMSTeamsConversationStoreMemory([
|
||||
{
|
||||
|
||||
@@ -8,20 +8,22 @@ export function createMSTeamsConversationStoreMemory(
|
||||
initial: MSTeamsConversationStoreEntry[] = [],
|
||||
): MSTeamsConversationStore {
|
||||
const map = new Map<string, StoredConversationReference>();
|
||||
const normalizeConversationId = (raw: string): string => raw.split(";")[0] ?? raw;
|
||||
for (const { conversationId, reference } of initial) {
|
||||
map.set(conversationId, reference);
|
||||
map.set(normalizeConversationId(conversationId), reference);
|
||||
}
|
||||
|
||||
return {
|
||||
upsert: async (conversationId, reference) => {
|
||||
const existing = map.get(conversationId);
|
||||
map.set(conversationId, {
|
||||
const normalizedId = normalizeConversationId(conversationId);
|
||||
const existing = map.get(normalizedId);
|
||||
map.set(normalizedId, {
|
||||
...(existing?.timezone && !reference.timezone ? { timezone: existing.timezone } : {}),
|
||||
...reference,
|
||||
});
|
||||
},
|
||||
get: async (conversationId) => {
|
||||
return map.get(conversationId) ?? null;
|
||||
return map.get(normalizeConversationId(conversationId)) ?? null;
|
||||
},
|
||||
list: async () => {
|
||||
return Array.from(map.entries()).map(([conversationId, reference]) => ({
|
||||
@@ -30,7 +32,7 @@ export function createMSTeamsConversationStoreMemory(
|
||||
}));
|
||||
},
|
||||
remove: async (conversationId) => {
|
||||
return map.delete(conversationId);
|
||||
return map.delete(normalizeConversationId(conversationId));
|
||||
},
|
||||
findByUserId: async (id) => {
|
||||
const target = id.trim();
|
||||
|
||||
Reference in New Issue
Block a user