-
Notifications
You must be signed in to change notification settings - Fork 295
Port: feat: Support for SharePoint (Viva) Adaptive Card Extension #2201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gandiddi
wants to merge
5
commits into
main
Choose a base branch
from
v-gandiddi/SharePoint-ACE-API
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
603e8bb
Support for SharePoint (Viva) Adaptive Card Extension
gandiddi 937fc0a
Merge branch 'main' into v-gandiddi/SharePoint-ACE-API
gandiddi 906c5f0
Merge branch 'main' into v-gandiddi/SharePoint-ACE-API
gandiddi f8f2c4a
remove print statement
gandiddi 3d841e1
Merge branch 'v-gandiddi/SharePoint-ACE-API' of https://github.com/Mi…
gandiddi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
libraries/botbuilder-core/botbuilder/core/sharepoint/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# -------------------------------------------------------------------------- | ||
|
||
from .sharepoint_activity_handler import SharePointActivityHandler | ||
|
||
__all__ = ["SharePointActivityHandler"] |
179 changes: 179 additions & 0 deletions
179
libraries/botbuilder-core/botbuilder/core/sharepoint/sharepoint_activity_handler.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
# pylint: disable=too-many-lines | ||
|
||
from http import HTTPStatus | ||
from botbuilder.core import ActivityHandler, InvokeResponse | ||
from botbuilder.core.activity_handler import _InvokeResponseException | ||
from botbuilder.core.turn_context import TurnContext | ||
from botbuilder.schema.sharepoint import ( | ||
AceRequest, | ||
BaseHandleActionResponse, | ||
CardViewResponse, | ||
GetPropertyPaneConfigurationResponse, | ||
QuickViewHandleActionResponse, | ||
QuickViewResponse, | ||
) | ||
from ..serializer_helper import deserializer_helper | ||
|
||
|
||
class SharePointActivityHandler(ActivityHandler): | ||
""" | ||
The SharePointActivityHandler is derived from ActivityHandler. It adds support for | ||
SharePoint-specific events and interactions. | ||
""" | ||
|
||
async def on_invoke_activity(self, turn_context: TurnContext) -> InvokeResponse: | ||
""" | ||
Invoked when an invoke activity is received from the connector. | ||
Invoke activities can be used to communicate many different things. | ||
|
||
:param turn_context: A context object for this turn. | ||
|
||
:returns: An InvokeResponse that represents the work queued to execute. | ||
|
||
.. remarks:: | ||
Invoke activities communicate programmatic commands from a client or channel to a bot. | ||
The meaning of an invoke activity is defined by the "invoke_activity.name" property, | ||
which is meaningful within the scope of a channel. | ||
""" | ||
try: | ||
if not turn_context.activity.name: | ||
raise NotImplementedError() | ||
|
||
if turn_context.activity.name == "cardExtension/getCardView": | ||
print("Printing AceReq", turn_context.activity.value) | ||
return self._create_invoke_response( | ||
await self.on_sharepoint_task_get_card_view( | ||
turn_context, | ||
deserializer_helper(AceRequest, turn_context.activity.value), | ||
) | ||
) | ||
|
||
if turn_context.activity.name == "cardExtension/getQuickView": | ||
return self._create_invoke_response( | ||
await self.on_sharepoint_task_get_quick_view( | ||
turn_context, | ||
deserializer_helper(AceRequest, turn_context.activity.value), | ||
) | ||
) | ||
|
||
if ( | ||
turn_context.activity.name | ||
== "cardExtension/getPropertyPaneConfiguration" | ||
): | ||
return self._create_invoke_response( | ||
await self.on_sharepoint_task_get_property_pane_configuration( | ||
turn_context, | ||
deserializer_helper(AceRequest, turn_context.activity.value), | ||
) | ||
) | ||
|
||
if ( | ||
turn_context.activity.name | ||
== "cardExtension/setPropertyPaneConfiguration" | ||
): | ||
ace_request = deserializer_helper( | ||
AceRequest, turn_context.activity.value | ||
) | ||
set_prop_pane_config_response = ( | ||
await self.on_sharepoint_task_set_property_pane_configuration( | ||
turn_context, ace_request | ||
) | ||
) | ||
self.validate_set_property_pane_configuration_response( | ||
set_prop_pane_config_response | ||
) | ||
return self._create_invoke_response(set_prop_pane_config_response) | ||
|
||
if turn_context.activity.name == "cardExtension/handleAction": | ||
return self._create_invoke_response( | ||
await self.on_sharepoint_task_handle_action( | ||
turn_context, | ||
deserializer_helper(AceRequest, turn_context.activity.value), | ||
) | ||
) | ||
|
||
if turn_context.activity.name == "cardExtension/token": | ||
await self.on_sign_in_invoke(turn_context) | ||
return self._create_invoke_response() | ||
|
||
except _InvokeResponseException as invoke_exception: | ||
return invoke_exception.create_invoke_response() | ||
return await super().on_invoke_activity(turn_context) | ||
|
||
async def on_sharepoint_task_get_card_view( | ||
self, turn_context: TurnContext, ace_request: AceRequest | ||
) -> CardViewResponse: | ||
""" | ||
Override this in a derived class to provide logic for when a card view is fetched. | ||
|
||
:param turn_context: A context object for this turn. | ||
:param ace_request: The ACE invoke request value payload. | ||
:returns: A Card View Response for the request. | ||
""" | ||
raise _InvokeResponseException(status_code=HTTPStatus.NOT_IMPLEMENTED) | ||
|
||
async def on_sharepoint_task_get_quick_view( | ||
self, turn_context: TurnContext, ace_request: AceRequest | ||
) -> QuickViewResponse: | ||
""" | ||
Override this in a derived class to provide logic for when a quick view is fetched. | ||
|
||
:param turn_context: A strongly-typed context object for this turn. | ||
:param ace_request: The ACE invoke request value payload. | ||
:returns: A Quick View Response for the request | ||
""" | ||
raise _InvokeResponseException(status_code=HTTPStatus.NOT_IMPLEMENTED) | ||
|
||
async def on_sharepoint_task_get_property_pane_configuration( | ||
self, turn_context: TurnContext, ace_request: AceRequest | ||
) -> GetPropertyPaneConfigurationResponse: | ||
""" | ||
Override this in a derived class to provide logic for getting configuration pane properties. | ||
|
||
:param turn_context: A strongly-typed context object for this turn. | ||
:param ace_request: The ACE invoke request value payload. | ||
:returns: A Property Pane Configuration Response for the request. | ||
""" | ||
raise _InvokeResponseException(status_code=HTTPStatus.NOT_IMPLEMENTED) | ||
|
||
async def on_sharepoint_task_set_property_pane_configuration( | ||
self, turn_context: TurnContext, ace_request: AceRequest | ||
) -> BaseHandleActionResponse: | ||
""" | ||
Override this in a derived class to provide logic for setting configuration pane properties. | ||
|
||
:param turn_context: A strongly-typed context object for this turn. | ||
:param ace_request: The ACE invoke request value payload. | ||
:returns: Card view or no-op action response. | ||
""" | ||
raise _InvokeResponseException(status_code=HTTPStatus.NOT_IMPLEMENTED) | ||
|
||
async def on_sharepoint_task_handle_action( | ||
self, turn_context: TurnContext, ace_request: AceRequest | ||
) -> BaseHandleActionResponse: | ||
""" | ||
Override this in a derived class to provide logic for handling ACE actions. | ||
|
||
:param turn_context: A strongly-typed context object for this turn. | ||
:param ace_request: The ACE invoke request value payload. | ||
:returns: A handle action response.. | ||
""" | ||
raise _InvokeResponseException(status_code=HTTPStatus.NOT_IMPLEMENTED) | ||
|
||
def validate_set_property_pane_configuration_response( | ||
self, response: BaseHandleActionResponse | ||
): | ||
""" | ||
Validates the response for SetPropertyPaneConfiguration action. | ||
|
||
:param response: The response object. | ||
:raises ValueError: If response is of type QuickViewHandleActionResponse. | ||
""" | ||
if isinstance(response, QuickViewHandleActionResponse): | ||
raise _InvokeResponseException( | ||
HTTPStatus.INTERNAL_SERVER_ERROR, | ||
"Response for SetPropertyPaneConfiguration action can't be of QuickView type.", | ||
) |
151 changes: 151 additions & 0 deletions
151
libraries/botbuilder-core/tests/sharepoint/test_sharepoint_activity_handler.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
# pylint: disable=too-many-lines | ||
import sys | ||
import os | ||
|
||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) | ||
|
||
from typing import List | ||
import aiounittest | ||
from botbuilder.schema.sharepoint import AceRequest | ||
from botbuilder.core import TurnContext | ||
from botbuilder.core.sharepoint import SharePointActivityHandler | ||
from botbuilder.schema import ( | ||
Activity, | ||
ActivityTypes, | ||
) | ||
from simple_adapter import SimpleAdapter | ||
|
||
|
||
class TestingSharePointActivityHandler(SharePointActivityHandler): | ||
__test__ = False | ||
|
||
def __init__(self): | ||
self.record: List[str] = [] | ||
|
||
async def on_sharepoint_task_get_card_view( | ||
self, turn_context: TurnContext, request: AceRequest | ||
): | ||
self.record.append("on_sharepoint_task_get_card_view") | ||
return await super().on_sharepoint_task_get_card_view(turn_context, request) | ||
|
||
async def on_sharepoint_task_get_property_pane_configuration( | ||
self, turn_context: TurnContext, request: AceRequest | ||
): | ||
self.record.append("on_sharepoint_task_get_property_pane_configuration") | ||
return await super().on_sharepoint_task_get_property_pane_configuration( | ||
turn_context, request | ||
) | ||
|
||
async def on_sharepoint_task_get_quick_view( | ||
self, turn_context: TurnContext, request: AceRequest | ||
): | ||
self.record.append("on_sharepoint_task_get_quick_view") | ||
return await super().on_sharepoint_task_get_quick_view(turn_context, request) | ||
|
||
async def on_sharepoint_task_set_property_pane_configuration( | ||
self, turn_context: TurnContext, request: AceRequest | ||
): | ||
self.record.append("on_sharepoint_task_set_property_pane_configuration") | ||
return await super().on_sharepoint_task_set_property_pane_configuration( | ||
turn_context, request | ||
) | ||
|
||
async def on_sharepoint_task_handle_action( | ||
self, turn_context: TurnContext, request: AceRequest | ||
): | ||
self.record.append("on_sharepoint_task_handle_action") | ||
return await super().on_sharepoint_task_handle_action(turn_context, request) | ||
|
||
|
||
class TestSharePointActivityHandler(aiounittest.AsyncTestCase): | ||
async def test_on_sharepoint_task_get_card_view(self): | ||
# Arrange | ||
activity = Activity( | ||
type=ActivityTypes.invoke, | ||
name="cardExtension/getCardView", | ||
value=AceRequest(), | ||
) | ||
turn_context = TurnContext(SimpleAdapter(), activity) | ||
|
||
# Act | ||
bot = TestingSharePointActivityHandler() | ||
await bot.on_turn(turn_context) | ||
|
||
# Assert | ||
self.assertEqual(1, len(bot.record)) | ||
self.assertEqual(bot.record, ["on_sharepoint_task_get_card_view"]) | ||
|
||
async def test_on_sharepoint_task_get_property_pane_configuration(self): | ||
# Arrange | ||
activity = Activity( | ||
type=ActivityTypes.invoke, | ||
name="cardExtension/getPropertyPaneConfiguration", | ||
value=AceRequest(), | ||
) | ||
turn_context = TurnContext(SimpleAdapter(), activity) | ||
|
||
# Act | ||
bot = TestingSharePointActivityHandler() | ||
await bot.on_turn(turn_context) | ||
|
||
# Assert | ||
self.assertEqual(1, len(bot.record)) | ||
self.assertEqual( | ||
bot.record, ["on_sharepoint_task_get_property_pane_configuration"] | ||
) | ||
|
||
async def test_on_sharepoint_task_get_quick_view(self): | ||
# Arrange | ||
activity = Activity( | ||
type=ActivityTypes.invoke, | ||
name="cardExtension/getQuickView", | ||
value=AceRequest(), | ||
) | ||
turn_context = TurnContext(SimpleAdapter(), activity) | ||
|
||
# Act | ||
bot = TestingSharePointActivityHandler() | ||
await bot.on_turn(turn_context) | ||
|
||
# Assert | ||
self.assertEqual(1, len(bot.record)) | ||
self.assertEqual(bot.record, ["on_sharepoint_task_get_quick_view"]) | ||
|
||
async def test_on_sharepoint_task_set_property_pane_configuration(self): | ||
# Arrange | ||
activity = Activity( | ||
type=ActivityTypes.invoke, | ||
name="cardExtension/setPropertyPaneConfiguration", | ||
value=AceRequest(), | ||
) | ||
turn_context = TurnContext(SimpleAdapter(), activity) | ||
|
||
# Act | ||
bot = TestingSharePointActivityHandler() | ||
await bot.on_turn(turn_context) | ||
|
||
# Assert | ||
self.assertEqual(1, len(bot.record)) | ||
self.assertEqual( | ||
bot.record, ["on_sharepoint_task_set_property_pane_configuration"] | ||
) | ||
|
||
async def test_on_sharepoint_task_handle_action(self): | ||
# Arrange | ||
activity = Activity( | ||
type=ActivityTypes.invoke, | ||
name="cardExtension/handleAction", | ||
value=AceRequest(), | ||
) | ||
turn_context = TurnContext(SimpleAdapter(), activity) | ||
|
||
# Act | ||
bot = TestingSharePointActivityHandler() | ||
await bot.on_turn(turn_context) | ||
|
||
# Assert | ||
self.assertEqual(1, len(bot.record)) | ||
self.assertEqual(bot.record, ["on_sharepoint_task_handle_action"]) |
24 changes: 24 additions & 0 deletions
24
libraries/botbuilder-schema/botbuilder/schema/sharepoint/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
|
||
from .ace_data import AceData | ||
from .ace_request import AceRequest | ||
from .card_view_response import CardViewResponse | ||
from .quick_view_response import QuickViewResponse | ||
from .get_property_pane_configuration_response import ( | ||
GetPropertyPaneConfigurationResponse, | ||
) | ||
from .handle_action_response import BaseHandleActionResponse | ||
from .handle_action_response import QuickViewHandleActionResponse | ||
|
||
|
||
__all__ = [ | ||
"AceData", | ||
"AceRequest", | ||
"CardViewResponse", | ||
"QuickViewResponse", | ||
"GetPropertyPaneConfigurationResponse", | ||
"BaseHandleActionResponse", | ||
"QuickViewHandleActionResponse", | ||
] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.