Commit 38c6e7a6 by Oleksandr Barabash

activity id fixed

parent 86603b3f
...@@ -14,9 +14,9 @@ from aiohttp.web_fileresponse import FileResponse ...@@ -14,9 +14,9 @@ from aiohttp.web_fileresponse import FileResponse
from botbuilder.core import ( from botbuilder.core import (
BotFrameworkAdapterSettings, BotFrameworkAdapterSettings,
TurnContext, TurnContext,
BotFrameworkAdapter, BotFrameworkAdapter, CardFactory,
) )
from botbuilder.schema import Activity, ActivityTypes from botbuilder.schema import Activity, ActivityTypes, ResourceResponse
from marshmallow import EXCLUDE, ValidationError from marshmallow import EXCLUDE, ValidationError
from bots.messaging_extension_action_preview_bot import \ from bots.messaging_extension_action_preview_bot import \
...@@ -199,6 +199,37 @@ async def v1_get_health_check(_request: Request) -> Response: ...@@ -199,6 +199,37 @@ async def v1_get_health_check(_request: Request) -> Response:
# key = await KEY_VAULT_CLIENT.create_key("pumpalot") # key = await KEY_VAULT_CLIENT.create_key("pumpalot")
# encrypted_data = await KEY_VAULT_CLIENT.encrypt(key, b"hello") # encrypted_data = await KEY_VAULT_CLIENT.encrypt(key, b"hello")
# decrypted_data = await KEY_VAULT_CLIENT.decrypt(key, encrypted_data) # 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") Log.i(TAG, "v1_health_check::ok")
return Response(status=HTTPStatus.OK, content_type="application/json") return Response(status=HTTPStatus.OK, content_type="application/json")
except Exception as e: except Exception as e:
......
...@@ -121,8 +121,7 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler): ...@@ -121,8 +121,7 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
async def callback(turn_context: TurnContext) -> None: async def callback(turn_context: TurnContext) -> None:
""" Turn Context callback. Kinda awful syntax, I know """ """ Turn Context callback. Kinda awful syntax, I know """
try: try:
activity = Activity(type=ActivityTypes.message, activity = Activity(type=ActivityTypes.message)
text="REMOVE ME")
if card is not None and isinstance(card, dict): if card is not None and isinstance(card, dict):
# TODO(s1z): handle card! # TODO(s1z): handle card!
if self.is_carousel(card): if self.is_carousel(card):
...@@ -138,8 +137,8 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler): ...@@ -138,8 +137,8 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
# unknown dara type received # unknown dara type received
Log.e(TAG, "send_message::error:unknown card") Log.e(TAG, "send_message::error:unknown card")
response = await turn_context.send_activity(activity) response = await turn_context.send_activity(activity)
print("RESPONSE:", response, "id:", response.id, pa_message.message_id = response.id
"activity:", activity) await self.cosmos_client.create_pa_message(pa_message)
return future.set_result(response) return future.set_result(response)
else: else:
# TODO(s1z): add response!!! # TODO(s1z): add response!!!
...@@ -188,6 +187,10 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler): ...@@ -188,6 +187,10 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
message = Activity(type=ActivityTypes.message, message = Activity(type=ActivityTypes.message,
attachments=attachments) attachments=attachments)
response = await turn_context.send_activity(message) response = await turn_context.send_activity(message)
notification.message_id = response.id
await self.cosmos_client.update_notification(
notification
)
print(f"notification response: {response}") print(f"notification response: {response}")
future.set_result(notification.id) future.set_result(notification.id)
except Exception as exception: except Exception as exception:
......
...@@ -14,3 +14,4 @@ class PAMessage(CamelCaseMixin): ...@@ -14,3 +14,4 @@ class PAMessage(CamelCaseMixin):
tenant_id: str tenant_id: str
card: Optional[Any] = None card: Optional[Any] = None
content_t_t_l: Optional[ContentTTL] = None content_t_t_l: Optional[ContentTTL] = None
message_id: Optional[str] = None
...@@ -260,13 +260,23 @@ class CosmosClient: ...@@ -260,13 +260,23 @@ class CosmosClient:
async def create_notification(self, notification: NotificationCosmos)\ async def create_notification(self, notification: NotificationCosmos)\
-> NotificationCosmos: -> NotificationCosmos:
""" Crete notification to the DB """ """ Crete notification in the DB """
notification.id = uuid.uuid4().__str__() notification.id = uuid.uuid4().__str__()
schema = NotificationCosmos.get_schema(unknown=EXCLUDE) schema = NotificationCosmos.get_schema(unknown=EXCLUDE)
container = await self.get_notifications_container() container = await self.get_notifications_container()
# TODO(s1z): change this to async!!!
saved_item = container.create_item(body=schema.dump(notification)) saved_item = container.create_item(body=schema.dump(notification))
return schema.load(saved_item) 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: async def create_pa_message(self, pa_message: PAMessage) -> PAMessage:
""" Saves PA Message to DB """ """ Saves PA Message to DB """
pa_message.id = uuid.uuid4().__str__() pa_message.id = uuid.uuid4().__str__()
...@@ -277,6 +287,16 @@ class CosmosClient: ...@@ -277,6 +287,16 @@ class CosmosClient:
saved_item = container.create_item(body=pa_message_dumped) saved_item = container.create_item(body=pa_message_dumped)
return schema.load(saved_item) 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: async def get_acknowledges_container(self) -> ContainerProxy:
""" get_acknowledges_container """ """ get_acknowledges_container """
from config import CosmosDBConfig 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