AgentNotificationActivity Class

Wrapper around an Activity object with typed notification entities.

This class provides convenient access to typed notification entities extracted from an Activity's entities collection. It automatically parses and validates email notifications, Word/PowerPoint/Excel comments, and lifecycle events at construction time.

Constructor

AgentNotificationActivity()

Parameters

Name Description
activity
Required

The Activity object to wrap. Must not be None.

Examples

``<<>>`<<python async def email_handler(context: TurnContext, state: TurnState, notification: AgentNotificationActivity):

email = notification.email if email:

  print(f"Received email: {email.id}")
  print(f"Body: {email.html_body}")

``<<>>`<<

Methods

__init__
__new__
as_model

Parse the activity value as a custom model type.

This method provides a generic way to validate and parse the activity's value payload into any Pydantic model type. Useful for custom notification types not directly supported by the typed properties.

__init__

__init__(activity: Activity)

Parameters

Name Description
activity
Required

__new__

__new__(**kwargs)

as_model

Parse the activity value as a custom model type.

This method provides a generic way to validate and parse the activity's value payload into any Pydantic model type. Useful for custom notification types not directly supported by the typed properties.

as_model(model: Type[TModel]) -> TModel | None

Parameters

Name Description
model
Required
Type[<xref:microsoft_agents_a365.notifications.models.agent_notification_activity.TModel>]

A Pydantic model class to validate and parse the activity value into.

Returns

Type Description
<xref:microsoft_agents_a365.notifications.models.agent_notification_activity.TModel> | None

An instance of the specified model type if validation succeeds, otherwise None.

Examples

``<<>>`<<python from pydantic import BaseModel

class CustomNotification(BaseModel): custom_field: str

notification = AgentNotificationActivity(activity) custom = notification.as_model(CustomNotification) if custom:

print(custom.custom_field)

``<<>>`<<

Attributes

channel

The channel identifier from the activity's channel_id.

Returns

Type Description

The channel name (e.g., 'agents', 'msteams') or None if not available.

email

The parsed email reference entity, if present.

Returns

Type Description

An EmailReference object if an email notification entity was found and successfully parsed, otherwise None.

notification_type

The detected notification type.

Returns

Type Description

The NotificationTypes enum value indicating the type of notification (EMAIL_NOTIFICATION, WPX_COMMENT, or AGENT_LIFECYCLE), or None if the notification type could not be determined.

sub_channel

The subchannel identifier from the activity's channel_id.

Returns

Type Description

The subchannel name (e.g., 'email', 'word') or None if not available.

type

The activity type.

Returns

Type Description

The type of the activity (e.g., 'message', 'event') or None if not set.

value

The value payload from the activity.

Returns

Type Description

The activity's value, which may contain additional notification data.

wpx_comment

The parsed Word/PowerPoint/Excel comment entity, if present.

Returns

Type Description

A WpxComment object if a comment entity was found and successfully parsed, otherwise None.

activity

The underlying Activity object.