Skip to content

Commit e7a4c13

Browse files
authored
Users/axsuarez/bot to bot (#12)
* WIP client library * WIP client library - formatting * HttpBotChannel WIP * ConversationIdFactory WIP * WIP * WIP: just missing ConversationIdFactory * WIP: just missing ConversationIdFactory - Formatting * MemoryStorage almost done, id factory pending * Conversation id factory WIP * Bot1 WIP * Bot 1 WIP * Adding route table helper (aiohttp) * Sample WIP * Bot1 multiple connection WIP * Bot2Bot integration WIP * Formatting * B2B serialization error on the way back. Communication successful. * B2B serialization error on the way back. Communication successful. - Formatting * B2B working * B2B style changes and light cleanup * Updated formatting
1 parent 0d51435 commit e7a4c13

100 files changed

Lines changed: 1760 additions & 103 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,6 @@ cython_debug/
122122
# JetBrains Rider
123123
*.sln.iml
124124
.idea/
125+
126+
# vscode
127+
.vscode/

libraries/Botbuilder/microsoft-agents-botbuilder/microsoft/agents/botbuilder/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Import necessary modules
22
from .activity_handler import ActivityHandler
33
from .bot import Bot
4+
from .channel_adapter import ChannelAdapter
5+
from .channel_api_handler_protocol import ChannelApiHandlerProtocol
46
from .channel_service_adapter import ChannelServiceAdapter
57
from .channel_service_client_factory_base import ChannelServiceClientFactoryBase
68
from .message_factory import MessageFactory
@@ -12,6 +14,8 @@
1214
__all__ = [
1315
"ActivityHandler",
1416
"Bot",
17+
"ChannelAdapter",
18+
"ChannelApiHandlerProtocol",
1519
"ChannelServiceAdapter",
1620
"ChannelServiceClientFactoryBase",
1721
"MessageFactory",

libraries/Botbuilder/microsoft-agents-botbuilder/microsoft/agents/botbuilder/activity_handler.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from http import HTTPStatus
55
from pydantic import BaseModel
66

7+
from microsoft.agents.core import TurnContextProtocol
78
from microsoft.agents.core.models import (
89
Activity,
910
ActivityTypes,
@@ -16,7 +17,6 @@
1617
)
1718

1819
from .bot import Bot
19-
from .turn_context import TurnContext
2020

2121

2222
class ActivityHandler(Bot):
@@ -30,7 +30,7 @@ class ActivityHandler(Bot):
3030
"""
3131

3232
async def on_turn(
33-
self, turn_context: TurnContext
33+
self, turn_context: TurnContextProtocol
3434
): # pylint: disable=arguments-differ
3535
"""
3636
Called by the adapter (for example, :class:`BotFrameworkAdapter`) at runtime
@@ -97,7 +97,7 @@ async def on_turn(
9797
await self.on_unrecognized_activity_type(turn_context)
9898

9999
async def on_message_activity( # pylint: disable=unused-argument
100-
self, turn_context: TurnContext
100+
self, turn_context: TurnContextProtocol
101101
):
102102
"""
103103
Override this method in a derived class to provide logic specific to activities,
@@ -111,7 +111,7 @@ async def on_message_activity( # pylint: disable=unused-argument
111111
return
112112

113113
async def on_message_update_activity( # pylint: disable=unused-argument
114-
self, turn_context: TurnContext
114+
self, turn_context: TurnContextProtocol
115115
):
116116
"""
117117
Override this method in a derived class to provide logic specific to activities,
@@ -125,7 +125,7 @@ async def on_message_update_activity( # pylint: disable=unused-argument
125125
return
126126

127127
async def on_message_delete_activity( # pylint: disable=unused-argument
128-
self, turn_context: TurnContext
128+
self, turn_context: TurnContextProtocol
129129
):
130130
"""
131131
Override this method in a derived class to provide logic specific to activities,
@@ -138,7 +138,7 @@ async def on_message_delete_activity( # pylint: disable=unused-argument
138138
"""
139139
return
140140

141-
async def on_conversation_update_activity(self, turn_context: TurnContext):
141+
async def on_conversation_update_activity(self, turn_context: TurnContextProtocol):
142142
"""
143143
Invoked when a conversation update activity is received from the channel when the base behavior of
144144
:meth:`on_turn()` is used.
@@ -176,7 +176,7 @@ async def on_conversation_update_activity(self, turn_context: TurnContext):
176176
return
177177

178178
async def on_members_added_activity(
179-
self, members_added: list[ChannelAccount], turn_context: TurnContext
179+
self, members_added: list[ChannelAccount], turn_context: TurnContextProtocol
180180
): # pylint: disable=unused-argument
181181
"""
182182
Override this method in a derived class to provide logic for when members other than the bot join
@@ -198,7 +198,7 @@ async def on_members_added_activity(
198198
return
199199

200200
async def on_members_removed_activity(
201-
self, members_removed: list[ChannelAccount], turn_context: TurnContext
201+
self, members_removed: list[ChannelAccount], turn_context: TurnContextProtocol
202202
): # pylint: disable=unused-argument
203203
"""
204204
Override this method in a derived class to provide logic for when members other than the bot leave
@@ -220,7 +220,7 @@ async def on_members_removed_activity(
220220

221221
return
222222

223-
async def on_message_reaction_activity(self, turn_context: TurnContext):
223+
async def on_message_reaction_activity(self, turn_context: TurnContextProtocol):
224224
"""
225225
Invoked when an event activity is received from the connector when the base behavior of
226226
:meth:`on_turn()` is used.
@@ -261,7 +261,9 @@ async def on_message_reaction_activity(self, turn_context: TurnContext):
261261
)
262262

263263
async def on_reactions_added( # pylint: disable=unused-argument
264-
self, message_reactions: list[MessageReaction], turn_context: TurnContext
264+
self,
265+
message_reactions: list[MessageReaction],
266+
turn_context: TurnContextProtocol,
265267
):
266268
"""
267269
Override this method in a derived class to provide logic for when reactions to a previous activity
@@ -285,7 +287,9 @@ async def on_reactions_added( # pylint: disable=unused-argument
285287
return
286288

287289
async def on_reactions_removed( # pylint: disable=unused-argument
288-
self, message_reactions: list[MessageReaction], turn_context: TurnContext
290+
self,
291+
message_reactions: list[MessageReaction],
292+
turn_context: TurnContextProtocol,
289293
):
290294
"""
291295
Override this method in a derived class to provide logic for when reactions to a previous activity
@@ -307,7 +311,7 @@ async def on_reactions_removed( # pylint: disable=unused-argument
307311
"""
308312
return
309313

310-
async def on_event_activity(self, turn_context: TurnContext):
314+
async def on_event_activity(self, turn_context: TurnContextProtocol):
311315
"""
312316
Invoked when an event activity is received from the connector when the base behavior of
313317
:meth:`on_turn()` is used.
@@ -336,7 +340,7 @@ async def on_event_activity(self, turn_context: TurnContext):
336340
return await self.on_event(turn_context)
337341

338342
async def on_token_response_event( # pylint: disable=unused-argument
339-
self, turn_context: TurnContext
343+
self, turn_context: TurnContextProtocol
340344
):
341345
"""
342346
Invoked when a `tokens/response` event is received when the base behavior of
@@ -356,7 +360,7 @@ async def on_token_response_event( # pylint: disable=unused-argument
356360
return
357361

358362
async def on_event( # pylint: disable=unused-argument
359-
self, turn_context: TurnContext
363+
self, turn_context: TurnContextProtocol
360364
):
361365
"""
362366
Invoked when an event other than `tokens/response` is received when the base behavior of
@@ -376,7 +380,7 @@ async def on_event( # pylint: disable=unused-argument
376380
return
377381

378382
async def on_end_of_conversation_activity( # pylint: disable=unused-argument
379-
self, turn_context: TurnContext
383+
self, turn_context: TurnContextProtocol
380384
):
381385
"""
382386
Invoked when a conversation end activity is received from the channel.
@@ -388,7 +392,7 @@ async def on_end_of_conversation_activity( # pylint: disable=unused-argument
388392
return
389393

390394
async def on_typing_activity( # pylint: disable=unused-argument
391-
self, turn_context: TurnContext
395+
self, turn_context: TurnContextProtocol
392396
):
393397
"""
394398
Override this in a derived class to provide logic specific to
@@ -401,7 +405,7 @@ async def on_typing_activity( # pylint: disable=unused-argument
401405
return
402406

403407
async def on_installation_update( # pylint: disable=unused-argument
404-
self, turn_context: TurnContext
408+
self, turn_context: TurnContextProtocol
405409
):
406410
"""
407411
Override this in a derived class to provide logic specific to
@@ -418,7 +422,7 @@ async def on_installation_update( # pylint: disable=unused-argument
418422
return
419423

420424
async def on_installation_update_add( # pylint: disable=unused-argument
421-
self, turn_context: TurnContext
425+
self, turn_context: TurnContextProtocol
422426
):
423427
"""
424428
Override this in a derived class to provide logic specific to
@@ -431,7 +435,7 @@ async def on_installation_update_add( # pylint: disable=unused-argument
431435
return
432436

433437
async def on_installation_update_remove( # pylint: disable=unused-argument
434-
self, turn_context: TurnContext
438+
self, turn_context: TurnContextProtocol
435439
):
436440
"""
437441
Override this in a derived class to provide logic specific to
@@ -444,7 +448,7 @@ async def on_installation_update_remove( # pylint: disable=unused-argument
444448
return
445449

446450
async def on_unrecognized_activity_type( # pylint: disable=unused-argument
447-
self, turn_context: TurnContext
451+
self, turn_context: TurnContextProtocol
448452
):
449453
"""
450454
Invoked when an activity other than a message, conversation update, or event is received when the base
@@ -463,7 +467,7 @@ async def on_unrecognized_activity_type( # pylint: disable=unused-argument
463467
return
464468

465469
async def on_invoke_activity( # pylint: disable=unused-argument
466-
self, turn_context: TurnContext
470+
self, turn_context: TurnContextProtocol
467471
) -> InvokeResponse | None:
468472
"""
469473
Registers an activity event handler for the _invoke_ event, emitted for every incoming event activity.
@@ -496,7 +500,7 @@ async def on_invoke_activity( # pylint: disable=unused-argument
496500
return invoke_exception.create_invoke_response()
497501

498502
async def on_sign_in_invoke( # pylint: disable=unused-argument
499-
self, turn_context: TurnContext
503+
self, turn_context: TurnContextProtocol
500504
):
501505
"""
502506
Invoked when a signin/verifyState or signin/tokenExchange event is received when the base behavior of
@@ -512,7 +516,7 @@ async def on_sign_in_invoke( # pylint: disable=unused-argument
512516
raise _InvokeResponseException(HTTPStatus.NOT_IMPLEMENTED)
513517

514518
async def on_adaptive_card_invoke(
515-
self, turn_context: TurnContext, invoke_value: AdaptiveCardInvokeValue
519+
self, turn_context: TurnContextProtocol, invoke_value: AdaptiveCardInvokeValue
516520
) -> AdaptiveCardInvokeResponse:
517521
"""
518522
Invoked when the bot is sent an Adaptive Card Action Execute.

libraries/Botbuilder/microsoft-agents-botbuilder/microsoft/agents/botbuilder/channel_adapter.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
from abc import ABC, abstractmethod
55
from collections.abc import Callable
6-
from typing import List, Awaitable, Protocol
6+
from typing import List, Awaitable
7+
from microsoft.agents.authentication import ClaimsIdentity
8+
from microsoft.agents.core import ChannelAdapterProtocol
79
from microsoft.agents.core.models import (
810
Activity,
911
ConversationReference,
@@ -15,7 +17,7 @@
1517
from .middleware_set import MiddlewareSet
1618

1719

18-
class ChannelAdapter(ABC):
20+
class ChannelAdapter(ABC, ChannelAdapterProtocol):
1921
BOT_IDENTITY_KEY = "BotIdentity"
2022
OAUTH_SCOPE_KEY = "Microsoft.Agents.BotBuilder.ChannelAdapter.OAuthScope"
2123
INVOKE_RESPONSE_KEY = "ChannelAdapter.InvokeResponse"
@@ -104,6 +106,29 @@ async def continue_conversation(
104106
context = TurnContext(self, reference.get_continuation_activity())
105107
return await self.run_pipeline(context, callback)
106108

109+
async def continue_conversation_with_claims(
110+
self,
111+
claims_identity: ClaimsIdentity,
112+
continuation_activity: Activity,
113+
callback: Callable[[TurnContext], Awaitable],
114+
audience: str = None,
115+
):
116+
"""
117+
Sends a proactive message to a conversation. Call this method to proactively send a message to a conversation.
118+
Most channels require a user to initiate a conversation with a bot before the bot can send activities
119+
to the user.
120+
121+
:param claims_identity: A :class:`botframework.connector.auth.ClaimsIdentity` for the conversation.
122+
:type claims_identity: :class:`botframework.connector.auth.ClaimsIdentity`
123+
:param continuation_activity: The activity to send.
124+
:type continuation_activity: :class:`botbuilder
125+
:param callback: The method to call for the resulting bot turn.
126+
:type callback: :class:`typing.Callable`
127+
:param audience: A value signifying the recipient of the proactive message.
128+
:type audience: str
129+
"""
130+
raise NotImplementedError()
131+
107132
async def create_conversation(
108133
self,
109134
bot_app_id: str,

0 commit comments

Comments
 (0)