2929#: notification: The typed notification activity with parsed entities.
3030#:
3131#: Example:
32- #: >>> async def handle_email(
33- #: ... context: TurnContext,
34- #: ... state: TurnState,
35- #: ... notification: AgentNotificationActivity,
36- #: ... ) -> None:
37- #: ... email = notification.email
38- #: ... if email:
39- #: ... print(f"Processing email: {email.id}")
32+ #:
33+ #: .. code-block:: python
34+ #:
35+ #: async def handle_email(
36+ #: context: TurnContext,
37+ #: state: TurnState,
38+ #: notification: AgentNotificationActivity,
39+ #: ) -> None:
40+ #: email = notification.email
41+ #: if email:
42+ #: print(f"Processing email: {email.id}")
4043AgentHandler = Callable [[TContext , TState , AgentNotificationActivity ], Awaitable [None ]]
4144
4245
@@ -55,15 +58,19 @@ class AgentNotification:
5558 defaults to all values in the AgentLifecycleEvent enum.
5659
5760 Example:
58- >>> from microsoft_agents.hosting import Application
59- >>> from microsoft_agents_a365.notifications import AgentNotification
60- >>> app = Application()
61- >>> notifications = AgentNotification(app)
62- >>> @notifications.on_email()
63- ... async def handle_email(context, state, notification):
64- ... email = notification.email
65- ... if email:
66- ... await context.send_activity(f"Received email: {email.id}")
61+ .. code-block:: python
62+
63+ from microsoft_agents.hosting import Application
64+ from microsoft_agents_a365.notifications import AgentNotification
65+
66+ app = Application()
67+ notifications = AgentNotification(app)
68+
69+ @notifications.on_email()
70+ async def handle_email(context, state, notification):
71+ email = notification.email
72+ if email:
73+ await context.send_activity(f"Received email: {email.id}")
6774 """
6875
6976 def __init__ (
@@ -120,12 +127,15 @@ def on_agent_notification(
120127 A decorator function that registers the handler with the application.
121128
122129 Example:
123- >>> from microsoft_agents.activity import ChannelId
124- >>> @notifications.on_agent_notification(
125- ... ChannelId(channel="agents", sub_channel="email")
126- ... )
127- ... async def handle_custom_channel(context, state, notification):
128- ... print(f"Received notification on {notification.channel}/{notification.sub_channel}")
130+ .. code-block:: python
131+
132+ from microsoft_agents.activity import ChannelId
133+
134+ @notifications.on_agent_notification(
135+ ChannelId(channel="agents", sub_channel="email")
136+ )
137+ async def handle_custom_channel(context, state, notification):
138+ print(f"Received notification on {notification.channel}/{notification.sub_channel}")
129139 """
130140 registered_channel = channel_id .channel .lower ()
131141 registered_subchannel = (channel_id .sub_channel or "*" ).lower ()
@@ -175,9 +185,11 @@ def on_agent_lifecycle_notification(
175185 A decorator function that registers the handler with the application.
176186
177187 Example:
178- >>> @notifications.on_agent_lifecycle_notification("agenticuseridentitycreated")
179- ... async def handle_user_created(context, state, notification):
180- ... print("New user created")
188+ .. code-block:: python
189+
190+ @notifications.on_agent_lifecycle_notification("agenticuseridentitycreated")
191+ async def handle_user_created(context, state, notification):
192+ print("New user created")
181193 """
182194
183195 def route_selector (context : TurnContext ) -> bool :
@@ -223,15 +235,17 @@ def on_email(
223235 A decorator function that registers the handler with the application.
224236
225237 Example:
226- >>> @notifications.on_email()
227- ... async def handle_email(context, state, notification):
228- ... email = notification.email
229- ... if email:
230- ... print(f"Received email: {email.id}")
231- ... response = EmailResponse.create_email_response_activity(
232- ... "<p>Thank you for your email.</p>"
233- ... )
234- ... await context.send_activity(response)
238+ .. code-block:: python
239+
240+ @notifications.on_email()
241+ async def handle_email(context, state, notification):
242+ email = notification.email
243+ if email:
244+ print(f"Received email: {email.id}")
245+ response = EmailResponse.create_email_response_activity(
246+ "<p>Thank you for your email.</p>"
247+ )
248+ await context.send_activity(response)
235249 """
236250 return self .on_agent_notification (
237251 ChannelId (channel = "agents" , sub_channel = AgentSubChannel .EMAIL ), ** kwargs
@@ -252,11 +266,13 @@ def on_word(
252266 A decorator function that registers the handler with the application.
253267
254268 Example:
255- >>> @notifications.on_word()
256- ... async def handle_word_comment(context, state, notification):
257- ... comment = notification.wpx_comment
258- ... if comment:
259- ... print(f"Received Word comment: {comment.comment_id}")
269+ .. code-block:: python
270+
271+ @notifications.on_word()
272+ async def handle_word_comment(context, state, notification):
273+ comment = notification.wpx_comment
274+ if comment:
275+ print(f"Received Word comment: {comment.comment_id}")
260276 """
261277 return self .on_agent_notification (
262278 ChannelId (channel = "agents" , sub_channel = AgentSubChannel .WORD ), ** kwargs
@@ -277,11 +293,13 @@ def on_excel(
277293 A decorator function that registers the handler with the application.
278294
279295 Example:
280- >>> @notifications.on_excel()
281- ... async def handle_excel_comment(context, state, notification):
282- ... comment = notification.wpx_comment
283- ... if comment:
284- ... print(f"Received Excel comment: {comment.comment_id}")
296+ .. code-block:: python
297+
298+ @notifications.on_excel()
299+ async def handle_excel_comment(context, state, notification):
300+ comment = notification.wpx_comment
301+ if comment:
302+ print(f"Received Excel comment: {comment.comment_id}")
285303 """
286304 return self .on_agent_notification (
287305 ChannelId (channel = "agents" , sub_channel = AgentSubChannel .EXCEL ), ** kwargs
@@ -302,11 +320,13 @@ def on_powerpoint(
302320 A decorator function that registers the handler with the application.
303321
304322 Example:
305- >>> @notifications.on_powerpoint()
306- ... async def handle_powerpoint_comment(context, state, notification):
307- ... comment = notification.wpx_comment
308- ... if comment:
309- ... print(f"Received PowerPoint comment: {comment.comment_id}")
323+ .. code-block:: python
324+
325+ @notifications.on_powerpoint()
326+ async def handle_powerpoint_comment(context, state, notification):
327+ comment = notification.wpx_comment
328+ if comment:
329+ print(f"Received PowerPoint comment: {comment.comment_id}")
310330 """
311331 return self .on_agent_notification (
312332 ChannelId (channel = "agents" , sub_channel = AgentSubChannel .POWERPOINT ), ** kwargs
@@ -327,9 +347,11 @@ def on_lifecycle(
327347 A decorator function that registers the handler with the application.
328348
329349 Example:
330- >>> @notifications.on_lifecycle()
331- ... async def handle_any_lifecycle_event(context, state, notification):
332- ... print(f"Lifecycle event type: {notification.notification_type}")
350+ .. code-block:: python
351+
352+ @notifications.on_lifecycle()
353+ async def handle_any_lifecycle_event(context, state, notification):
354+ print(f"Lifecycle event type: {notification.notification_type}")
333355 """
334356 return self .on_lifecycle_notification ("*" , ** kwargs )
335357
@@ -348,9 +370,11 @@ def on_user_created(
348370 A decorator function that registers the handler with the application.
349371
350372 Example:
351- >>> @notifications.on_user_created()
352- ... async def handle_user_created(context, state, notification):
353- ... print("New agentic user identity created")
373+ .. code-block:: python
374+
375+ @notifications.on_user_created()
376+ async def handle_user_created(context, state, notification):
377+ print("New agentic user identity created")
354378 """
355379 return self .on_lifecycle_notification (AgentLifecycleEvent .USERCREATED , ** kwargs )
356380
@@ -369,9 +393,11 @@ def on_user_workload_onboarding(
369393 A decorator function that registers the handler with the application.
370394
371395 Example:
372- >>> @notifications.on_user_workload_onboarding()
373- ... async def handle_onboarding_update(context, state, notification):
374- ... print("User workload onboarding status updated")
396+ .. code-block:: python
397+
398+ @notifications.on_user_workload_onboarding()
399+ async def handle_onboarding_update(context, state, notification):
400+ print("User workload onboarding status updated")
375401 """
376402 return self .on_lifecycle_notification (
377403 AgentLifecycleEvent .USERWORKLOADONBOARDINGUPDATED , ** kwargs
@@ -392,9 +418,11 @@ def on_user_deleted(
392418 A decorator function that registers the handler with the application.
393419
394420 Example:
395- >>> @notifications.on_user_deleted()
396- ... async def handle_user_deleted(context, state, notification):
397- ... print("Agentic user identity deleted")
421+ .. code-block:: python
422+
423+ @notifications.on_user_deleted()
424+ async def handle_user_deleted(context, state, notification):
425+ print("Agentic user identity deleted")
398426 """
399427 return self .on_lifecycle_notification (AgentLifecycleEvent .USERDELETED , ** kwargs )
400428
0 commit comments