Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,6 @@ cython_debug/
# JetBrains Rider
*.sln.iml
.idea/

# vscode
.vscode/
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Import necessary modules
from .activity_handler import ActivityHandler
from .bot import Bot
from .channel_adapter import ChannelAdapter
from .channel_api_handler_protocol import ChannelApiHandlerProtocol
from .channel_service_adapter import ChannelServiceAdapter
from .channel_service_client_factory_base import ChannelServiceClientFactoryBase
from .message_factory import MessageFactory
Expand All @@ -12,6 +14,8 @@
__all__ = [
"ActivityHandler",
"Bot",
"ChannelAdapter",
"ChannelApiHandlerProtocol",
"ChannelServiceAdapter",
"ChannelServiceClientFactoryBase",
"MessageFactory",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from http import HTTPStatus
from pydantic import BaseModel

from microsoft.agents.core import TurnContextProtocol
from microsoft.agents.core.models import (
Activity,
ActivityTypes,
Expand All @@ -16,7 +17,6 @@
)

from .bot import Bot
from .turn_context import TurnContext


class ActivityHandler(Bot):
Expand All @@ -30,7 +30,7 @@ class ActivityHandler(Bot):
"""

async def on_turn(
self, turn_context: TurnContext
self, turn_context: TurnContextProtocol
): # pylint: disable=arguments-differ
"""
Called by the adapter (for example, :class:`BotFrameworkAdapter`) at runtime
Expand Down Expand Up @@ -97,7 +97,7 @@ async def on_turn(
await self.on_unrecognized_activity_type(turn_context)

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

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

async def on_message_delete_activity( # pylint: disable=unused-argument
self, turn_context: TurnContext
self, turn_context: TurnContextProtocol
):
"""
Override this method in a derived class to provide logic specific to activities,
Expand All @@ -138,7 +138,7 @@ async def on_message_delete_activity( # pylint: disable=unused-argument
"""
return

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

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

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

return

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

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

async def on_reactions_removed( # pylint: disable=unused-argument
self, message_reactions: list[MessageReaction], turn_context: TurnContext
self,
message_reactions: list[MessageReaction],
turn_context: TurnContextProtocol,
):
"""
Override this method in a derived class to provide logic for when reactions to a previous activity
Expand All @@ -307,7 +311,7 @@ async def on_reactions_removed( # pylint: disable=unused-argument
"""
return

async def on_event_activity(self, turn_context: TurnContext):
async def on_event_activity(self, turn_context: TurnContextProtocol):
"""
Invoked when an event activity is received from the connector when the base behavior of
:meth:`on_turn()` is used.
Expand Down Expand Up @@ -336,7 +340,7 @@ async def on_event_activity(self, turn_context: TurnContext):
return await self.on_event(turn_context)

async def on_token_response_event( # pylint: disable=unused-argument
self, turn_context: TurnContext
self, turn_context: TurnContextProtocol
):
"""
Invoked when a `tokens/response` event is received when the base behavior of
Expand All @@ -356,7 +360,7 @@ async def on_token_response_event( # pylint: disable=unused-argument
return

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

async def on_end_of_conversation_activity( # pylint: disable=unused-argument
self, turn_context: TurnContext
self, turn_context: TurnContextProtocol
):
"""
Invoked when a conversation end activity is received from the channel.
Expand All @@ -388,7 +392,7 @@ async def on_end_of_conversation_activity( # pylint: disable=unused-argument
return

async def on_typing_activity( # pylint: disable=unused-argument
self, turn_context: TurnContext
self, turn_context: TurnContextProtocol
):
"""
Override this in a derived class to provide logic specific to
Expand All @@ -401,7 +405,7 @@ async def on_typing_activity( # pylint: disable=unused-argument
return

async def on_installation_update( # pylint: disable=unused-argument
self, turn_context: TurnContext
self, turn_context: TurnContextProtocol
):
"""
Override this in a derived class to provide logic specific to
Expand All @@ -418,7 +422,7 @@ async def on_installation_update( # pylint: disable=unused-argument
return

async def on_installation_update_add( # pylint: disable=unused-argument
self, turn_context: TurnContext
self, turn_context: TurnContextProtocol
):
"""
Override this in a derived class to provide logic specific to
Expand All @@ -431,7 +435,7 @@ async def on_installation_update_add( # pylint: disable=unused-argument
return

async def on_installation_update_remove( # pylint: disable=unused-argument
self, turn_context: TurnContext
self, turn_context: TurnContextProtocol
):
"""
Override this in a derived class to provide logic specific to
Expand All @@ -444,7 +448,7 @@ async def on_installation_update_remove( # pylint: disable=unused-argument
return

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

async def on_invoke_activity( # pylint: disable=unused-argument
self, turn_context: TurnContext
self, turn_context: TurnContextProtocol
) -> InvokeResponse | None:
"""
Registers an activity event handler for the _invoke_ event, emitted for every incoming event activity.
Expand Down Expand Up @@ -496,7 +500,7 @@ async def on_invoke_activity( # pylint: disable=unused-argument
return invoke_exception.create_invoke_response()

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

async def on_adaptive_card_invoke(
self, turn_context: TurnContext, invoke_value: AdaptiveCardInvokeValue
self, turn_context: TurnContextProtocol, invoke_value: AdaptiveCardInvokeValue
) -> AdaptiveCardInvokeResponse:
"""
Invoked when the bot is sent an Adaptive Card Action Execute.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

from abc import ABC, abstractmethod
from collections.abc import Callable
from typing import List, Awaitable, Protocol
from typing import List, Awaitable
from microsoft.agents.authentication import ClaimsIdentity
from microsoft.agents.core import ChannelAdapterProtocol
from microsoft.agents.core.models import (
Activity,
ConversationReference,
Expand All @@ -15,7 +17,7 @@
from .middleware_set import MiddlewareSet


class ChannelAdapter(ABC):
class ChannelAdapter(ABC, ChannelAdapterProtocol):
BOT_IDENTITY_KEY = "BotIdentity"
OAUTH_SCOPE_KEY = "Microsoft.Agents.BotBuilder.ChannelAdapter.OAuthScope"
INVOKE_RESPONSE_KEY = "ChannelAdapter.InvokeResponse"
Expand Down Expand Up @@ -104,6 +106,29 @@ async def continue_conversation(
context = TurnContext(self, reference.get_continuation_activity())
return await self.run_pipeline(context, callback)

async def continue_conversation_with_claims(
self,
claims_identity: ClaimsIdentity,
continuation_activity: Activity,
callback: Callable[[TurnContext], Awaitable],
audience: str = None,
):
"""
Sends a proactive message to a conversation. Call this method to proactively send a message to a conversation.
Most channels require a user to initiate a conversation with a bot before the bot can send activities
to the user.

:param claims_identity: A :class:`botframework.connector.auth.ClaimsIdentity` for the conversation.
:type claims_identity: :class:`botframework.connector.auth.ClaimsIdentity`
:param continuation_activity: The activity to send.
:type continuation_activity: :class:`botbuilder
:param callback: The method to call for the resulting bot turn.
:type callback: :class:`typing.Callable`
:param audience: A value signifying the recipient of the proactive message.
:type audience: str
"""
raise NotImplementedError()

async def create_conversation(
self,
bot_app_id: str,
Expand Down
Loading