Skip to content

fix(api): Activity.timestamp should be string instead of Date (type only)#571

Open
heyitsaamir wants to merge 1 commit into
mainfrom
fix/activity-timestamp-string
Open

fix(api): Activity.timestamp should be string instead of Date (type only)#571
heyitsaamir wants to merge 1 commit into
mainfrom
fix/activity-timestamp-string

Conversation

@heyitsaamir
Copy link
Copy Markdown
Collaborator

Activity.timestamp was lying about being a Date. It's a string. Always was. The doc comment literally says "expressed in ISO-8601 format" two lines above the : Date annotation 🙃

Inbound activities go through express.json() (no reviver), and Activity.from() is just Object.assign — nothing ever turns it into a Date. So activity.timestamp.toISOString() in a handler? Crash.

Fix: type as string. Builders still accept Date and normalize via toISOString() so nobody's call sites blow up.

Same treatment for localTimestamp.

The Bot Framework Activity protocol sends these as ISO-8601 strings
over JSON (as the existing doc comments already say). Inbound
activities are parsed by express.json() with no reviver and
Activity.from() is just Object.assign — so at runtime these fields
are strings, not Date objects. The Date type was a lie; calling
activity.timestamp.toISOString() in a handler would crash.

The withTimestamp/withLocalTimestamp builders still accept Date for
ergonomics and normalize via toISOString(), so existing call sites
keep working.
Copilot AI review requested due to automatic review settings May 10, 2026 06:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR corrects the public typings for Activity.timestamp and Activity.localTimestamp in @microsoft/teams.api to reflect actual runtime behavior: these fields are ISO-8601 strings on inbound activities, not Date objects. It also updates the fluent builder methods to keep accepting Date inputs while normalizing them to ISO strings to avoid breaking common construction patterns.

Changes:

  • Change IActivity.timestamp / localTimestamp and Activity.timestamp / localTimestamp from Date to string.
  • Update withTimestamp and withLocalTimestamp to accept Date | string, converting Date inputs to toISOString().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 49 to +53
* Contains the local date and time of the message, expressed in ISO-8601 format.
*
* For example, 2016-09-23T13:07:49.4714686-07:00.
*/
localTimestamp?: Date;
localTimestamp?: string;
Comment on lines +305 to 307
withTimestamp(value: Date | string) {
this.timestamp = value instanceof Date ? value.toISOString() : value;
return this;
Comment on lines +315 to 317
withLocalTimestamp(value: Date | string) {
this.localTimestamp = value instanceof Date ? value.toISOString() : value;
return this;
@heyitsaamir heyitsaamir changed the title fix(api): Activity.timestamp was lying about being a Date fix(api): Activity.timestamp should be string instead of Date (type only) May 10, 2026

withTimestamp(value: Date) {
this.timestamp = value;
withTimestamp(value: Date | string) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should review if this method should be marked as obsolete, along with changes in #525. Timestamps set on outgoing activities are ignored

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants