6
6
from botbuilder .core .turn_context import TurnContext
7
7
from botbuilder .core import ActivityHandler , InvokeResponse , BotFrameworkAdapter
8
8
from botbuilder .schema .teams import (
9
+ AppBasedLinkQuery ,
9
10
TeamInfo ,
10
11
ChannelInfo ,
12
+ FileConsentCardResponse ,
11
13
TeamsChannelData ,
12
14
TeamsChannelAccount ,
15
+ MessagingExtensionAction ,
16
+ MessagingExtensionQuery ,
17
+ O365ConnectorCardActionQuery ,
18
+ TaskModuleRequest ,
13
19
)
14
20
from botframework .connector import Channels
15
21
@@ -55,26 +61,28 @@ async def on_invoke_activity(self, turn_context: TurnContext):
55
61
56
62
if turn_context .activity .name == "fileConsent/invoke" :
57
63
return await self .on_teams_file_consent (
58
- turn_context , turn_context .activity .value
64
+ turn_context , FileConsentCardResponse ( ** turn_context .activity .value )
59
65
)
60
66
61
67
if turn_context .activity .name == "actionableMessage/executeAction" :
62
68
await self .on_teams_o365_connector_card_action (
63
- turn_context , turn_context .activity .value
69
+ turn_context ,
70
+ O365ConnectorCardActionQuery (** turn_context .activity .value ),
64
71
)
65
72
return self ._create_invoke_response ()
66
73
67
74
if turn_context .activity .name == "composeExtension/queryLink" :
68
75
return self ._create_invoke_response (
69
76
await self .on_teams_app_based_link_query (
70
- turn_context , turn_context .activity .value
77
+ turn_context , AppBasedLinkQuery ( ** turn_context .activity .value )
71
78
)
72
79
)
73
80
74
81
if turn_context .activity .name == "composeExtension/query" :
75
82
return self ._create_invoke_response (
76
83
await self .on_teams_messaging_extension_query (
77
- turn_context , turn_context .activity .value
84
+ turn_context ,
85
+ MessagingExtensionQuery (** turn_context .activity .value ),
78
86
)
79
87
)
80
88
@@ -88,21 +96,24 @@ async def on_invoke_activity(self, turn_context: TurnContext):
88
96
if turn_context .activity .name == "composeExtension/submitAction" :
89
97
return self ._create_invoke_response (
90
98
await self .on_teams_messaging_extension_submit_action_dispatch (
91
- turn_context , turn_context .activity .value
99
+ turn_context ,
100
+ MessagingExtensionAction (** turn_context .activity .value ),
92
101
)
93
102
)
94
103
95
104
if turn_context .activity .name == "composeExtension/fetchTask" :
96
105
return self ._create_invoke_response (
97
106
await self .on_teams_messaging_extension_fetch_task (
98
- turn_context , turn_context .activity .value
107
+ turn_context ,
108
+ MessagingExtensionAction (** turn_context .activity .value ),
99
109
)
100
110
)
101
111
102
112
if turn_context .activity .name == "composeExtension/querySettingUrl" :
103
113
return self ._create_invoke_response (
104
114
await self .on_teams_messaging_extension_configuration_query_settings_url (
105
- turn_context , turn_context .activity .value
115
+ turn_context ,
116
+ MessagingExtensionQuery (** turn_context .activity .value ),
106
117
)
107
118
)
108
119
@@ -121,14 +132,14 @@ async def on_invoke_activity(self, turn_context: TurnContext):
121
132
if turn_context .activity .name == "task/fetch" :
122
133
return self ._create_invoke_response (
123
134
await self .on_teams_task_module_fetch (
124
- turn_context , turn_context .activity .value
135
+ turn_context , TaskModuleRequest ( ** turn_context .activity .value )
125
136
)
126
137
)
127
138
128
139
if turn_context .activity .name == "task/submit" :
129
140
return self ._create_invoke_response (
130
141
await self .on_teams_task_module_submit (
131
- turn_context , turn_context .activity .value
142
+ turn_context , TaskModuleRequest ( ** turn_context .activity .value )
132
143
)
133
144
)
134
145
@@ -143,7 +154,9 @@ async def on_teams_signin_verify_state(self, turn_context: TurnContext):
143
154
raise _InvokeResponseException (status_code = HTTPStatus .NOT_IMPLEMENTED )
144
155
145
156
async def on_teams_file_consent (
146
- self , turn_context : TurnContext , file_consent_card_response
157
+ self ,
158
+ turn_context : TurnContext ,
159
+ file_consent_card_response : FileConsentCardResponse ,
147
160
):
148
161
if file_consent_card_response .action == "accept" :
149
162
await self .on_teams_file_consent_accept_activity (
@@ -163,27 +176,31 @@ async def on_teams_file_consent(
163
176
)
164
177
165
178
async def on_teams_file_consent_accept_activity ( # pylint: disable=unused-argument
166
- self , turn_context : TurnContext , file_consent_card_response
179
+ self ,
180
+ turn_context : TurnContext ,
181
+ file_consent_card_response : FileConsentCardResponse ,
167
182
):
168
183
raise _InvokeResponseException (status_code = HTTPStatus .NOT_IMPLEMENTED )
169
184
170
185
async def on_teams_file_consent_decline_activity ( # pylint: disable=unused-argument
171
- self , turn_context : TurnContext , file_consent_card_response
186
+ self ,
187
+ turn_context : TurnContext ,
188
+ file_consent_card_response : FileConsentCardResponse ,
172
189
):
173
190
raise _InvokeResponseException (status_code = HTTPStatus .NOT_IMPLEMENTED )
174
191
175
192
async def on_teams_o365_connector_card_action ( # pylint: disable=unused-argument
176
- self , turn_context : TurnContext , query
193
+ self , turn_context : TurnContext , query : O365ConnectorCardActionQuery
177
194
):
178
195
raise _InvokeResponseException (status_code = HTTPStatus .NOT_IMPLEMENTED )
179
196
180
197
async def on_teams_app_based_link_query ( # pylint: disable=unused-argument
181
- self , turn_context : TurnContext , query
198
+ self , turn_context : TurnContext , query : AppBasedLinkQuery
182
199
):
183
200
raise _InvokeResponseException (status_code = HTTPStatus .NOT_IMPLEMENTED )
184
201
185
202
async def on_teams_messaging_extension_query ( # pylint: disable=unused-argument
186
- self , turn_context : TurnContext , query
203
+ self , turn_context : TurnContext , query : MessagingExtensionQuery
187
204
):
188
205
raise _InvokeResponseException (status_code = HTTPStatus .NOT_IMPLEMENTED )
189
206
@@ -193,9 +210,9 @@ async def on_teams_messaging_extension_select_item( # pylint: disable=unused-ar
193
210
raise _InvokeResponseException (status_code = HTTPStatus .NOT_IMPLEMENTED )
194
211
195
212
async def on_teams_messaging_extension_submit_action_dispatch (
196
- self , turn_context : TurnContext , action
213
+ self , turn_context : TurnContext , action : MessagingExtensionAction
197
214
):
198
- if not action :
215
+ if not action . bot_message_preview_action :
199
216
return await self .on_teams_messaging_extension_submit_action_activity (
200
217
turn_context , action
201
218
)
@@ -226,17 +243,17 @@ async def on_teams_messaging_extension_bot_message_send_activity( # pylint: dis
226
243
raise _InvokeResponseException (status_code = HTTPStatus .NOT_IMPLEMENTED )
227
244
228
245
async def on_teams_messaging_extension_submit_action_activity ( # pylint: disable=unused-argument
229
- self , turn_context : TurnContext , action
246
+ self , turn_context : TurnContext , action : MessagingExtensionAction
230
247
):
231
248
raise _InvokeResponseException (status_code = HTTPStatus .NOT_IMPLEMENTED )
232
249
233
250
async def on_teams_messaging_extension_fetch_task ( # pylint: disable=unused-argument
234
- self , turn_context : TurnContext , task_module_request
251
+ self , turn_context : TurnContext , action : MessagingExtensionAction
235
252
):
236
253
raise _InvokeResponseException (status_code = HTTPStatus .NOT_IMPLEMENTED )
237
254
238
255
async def on_teams_messaging_extension_configuration_query_settings_url ( # pylint: disable=unused-argument
239
- self , turn_context : TurnContext , query
256
+ self , turn_context : TurnContext , query : MessagingExtensionQuery
240
257
):
241
258
raise _InvokeResponseException (status_code = HTTPStatus .NOT_IMPLEMENTED )
242
259
@@ -251,19 +268,19 @@ async def on_teams_messaging_extension_card_button_clicked( # pylint: disable=u
251
268
raise _InvokeResponseException (status_code = HTTPStatus .NOT_IMPLEMENTED )
252
269
253
270
async def on_teams_task_module_fetch ( # pylint: disable=unused-argument
254
- self , turn_context : TurnContext , task_module_request
271
+ self , turn_context : TurnContext , task_module_request : TaskModuleRequest
255
272
):
256
273
raise _InvokeResponseException (status_code = HTTPStatus .NOT_IMPLEMENTED )
257
274
258
275
async def on_teams_task_module_submit ( # pylint: disable=unused-argument
259
- self , turn_context : TurnContext , task_module_request
276
+ self , turn_context : TurnContext , task_module_request : TaskModuleRequest
260
277
):
261
278
raise _InvokeResponseException (status_code = HTTPStatus .NOT_IMPLEMENTED )
262
279
263
280
async def on_conversation_update_activity (self , turn_context : TurnContext ):
281
+
264
282
if turn_context .activity .channel_id == Channels .ms_teams :
265
283
channel_data = TeamsChannelData (** turn_context .activity .channel_data )
266
-
267
284
if turn_context .activity .members_added :
268
285
return await self .on_teams_members_added_dispatch_activity (
269
286
turn_context .activity .members_added , channel_data .team , turn_context
@@ -279,7 +296,9 @@ async def on_conversation_update_activity(self, turn_context: TurnContext):
279
296
if channel_data :
280
297
if channel_data .event_type == "channelCreated" :
281
298
return await self .on_teams_channel_created_activity (
282
- channel_data .channel , channel_data .team , turn_context
299
+ ChannelInfo (** channel_data .channel ),
300
+ channel_data .team ,
301
+ turn_context ,
283
302
)
284
303
if channel_data .event_type == "channelDeleted" :
285
304
return await self .on_teams_channel_deleted_activity (
@@ -337,17 +356,26 @@ async def on_teams_members_added_dispatch_activity( # pylint: disable=unused-ar
337
356
338
357
return await self.on_teams_members_added_activity(teams_members_added, team_info, turn_context)
339
358
"""
359
+ team_accounts_added = []
340
360
for member in members_added :
341
361
new_account_json = member .serialize ()
342
- del new_account_json ["additional_properties" ]
362
+ if "additional_properties" in new_account_json :
363
+ del new_account_json ["additional_properties" ]
343
364
member = TeamsChannelAccount (** new_account_json )
344
- return await self .on_teams_members_added_activity (members_added , turn_context )
365
+ team_accounts_added .append (member )
366
+ return await self .on_teams_members_added_activity (
367
+ team_accounts_added , turn_context
368
+ )
345
369
346
370
async def on_teams_members_added_activity (
347
371
self , teams_members_added : [TeamsChannelAccount ], turn_context : TurnContext
348
372
):
349
- teams_members_added = [ChannelAccount (member ) for member in teams_members_added ]
350
- return super ().on_members_added_activity (teams_members_added , turn_context )
373
+ teams_members_added = [
374
+ ChannelAccount (** member .serialize ()) for member in teams_members_added
375
+ ]
376
+ return await super ().on_members_added_activity (
377
+ teams_members_added , turn_context
378
+ )
351
379
352
380
async def on_teams_members_removed_dispatch_activity ( # pylint: disable=unused-argument
353
381
self ,
@@ -358,7 +386,8 @@ async def on_teams_members_removed_dispatch_activity( # pylint: disable=unused-
358
386
teams_members_removed = []
359
387
for member in members_removed :
360
388
new_account_json = member .serialize ()
361
- del new_account_json ["additional_properties" ]
389
+ if "additional_properties" in new_account_json :
390
+ del new_account_json ["additional_properties" ]
362
391
teams_members_removed .append (TeamsChannelAccount (** new_account_json ))
363
392
364
393
return await self .on_teams_members_removed_activity (
@@ -368,8 +397,10 @@ async def on_teams_members_removed_dispatch_activity( # pylint: disable=unused-
368
397
async def on_teams_members_removed_activity (
369
398
self , teams_members_removed : [TeamsChannelAccount ], turn_context : TurnContext
370
399
):
371
- members_removed = [ChannelAccount (member ) for member in teams_members_removed ]
372
- return super ().on_members_removed_activity (members_removed , turn_context )
400
+ members_removed = [
401
+ ChannelAccount (** member .serialize ()) for member in teams_members_removed
402
+ ]
403
+ return await super ().on_members_removed_activity (members_removed , turn_context )
373
404
374
405
async def on_teams_channel_deleted_activity ( # pylint: disable=unused-argument
375
406
self , channel_info : ChannelInfo , team_info : TeamInfo , turn_context : TurnContext
0 commit comments