Commit 38c6e7a6 by Oleksandr Barabash

activity id fixed

parent 86603b3f
......@@ -14,9 +14,9 @@ from aiohttp.web_fileresponse import FileResponse
from botbuilder.core import (
BotFrameworkAdapterSettings,
TurnContext,
BotFrameworkAdapter,
BotFrameworkAdapter, CardFactory,
)
from botbuilder.schema import Activity, ActivityTypes
from botbuilder.schema import Activity, ActivityTypes, ResourceResponse
from marshmallow import EXCLUDE, ValidationError
from bots.messaging_extension_action_preview_bot import \
......@@ -199,6 +199,37 @@ async def v1_get_health_check(_request: Request) -> Response:
# key = await KEY_VAULT_CLIENT.create_key("pumpalot")
# encrypted_data = await KEY_VAULT_CLIENT.encrypt(key, b"hello")
# decrypted_data = await KEY_VAULT_CLIENT.decrypt(key, encrypted_data)
conversation_reference = await BOT.cosmos_client.get_conversation(
"a:1aStwF-2DE5JiwY3D56l6w1tEnb0N13ITGJL3Sj4fwnXwFblV1csv3EOsFEqvqQiKfOCvuaXoKuIpsU47QTnb4Pb_65G89EfgDzzL9EbhTDAi4eq4EG18xQGsjogUhlEo",
"d3c0e3f9-060e-43d8-9d64-57fbb51d2003"
)
conversation_reference.activity_id = '1674824975220'
async def cb(turn_context: TurnContext):
""" callback """
activity = Activity(id='1674825125020',
type=ActivityTypes.message)
activity.attachments = [
CardFactory.adaptive_card({
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.5",
"body": [
{
"type": "TextBlock",
"text": "The card to be purged2",
"wrap": True
}
]
})
]
response = await turn_context.update_activity(activity)
print(f"response: {response}")
print(f"activity: {activity}")
await ADAPTER.continue_conversation(conversation_reference, cb,
app_config.APP_ID)
Log.i(TAG, "v1_health_check::ok")
return Response(status=HTTPStatus.OK, content_type="application/json")
except Exception as e:
......
......@@ -121,8 +121,7 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
async def callback(turn_context: TurnContext) -> None:
""" Turn Context callback. Kinda awful syntax, I know """
try:
activity = Activity(type=ActivityTypes.message,
text="REMOVE ME")
activity = Activity(type=ActivityTypes.message)
if card is not None and isinstance(card, dict):
# TODO(s1z): handle card!
if self.is_carousel(card):
......@@ -138,8 +137,8 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
# unknown dara type received
Log.e(TAG, "send_message::error:unknown card")
response = await turn_context.send_activity(activity)
print("RESPONSE:", response, "id:", response.id,
"activity:", activity)
pa_message.message_id = response.id
await self.cosmos_client.create_pa_message(pa_message)
return future.set_result(response)
else:
# TODO(s1z): add response!!!
......@@ -188,6 +187,10 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
message = Activity(type=ActivityTypes.message,
attachments=attachments)
response = await turn_context.send_activity(message)
notification.message_id = response.id
await self.cosmos_client.update_notification(
notification
)
print(f"notification response: {response}")
future.set_result(notification.id)
except Exception as exception:
......
......@@ -14,3 +14,4 @@ class PAMessage(CamelCaseMixin):
tenant_id: str
card: Optional[Any] = None
content_t_t_l: Optional[ContentTTL] = None
message_id: Optional[str] = None
......@@ -260,13 +260,23 @@ class CosmosClient:
async def create_notification(self, notification: NotificationCosmos)\
-> NotificationCosmos:
""" Crete notification to the DB """
""" Crete notification in the DB """
notification.id = uuid.uuid4().__str__()
schema = NotificationCosmos.get_schema(unknown=EXCLUDE)
container = await self.get_notifications_container()
# TODO(s1z): change this to async!!!
saved_item = container.create_item(body=schema.dump(notification))
return schema.load(saved_item)
async def update_notification(self, notification: NotificationCosmos)\
-> NotificationCosmos:
""" Update notification in the DB """
schema = NotificationCosmos.get_schema(unknown=EXCLUDE)
container = await self.get_notifications_container()
# TODO(s1z): change this to async!!!
saved_item = container.upsert_item(body=schema.dump(notification))
return schema.load(saved_item)
async def create_pa_message(self, pa_message: PAMessage) -> PAMessage:
""" Saves PA Message to DB """
pa_message.id = uuid.uuid4().__str__()
......@@ -277,6 +287,16 @@ class CosmosClient:
saved_item = container.create_item(body=pa_message_dumped)
return schema.load(saved_item)
async def update_pa_message(self, pa_message: PAMessage) -> PAMessage:
""" Update notification in the DB """
schema = PAMessage.get_schema(unknown=EXCLUDE)
container = await self.get_pa_container()
pa_message_dumped = schema.dump(pa_message)
print(f"pa_message_dumped: {pa_message_dumped}")
saved_item = container.upsert_item(body=pa_message_dumped)
return schema.load(saved_item)
async def get_acknowledges_container(self) -> ContainerProxy:
""" get_acknowledges_container """
from config import CosmosDBConfig
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment