Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

Commit 8a27c69

Browse files
authored
Merge pull request #1413 from microsoft/axsuarez/SupportUpdateAndDeleteFromSkills
Support update and delete from skills
2 parents 30bce78 + f5287da commit 8a27c69

File tree

2 files changed

+268
-62
lines changed

2 files changed

+268
-62
lines changed

libraries/botbuilder-core/botbuilder/core/skills/skill_handler.py

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ async def on_send_to_conversation(
6262
This method allows you to send an activity to the end of a conversation.
6363
6464
This is slightly different from ReplyToActivity().
65-
* SendToConversation(conversationId) - will append the activity to the end
65+
* SendToConversation(conversation_id) - will append the activity to the end
6666
of the conversation according to the timestamp or semantics of the channel.
67-
* ReplyToActivity(conversationId,ActivityId) - adds the activity as a reply
67+
* ReplyToActivity(conversation_id,ActivityId) - adds the activity as a reply
6868
to another activity, if the channel supports it. If the channel does not
6969
support nested replies, ReplyToActivity falls back to SendToConversation.
7070
@@ -97,9 +97,9 @@ async def on_reply_to_activity(
9797
This method allows you to reply to an activity.
9898
9999
This is slightly different from SendToConversation().
100-
* SendToConversation(conversationId) - will append the activity to the end
100+
* SendToConversation(conversation_id) - will append the activity to the end
101101
of the conversation according to the timestamp or semantics of the channel.
102-
* ReplyToActivity(conversationId,ActivityId) - adds the activity as a reply
102+
* ReplyToActivity(conversation_id,ActivityId) - adds the activity as a reply
103103
to another activity, if the channel supports it. If the channel does not
104104
support nested replies, ReplyToActivity falls back to SendToConversation.
105105
@@ -111,6 +111,8 @@ async def on_reply_to_activity(
111111
:type claims_identity: :class:`botframework.connector.auth.ClaimsIdentity`
112112
:param conversation_id:The conversation ID.
113113
:type conversation_id: str
114+
:param activity_id: Activity ID to send.
115+
:type activity_id: str
114116
:param activity: Activity to send.
115117
:type activity: Activity
116118
:return:
@@ -119,13 +121,66 @@ async def on_reply_to_activity(
119121
claims_identity, conversation_id, activity_id, activity,
120122
)
121123

122-
async def _process_activity(
124+
async def on_delete_activity(
125+
self, claims_identity: ClaimsIdentity, conversation_id: str, activity_id: str
126+
):
127+
skill_conversation_reference = await self._get_skill_conversation_reference(
128+
conversation_id
129+
)
130+
131+
async def callback(turn_context: TurnContext):
132+
turn_context.turn_state[
133+
self.SKILL_CONVERSATION_REFERENCE_KEY
134+
] = skill_conversation_reference
135+
await turn_context.delete_activity(activity_id)
136+
137+
await self._adapter.continue_conversation(
138+
skill_conversation_reference.conversation_reference,
139+
callback,
140+
claims_identity=claims_identity,
141+
audience=skill_conversation_reference.oauth_scope,
142+
)
143+
144+
async def on_update_activity(
123145
self,
124146
claims_identity: ClaimsIdentity,
125147
conversation_id: str,
126-
reply_to_activity_id: str,
148+
activity_id: str,
127149
activity: Activity,
128150
) -> ResourceResponse:
151+
skill_conversation_reference = await self._get_skill_conversation_reference(
152+
conversation_id
153+
)
154+
155+
resource_response: ResourceResponse = None
156+
157+
async def callback(turn_context: TurnContext):
158+
nonlocal resource_response
159+
turn_context.turn_state[
160+
self.SKILL_CONVERSATION_REFERENCE_KEY
161+
] = skill_conversation_reference
162+
activity.apply_conversation_reference(
163+
skill_conversation_reference.conversation_reference
164+
)
165+
turn_context.activity.id = activity_id
166+
turn_context.activity.caller_id = (
167+
f"{CallerIdConstants.bot_to_bot_prefix}"
168+
f"{JwtTokenValidation.get_app_id_from_claims(claims_identity.claims)}"
169+
)
170+
resource_response = await turn_context.update_activity(activity)
171+
172+
await self._adapter.continue_conversation(
173+
skill_conversation_reference.conversation_reference,
174+
callback,
175+
claims_identity=claims_identity,
176+
audience=skill_conversation_reference.oauth_scope,
177+
)
178+
179+
return resource_response or ResourceResponse(id=str(uuid4()).replace("-", ""))
180+
181+
async def _get_skill_conversation_reference(
182+
self, conversation_id: str
183+
) -> SkillConversationReference:
129184
# Get the SkillsConversationReference
130185
conversation_reference_result = await self._conversation_id_factory.get_conversation_reference(
131186
conversation_id
@@ -135,11 +190,10 @@ async def _process_activity(
135190
# or a ConversationReference (the old way, but still here for compatibility). If a
136191
# ConversationReference is returned, build a new SkillConversationReference to simplify
137192
# the remainder of this method.
138-
skill_conversation_reference: SkillConversationReference = None
139193
if isinstance(conversation_reference_result, SkillConversationReference):
140-
skill_conversation_reference = conversation_reference_result
194+
skill_conversation_reference: SkillConversationReference = conversation_reference_result
141195
else:
142-
skill_conversation_reference = SkillConversationReference(
196+
skill_conversation_reference: SkillConversationReference = SkillConversationReference(
143197
conversation_reference=conversation_reference_result,
144198
oauth_scope=(
145199
GovernmentConstants.TO_CHANNEL_FROM_BOT_OAUTH_SCOPE
@@ -154,6 +208,19 @@ async def _process_activity(
154208
if not skill_conversation_reference.conversation_reference:
155209
raise KeyError("conversationReference not found")
156210

211+
return skill_conversation_reference
212+
213+
async def _process_activity(
214+
self,
215+
claims_identity: ClaimsIdentity,
216+
conversation_id: str,
217+
reply_to_activity_id: str,
218+
activity: Activity,
219+
) -> ResourceResponse:
220+
skill_conversation_reference = await self._get_skill_conversation_reference(
221+
conversation_id
222+
)
223+
157224
# If an activity is sent, return the ResourceResponse
158225
resource_response: ResourceResponse = None
159226

0 commit comments

Comments
 (0)