0
# Activity Types and Enums
1
2
Comprehensive enumeration types defining activity types, role types, input hints, action types, and other standardized values used throughout the Bot Framework for consistent communication and behavior.
3
4
## Core Activity Types
5
6
### ActivityTypes Enum
7
8
Defines the type of activity being sent or received in Bot Framework conversations.
9
10
```python { .api }
11
class ActivityTypes(str, Enum):
12
message = "message"
13
conversation_update = "conversationUpdate"
14
typing = "typing"
15
end_of_conversation = "endOfConversation"
16
event = "event"
17
invoke = "invoke"
18
invoke_response = "invokeResponse"
19
delete_user_data = "deleteUserData"
20
message_update = "messageUpdate"
21
message_delete = "messageDelete"
22
installation_update = "installationUpdate"
23
message_reaction = "messageReaction"
24
suggestion = "suggestion"
25
trace = "trace"
26
handoff = "handoff"
27
command = "command"
28
command_result = "commandResult"
29
contact_relation_update = "contactRelationUpdate"
30
```
31
32
**Common Activity Types:**
33
34
```python
35
from botbuilder.schema import ActivityTypes, Activity
36
37
# Text message from user to bot
38
message_activity = Activity(
39
type=ActivityTypes.message,
40
text="Hello bot!"
41
)
42
43
# Bot typing indicator
44
typing_activity = Activity(
45
type=ActivityTypes.typing
46
)
47
48
# User joined conversation
49
conversation_update = Activity(
50
type=ActivityTypes.conversation_update,
51
members_added=[channel_account]
52
)
53
54
# End conversation
55
end_conversation = Activity(
56
type=ActivityTypes.end_of_conversation,
57
code="userCancelled"
58
)
59
```
60
61
### Role Types
62
63
Identifies the role of the participant in the conversation.
64
65
```python { .api }
66
class RoleTypes(str, Enum):
67
user = "user"
68
bot = "bot"
69
skill = "skill"
70
```
71
72
```python
73
from botbuilder.schema import RoleTypes, ChannelAccount
74
75
user_account = ChannelAccount(
76
id="user123",
77
name="John Doe",
78
role=RoleTypes.user
79
)
80
81
bot_account = ChannelAccount(
82
id="bot456",
83
name="My Bot",
84
role=RoleTypes.bot
85
)
86
```
87
88
## Message and Text Formatting
89
90
### Text Format Types
91
92
Specifies the format of text content in messages.
93
94
```python { .api }
95
class TextFormatTypes(str, Enum):
96
markdown = "markdown"
97
plain = "plain"
98
xml = "xml"
99
```
100
101
```python
102
from botbuilder.schema import Activity, ActivityTypes, TextFormatTypes
103
104
# Plain text message
105
plain_message = Activity(
106
type=ActivityTypes.message,
107
text="This is plain text",
108
text_format=TextFormatTypes.plain
109
)
110
111
# Markdown formatted message
112
markdown_message = Activity(
113
type=ActivityTypes.message,
114
text="**Bold text** and *italic text*",
115
text_format=TextFormatTypes.markdown
116
)
117
118
# SSML for speech
119
speech_message = Activity(
120
type=ActivityTypes.message,
121
text="Hello there!",
122
speak="<speak>Hello <emphasis level='strong'>there</emphasis>!</speak>",
123
text_format=TextFormatTypes.xml
124
)
125
```
126
127
### Input Hints
128
129
Provides hints about whether the bot is expecting input from the user.
130
131
```python { .api }
132
class InputHints(str, Enum):
133
accepting_input = "acceptingInput"
134
ignoring_input = "ignoringInput"
135
expecting_input = "expectingInput"
136
```
137
138
```python
139
from botbuilder.schema import Activity, ActivityTypes, InputHints
140
141
# Bot is expecting a response
142
question = Activity(
143
type=ActivityTypes.message,
144
text="What's your name?",
145
input_hint=InputHints.expecting_input
146
)
147
148
# Bot is not expecting input (informational message)
149
info = Activity(
150
type=ActivityTypes.message,
151
text="Processing your request...",
152
input_hint=InputHints.ignoring_input
153
)
154
155
# Bot can accept input but doesn't require it
156
optional = Activity(
157
type=ActivityTypes.message,
158
text="I'm here if you need help!",
159
input_hint=InputHints.accepting_input
160
)
161
```
162
163
## Action and Interaction Types
164
165
### Action Types
166
167
Defines types of actions that can be performed with buttons and cards.
168
169
```python { .api }
170
class ActionTypes(str, Enum):
171
open_url = "openUrl"
172
im_back = "imBack"
173
post_back = "postBack"
174
play_audio = "playAudio"
175
play_video = "playVideo"
176
show_image = "showImage"
177
download_file = "downloadFile"
178
signin = "signin"
179
call = "call"
180
message_back = "messageBack"
181
```
182
183
```python
184
from botbuilder.schema import CardAction, ActionTypes
185
186
actions = [
187
CardAction(type=ActionTypes.open_url, title="Visit Website", value="https://example.com"),
188
CardAction(type=ActionTypes.im_back, title="Say Hello", value="hello"),
189
CardAction(type=ActionTypes.post_back, title="Submit", value="submit_data"),
190
CardAction(type=ActionTypes.signin, title="Sign In", value="signin_url"),
191
CardAction(type=ActionTypes.call, title="Call Support", value="tel:+1234567890")
192
]
193
```
194
195
### Message Reaction Types
196
197
Types of reactions that can be applied to messages.
198
199
```python { .api }
200
class MessageReactionTypes(str, Enum):
201
like = "like"
202
plus_one = "+1"
203
```
204
205
```python
206
from botbuilder.schema import MessageReaction, MessageReactionTypes
207
208
reactions = [
209
MessageReaction(type=MessageReactionTypes.like),
210
MessageReaction(type=MessageReactionTypes.plus_one)
211
]
212
```
213
214
## Layout and Presentation
215
216
### Attachment Layout Types
217
218
Specifies how multiple attachments should be displayed.
219
220
```python { .api }
221
class AttachmentLayoutTypes(str, Enum):
222
list = "list"
223
carousel = "carousel"
224
```
225
226
```python
227
from botbuilder.schema import Activity, ActivityTypes, AttachmentLayoutTypes
228
229
# Cards displayed in a carousel
230
carousel_activity = Activity(
231
type=ActivityTypes.message,
232
attachment_layout=AttachmentLayoutTypes.carousel,
233
attachments=[card1, card2, card3]
234
)
235
236
# Cards displayed in a vertical list
237
list_activity = Activity(
238
type=ActivityTypes.message,
239
attachment_layout=AttachmentLayoutTypes.list,
240
attachments=[card1, card2, card3]
241
)
242
```
243
244
### Activity Importance
245
246
Indicates the importance level of an activity.
247
248
```python { .api }
249
class ActivityImportance(str, Enum):
250
low = "low"
251
normal = "normal"
252
high = "high"
253
```
254
255
```python
256
from botbuilder.schema import Activity, ActivityTypes, ActivityImportance
257
258
# High priority alert
259
alert = Activity(
260
type=ActivityTypes.message,
261
text="URGENT: System maintenance in 5 minutes",
262
importance=ActivityImportance.high
263
)
264
265
# Low priority informational message
266
info = Activity(
267
type=ActivityTypes.message,
268
text="Tip: You can ask me for help anytime",
269
importance=ActivityImportance.low
270
)
271
```
272
273
## Conversation Control
274
275
### End of Conversation Codes
276
277
Codes indicating why a conversation ended.
278
279
```python { .api }
280
class EndOfConversationCodes(str, Enum):
281
unknown = "unknown"
282
completed_successfully = "completedSuccessfully"
283
user_cancelled = "userCancelled"
284
bot_timed_out = "botTimedOut"
285
bot_issued_invalid_message = "botIssuedInvalidMessage"
286
channel_failed = "channelFailed"
287
```
288
289
```python
290
from botbuilder.schema import Activity, ActivityTypes, EndOfConversationCodes
291
292
# Successful completion
293
success_end = Activity(
294
type=ActivityTypes.end_of_conversation,
295
code=EndOfConversationCodes.completed_successfully,
296
text="Task completed successfully!"
297
)
298
299
# User cancelled
300
cancelled_end = Activity(
301
type=ActivityTypes.end_of_conversation,
302
code=EndOfConversationCodes.user_cancelled,
303
text="Operation cancelled by user"
304
)
305
```
306
307
### Delivery Modes
308
309
Specifies how activities should be delivered.
310
311
```python { .api }
312
class DeliveryModes(str, Enum):
313
normal = "normal"
314
notification = "notification"
315
expect_replies = "expectReplies"
316
ephemeral = "ephemeral"
317
```
318
319
```python
320
from botbuilder.schema import Activity, ActivityTypes, DeliveryModes
321
322
# Push notification
323
notification = Activity(
324
type=ActivityTypes.message,
325
text="You have a new message",
326
delivery_mode=DeliveryModes.notification
327
)
328
329
# Ephemeral message (not stored in history)
330
temp_message = Activity(
331
type=ActivityTypes.message,
332
text="This message will disappear",
333
delivery_mode=DeliveryModes.ephemeral
334
)
335
```
336
337
## Update and Installation Events
338
339
### Contact Relation Update Action Types
340
341
Actions for contact relationship changes.
342
343
```python { .api }
344
class ContactRelationUpdateActionTypes(str, Enum):
345
add = "add"
346
remove = "remove"
347
```
348
349
```python
350
from botbuilder.schema import Activity, ActivityTypes, ContactRelationUpdateActionTypes
351
352
contact_added = Activity(
353
type=ActivityTypes.contact_relation_update,
354
action=ContactRelationUpdateActionTypes.add,
355
from_property=channel_account
356
)
357
```
358
359
### Installation Update Action Types
360
361
Actions for bot installation changes.
362
363
```python { .api }
364
class InstallationUpdateActionTypes(str, Enum):
365
add = "add"
366
remove = "remove"
367
```
368
369
```python
370
from botbuilder.schema import Activity, ActivityTypes, InstallationUpdateActionTypes
371
372
bot_installed = Activity(
373
type=ActivityTypes.installation_update,
374
action=InstallationUpdateActionTypes.add
375
)
376
377
bot_removed = Activity(
378
type=ActivityTypes.installation_update,
379
action=InstallationUpdateActionTypes.remove
380
)
381
```
382
383
## Semantic Actions
384
385
### Semantic Action States
386
387
States for programmatic actions.
388
389
```python { .api }
390
class SemanticActionStates(str, Enum):
391
start = "start"
392
continue = "continue"
393
done = "done"
394
```
395
396
```python
397
from botbuilder.schema import SemanticAction, SemanticActionStates
398
399
action = SemanticAction(
400
id="booking_action",
401
state=SemanticActionStates.start,
402
entities={"date": "2023-12-25", "guests": 4}
403
)
404
```
405
406
## Activity Event Names
407
408
### Standard Event Names
409
410
Predefined event names for system activities.
411
412
```python { .api }
413
class ActivityEventNames(str, Enum):
414
continue_conversation = "ContinueConversation"
415
create_conversation = "CreateConversation"
416
```
417
418
```python
419
from botbuilder.schema import Activity, ActivityTypes, ActivityEventNames
420
421
continue_event = Activity(
422
type=ActivityTypes.event,
423
name=ActivityEventNames.continue_conversation
424
)
425
```
426
427
## Usage Patterns
428
429
### Activity Type Detection
430
431
```python
432
from botbuilder.schema import ActivityTypes
433
434
def handle_activity(activity):
435
"""Route activity based on type"""
436
if activity.type == ActivityTypes.message:
437
return handle_message(activity)
438
elif activity.type == ActivityTypes.conversation_update:
439
return handle_members_added(activity)
440
elif activity.type == ActivityTypes.typing:
441
return handle_typing(activity)
442
elif activity.type == ActivityTypes.end_of_conversation:
443
return handle_conversation_end(activity)
444
else:
445
return handle_unknown_activity(activity)
446
```
447
448
### Enum Validation
449
450
```python
451
from botbuilder.schema import ActivityTypes, RoleTypes
452
453
def validate_activity(activity):
454
"""Validate activity has proper enum values"""
455
valid_types = [t.value for t in ActivityTypes]
456
if activity.type not in valid_types:
457
raise ValueError(f"Invalid activity type: {activity.type}")
458
459
if activity.from_property and activity.from_property.role:
460
valid_roles = [r.value for r in RoleTypes]
461
if activity.from_property.role not in valid_roles:
462
raise ValueError(f"Invalid role type: {activity.from_property.role}")
463
```
464
465
### Conditional Responses
466
467
```python
468
from botbuilder.schema import InputHints, TextFormatTypes
469
470
def create_response(text: str, expects_input: bool = False, use_markdown: bool = False):
471
"""Create activity with appropriate hints and formatting"""
472
return Activity(
473
type=ActivityTypes.message,
474
text=text,
475
text_format=TextFormatTypes.markdown if use_markdown else TextFormatTypes.plain,
476
input_hint=InputHints.expecting_input if expects_input else InputHints.accepting_input
477
)
478
```
479
480
## Constants Integration
481
482
The enums work together with constants classes for complete Bot Framework integration:
483
484
```python
485
from botbuilder.schema import (
486
ActivityTypes, SignInConstants, CallerIdConstants,
487
SpeechConstants
488
)
489
490
# Event handling with constants
491
if activity.type == ActivityTypes.event:
492
if activity.name == SignInConstants.token_response_event_name:
493
# Handle token response
494
pass
495
elif activity.name == SignInConstants.verify_state_operation_name:
496
# Handle state verification
497
pass
498
499
# Channel identification
500
if caller_id == CallerIdConstants.public_azure_channel:
501
# Handle Azure channel specific logic
502
pass
503
504
# Speech handling
505
if not activity.speak:
506
activity.speak = SpeechConstants.EMPTY_SPEAK_TAG
507
```