Skip to content

fix: conditionally set citation encodingFormat based on text presence#579

Open
chonlaphoom wants to merge 1 commit into
microsoft:mainfrom
chonlaphoom:fix/citation-encoding-format
Open

fix: conditionally set citation encodingFormat based on text presence#579
chonlaphoom wants to merge 1 commit into
microsoft:mainfrom
chonlaphoom:fix/citation-encoding-format

Conversation

@chonlaphoom
Copy link
Copy Markdown
Contributor

@chonlaphoom chonlaphoom commented May 15, 2026

While following the citations example (https://microsoft.github.io/teams-sdk/typescript/in-depth-guides/ai/best-practices) (which calls addCitation without text), I encountered a BadSyntax error: citation.appearance.text and citation.appearance.encodingFormat must either both be empty or both have values. This happens because encodingFormat was unconditionally set to 'application/vnd.microsoft.card.adaptive', even when text was omitted

Summary

Fixes BadSyntax error when addCitation is called without text.

Problem

Calling addCitation(position, appearance) without appearance.text causes a 400 error:

code: "BadSyntax"
message: "Error while parsing citation entity with id: x"
Detail: "citation.appearance.text and citation.appearance.encodingFormat must either both be empty or both have values"

The root cause: encodingFormat was hardcoded to 'application/vnd.microsoft.card.adaptive' unconditionally, but the Teams API requires it to be absent when text is absent.

Fix

Changed encodingFormat to be set only when appearance.text is truthy:

encodingFormat: appearance.text ? 'application/vnd.microsoft.card.adaptive' : undefined,

The encodingFormat field must be present only when citation text is provided,
otherwise Teams API returns a BadSyntax error.
Copilot AI review requested due to automatic review settings May 15, 2026 16:04
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 fixes citation payload construction so encodingFormat is only populated when citation text is present, avoiding Teams API BadSyntax responses for citations without adaptive card text.

Changes:

  • Conditionally sets citation encodingFormat based on appearance.text.
  • Updates addCitation tests to cover text/no-text behavior and icon handling.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/api/src/activities/activity.ts Updates citation appearance construction to avoid setting encodingFormat without text.
packages/api/src/activities/activity.spec.ts Adjusts and expands addCitation test cases for encoding format behavior.

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

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.

2 participants