diff --git a/packages/api/src/activities/activity.spec.ts b/packages/api/src/activities/activity.spec.ts index dd1b7767a..a423accb8 100644 --- a/packages/api/src/activities/activity.spec.ts +++ b/packages/api/src/activities/activity.spec.ts @@ -33,9 +33,7 @@ describe('Activity', () => { conversation: chat, }) .withRecipient(bot) - .withServiceUrl('http://localhost') - .withTimestamp(new Date()) - .withLocalTimestamp(new Date()); + .withServiceUrl('http://localhost'); expect(activity.id).toEqual('1'); expect(activity.type).toEqual('test'); @@ -51,8 +49,20 @@ describe('Activity', () => { expect(activity.recipient).toEqual(bot); expect(activity.serviceUrl).toEqual('http://localhost'); - expect(activity.timestamp).toBeDefined(); - expect(activity.localTimestamp).toBeDefined(); + }); + + it('should preserve timestamp strings from constructor data', () => { + const timestamp = '2026-06-04T21:00:00.000Z'; + const localTimestamp = '2026-06-04T14:00:00.000-07:00'; + + const activity = new Activity({ + type: 'test', + timestamp, + localTimestamp, + }); + + expect(activity.timestamp).toEqual(timestamp); + expect(activity.localTimestamp).toEqual(localTimestamp); }); it('should build from interface', () => { diff --git a/packages/api/src/activities/activity.ts b/packages/api/src/activities/activity.ts index d23162ed1..588c05579 100644 --- a/packages/api/src/activities/activity.ts +++ b/packages/api/src/activities/activity.ts @@ -34,7 +34,7 @@ export interface IActivity { /** * Contains the date and time that the message was sent, in UTC, expressed in ISO-8601 format. */ - timestamp?: Date; + timestamp?: string; /** * A locale name for the contents of the text field. @@ -50,7 +50,7 @@ export interface IActivity { * * For example, 2016-09-23T13:07:49.4714686-07:00. */ - localTimestamp?: Date; + localTimestamp?: string; /** * Contains an ID that uniquely identifies the channel. Set by the channel. @@ -138,7 +138,7 @@ export class Activity implements IActivity { /** * Contains the date and time that the message was sent, in UTC, expressed in ISO-8601 format. */ - timestamp?: Date; + timestamp?: string; /** * A locale name for the contents of the text field. @@ -154,7 +154,7 @@ export class Activity implements IActivity { * * For example, 2016-09-23T13:07:49.4714686-07:00. */ - localTimestamp?: Date; + localTimestamp?: string; /** * Contains an ID that uniquely identifies the channel. Set by the channel. @@ -302,21 +302,11 @@ export class Activity implements IActivity { return this; } - withTimestamp(value: Date) { - this.timestamp = value; - return this; - } - withLocale(value: string) { this.locale = value; return this; } - withLocalTimestamp(value: Date) { - this.localTimestamp = value; - return this; - } - withChannelData(value: ChannelData) { const merged: ChannelData = { ...this.channelData, ...value }; diff --git a/packages/devtools/src/stores/ChatStore.ts b/packages/devtools/src/stores/ChatStore.ts index 5f77ea2ae..4bf53947a 100644 --- a/packages/devtools/src/stores/ChatStore.ts +++ b/packages/devtools/src/stores/ChatStore.ts @@ -40,6 +40,10 @@ interface MessageBase { createdDateTime: string; } +const toUTCString = (value?: string | Date) => { + return (value instanceof Date ? value : new Date(value || Date.now())).toUTCString(); +}; + const createMessageBase = ( event: ActivityEvent ): MessageBase => { @@ -66,7 +70,7 @@ const createMessageBase = ( } : undefined, }, - createdDateTime: (event.body.timestamp || new Date()).toUTCString(), + createdDateTime: toUTCString(event.body.timestamp), }; }; @@ -303,7 +307,7 @@ export const useChatStore = create()( message.body.textContent = event.body.text; } - message.lastModifiedDateTime = (event.body.timestamp || new Date()).toUTCString(); + message.lastModifiedDateTime = toUTCString(event.body.timestamp); state.put(state.chat.id, message); return state; }, diff --git a/packages/devtools/src/utils/create-feedback.ts b/packages/devtools/src/utils/create-feedback.ts index 590c55576..c757d73cd 100644 --- a/packages/devtools/src/utils/create-feedback.ts +++ b/packages/devtools/src/utils/create-feedback.ts @@ -49,7 +49,7 @@ export const createFeedbackActivity = ({ conversationType: conversation.conversationType || 'personal', }, recipient: invokeRecipient, - localTimestamp: new Date(), + localTimestamp: new Date().toISOString(), locale, value: { actionName: 'feedback' as const,