8000 updating callback function · TheCompuGuru/botbuilder-python@d66de1b · GitHub
[go: up one dir, main page]

Skip to content

Commit d66de1b

Browse files
committed
updating callback function
1 parent cf76bd8 commit d66de1b

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-2
lines changed
Lines changed: 78 additions & 0 deletions
8000 < 8000 /tr>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import unittest
5+
from typing import List, Tuple, Awaitable, Callable
6+
from botbuilder.core import BotAdapter, TurnContext
7+
from botbuilder.schema import Activity, ConversationReference, ResourceResponse, ConversationParameters
8+
9+
10+
class SimpleAdapterWithCreateConversation(BotAdapter):
11+
# pylint: disable=unused-argument
12+
13+
def __init__(
14+
self,
15+
call_on_send=None,
16+
call_on_update=None,
17+
call_on_delete=None,
18+
call_create_conversation=None,
19+
):
20+
super(SimpleAdapterWithCreateConversation, self).__init__()
21+
self.test_aux = unittest.TestCase("__init__")
22+
self._call_on_send = call_on_send
23+
self._call_on_update = call_on_update
24+
self._call_on_delete = call_on_delete
25+
self._call_create_conversation = call_create_conversation
26+
27+
async def delete_activity(
28+
self, context: TurnContext, reference: ConversationReference
29+
):
30+
self.test_aux.assertIsNotNone(
31+
reference, "SimpleAdapter.delete_activity: missing reference"
32+
)
33+
if self._call_on_delete is not None:
34+
self._call_on_delete(reference)
35+
36+
async def send_activities(
37+
self, context: TurnContext, activities: List[Activity]
38+
) -> List[ResourceResponse]:
39+
self.test_aux.assertIsNotNone(
40+
activities, "SimpleAdapter.delete_activity: missing reference"
41+
)
42+
self.test_aux.assertTrue(
43+
len(activities) > 0,
44+
"SimpleAdapter.send_activities: empty activities array.",
45+
)
46+
47+
if self._call_on_send is not None:
48+
self._call_on_send(activities)
49+
responses = []
50+
51+
for activity in activities:
52+
responses.append(ResourceResponse(id=activity.id))
53+
54+
return responses
55+
56+
async def create_conversation(
57+
self,
58+
reference: ConversationReference,
59+
logic: Callable[[TurnContext], Awaitable] = None,
60+
conversation_parameters: ConversationParameters = None,
61+
) -> Tuple[ConversationReference, str]:
62+
if self._call_create_conversation is not None:
63+
self._call_create_conversation()
64+
ref = ConversationReference(activity_id="new_conversation_id")
65+
return (ref, "reference123")
66+
67+
async def update_activity(self, context: TurnContext, activity: Activity):
68+
self.test_aux.assertIsNotNone(
69+
activity, "SimpleAdapter.update_activity: missing activity"
70+
)
71+
if self._call_on_update is not None:
72+
self._call_on_update(activity)
73+
74+
return ResourceResponse(activity.id)
75+
76+
async def process_request(self, activity, handler):
77+
context = TurnContext(self, activity)
78+
return await self.run_pipeline(context, handler)

libraries/botbuilder-core/tests/teams/test_teams_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
from botbuilder.schema import Activity
1010
from botbuilder.schema.teams import TeamsChannelData, TeamInfo
1111
from botframework.connector import Channels
12-
from simple_adapter import SimpleAdapter
12+
from simple_adapter_with_create_conversation import SimpleAdapterWithCreateConversation
1313

1414

1515
class TestTeamsInfo(aiounittest.AsyncTestCase):
1616
async def test_send_message_to_teams(self):
1717
def create_conversation():
1818
pass
1919

20-
adapter = SimpleAdapter(call_create_conversation=create_conversation)
20+
adapter = SimpleAdapterWithCreateConversation(call_create_conversation=create_conversation)
2121

2222
activity = Activity(
2323
type="message",

0 commit comments

Comments
 (0)
0