Skip to content

Conversation

@rido-min
Copy link
Member

@rido-min rido-min commented Jan 8, 2026

BF Adapter base expects an Id in the SendActivity return value.

Without this fix, the compat layer throws NRE

This pull request introduces several updates to the bot framework sample applications and core libraries, mainly focusing on improving the handling and propagation of InvokeResponse objects, refining status codes, and enhancing logging and code structure. The changes help standardize response formats, improve traceability, and clarify code intent.

InvokeResponse Handling and Status Codes

  • Added an Id property to the InvokeResponse class, ensuring responses can be correlated to originating activities, and updated serialization attributes for Body and Type to ignore nulls for cleaner JSON output. [1] [2] [3]
  • Standardized and diversified status codes for InvokeResponse across sample bots and core libraries (EchoBot, CoreBot, TeamsBot, and core adapter), improving clarity in response semantics. [1] [2] [3] [4] [5]

Refactoring and Code Structure

  • Moved proactive message send/update/delete logic in EchoBot to a dedicated helper method (SendUpdateDeleteActivityAsync), improving code readability and maintainability. [1] [2]
  • Minor code cleanup in EchoBot.cs, such as removing unused using statements.

Logging and Diagnostics

  • Enhanced logging in CompatBotAdapter to provide better traceability of activity responses, replacing a warning for null responses with information logs and always assigning the response ID.

Other Improvements

  • Added null-handling and improved response assignment in activity deletion logic for the compat adapter.

These updates collectively improve the reliability, maintainability, and clarity of bot applications and supporting libraries.

Refactored the handling of SendActivityAsync responses by removing the null check and warning log. Now, the response ID is always assigned (even if null), and an informational log records the response ID. This streamlines the code and improves logging clarity.
Introduce granular status codes for InvokeResponse across the bot, add optional Id property, and improve conditional serialization of Type and Body. Refactor proactive message logic in EchoBot, add message reaction handler, and update response handling in Program.cs, CompatAdapter, and TeamsBotApplication to include activity Ids and new status codes.
@rido-min rido-min changed the base branch from main to next/core January 8, 2026 03:32
@rido-min rido-min marked this pull request as ready for review January 8, 2026 03:33
@rido-min rido-min added the CORE label Jan 8, 2026
@rajan-chari
Copy link
Contributor

I asked Claude Code to review PR. Results are here:

image

Refactored the bot and Teams application layers to handle invoke responses by writing directly to the HTTP response stream, removing the need to return InvokeResponse objects through the pipeline. Updated delegate and middleware signatures to return Task instead of Task<InvokeResponse?>. Introduced CoreInvokeResponse as the standard invoke response type. Updated adapters and application builders to use IHttpContextAccessor for response handling. Adjusted tests and removed legacy code to align with the new response model, simplifying and modernizing the activity processing flow.
- Re-enabled echo and proactive messaging in EchoBot
- Refactored invokeResponse handling in CompatBotAdapter
- Replaced ArgumentNullException with ArgumentException for string validation
- Moved CoreInvokeResponse to InvokeHandler.cs for consolidation
- Removed ActivityType.Invoke; use hardcoded "invoke" in TeamsActivityType
- Cleaned up middleware and removed unused usings
- Allowed route path in UseBotApplication for flexible routing
- Updated tests for new handler signatures and validation
- General code cleanup and improved maintainability
Refactored CompatBotAdapter to use StreamWriter and JsonTextWriter with BotMessageSerializer.Serialize (Newtonsoft.Json) for writing InvokeResponse to HTTP response. Removed System.Text.Json-based serialization and added commented alternatives for reference. This improves compatibility with Bot Framework serialization expectations.
Comment on lines +41 to +52
[JsonPropertyName("value")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public object? Body { get; set; } = body;

// TODO: Get confirmation that this should be "Type"
// This particular type should be for AC responses
/// <summary>
/// Gets or Sets the Type
/// </summary>
[JsonPropertyName("type")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Type { get; set; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, this is not exactly correct since "value" etc is for adaptive cards

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe InvokeResponse should be abstract

Copy link
Member Author

Choose a reason for hiding this comment

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

IIRC Value is for any invoke.

Keep in mind the goal is the compat layer, once we get into the new FE we will look into the concrete invoke types

Copy link
Collaborator

Choose a reason for hiding this comment

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

Gotcha, so let's add a TODO here so we fix this for the new FE?

Copy link
Collaborator

@heyitsaamir heyitsaamir left a comment

Choose a reason for hiding this comment

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

lgtm! 1 comment about a todo

@rido-min rido-min merged commit 1ac1a07 into next/core Jan 12, 2026
3 checks passed
@rido-min rido-min deleted the core/next-fix-return-id branch January 12, 2026 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants