Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cake-bot
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Oleksandr Barabash
cake-bot
Commits
d9947178
Commit
d9947178
authored
Oct 26, 2022
by
Oleksandr Barabash
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reverted back by diff
parent
78756e32
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
29 additions
and
39 deletions
+29
-39
app.py
app.py
+4
-4
messaging_extension_action_preview_bot.py
bots/messaging_extension_action_preview_bot.py
+10
-9
acknowledge_schema.py
entities/json/acknowledge_schema.py
+0
-1
initiation.py
entities/json/initiation.py
+0
-1
medx.py
entities/json/medx.py
+0
-1
notification.py
entities/json/notification.py
+2
-3
cosmos_client.py
utils/cosmos_client.py
+13
-20
No files found.
app.py
View file @
d9947178
...
...
@@ -86,10 +86,10 @@ async def v1_get_initiations(request: Request) -> Response:
id
=
init
.
id
)
for
init
in
inits
])
return
Response
(
body
=
json
.
dumps
(
data
),
status
=
HTTPStatus
.
OK
)
except
ItemNotFound
as
e
:
print
(
"ItemNotFound:
"
,
e
)
Log
.
e
(
TAG
,
"v1_get_initiations::item not found
"
,
e
)
return
Response
(
status
=
HTTPStatus
.
NOT_FOUND
)
except
Exception
as
e
:
print
(
"error:"
,
e
)
Log
.
e
(
TAG
,
"v1_get_initiations::exception"
,
sys
.
exc_info
()
)
return
Response
(
status
=
HTTPStatus
.
BAD_REQUEST
)
...
...
@@ -111,8 +111,8 @@ async def v1_get_notification(request: Request) -> Response:
except
ItemNotFound
as
e
:
Log
.
e
(
TAG
,
"v1_get_notification::item not found"
,
e
)
return
Response
(
status
=
HTTPStatus
.
NOT_FOUND
)
except
Exception
as
e
:
Log
.
e
(
TAG
,
exc_info
=
e
)
except
Exception
:
Log
.
e
(
TAG
,
exc_info
=
sys
.
exc_info
()
)
return
Response
(
status
=
HTTPStatus
.
BAD_REQUEST
)
...
...
bots/messaging_extension_action_preview_bot.py
View file @
d9947178
...
...
@@ -83,13 +83,13 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
# reset parameters
notification
.
id
=
uuid
.
uuid4
()
.
__str__
()
notification
.
tenant_id
=
notification
.
tenant_id
or
AppConfig
.
TENANT_ID
notification
.
tenant_id
=
AppConfig
.
TENANT_ID
async
def
routine
():
""" async routine """
try
:
reference
=
await
self
.
cosmos_client
.
get_conversation
(
notification
notification
.
destination
)
except
ItemNotFound
:
future
.
set_exception
(
ConversationNotFound
(
"not found"
))
...
...
@@ -142,13 +142,12 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
try
:
account
=
turn_context
.
activity
.
from_property
acks
=
await
self
.
cosmos_client
.
get_acknowledge_items
(
mx
.
notification_id
,
mx
.
tenant_id
mx
.
notification_id
)
if
len
(
acks
)
>
0
:
return
await
self
.
cosmos_client
.
create_acknowledge
(
mx
.
notification_id
,
mx
.
tenant_id
,
account
)
notification
=
await
self
.
cosmos_client
.
get_notification
(
mx
.
notification_id
...
...
@@ -187,12 +186,12 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
return
await
self
.
on_mx_task_default
(
turn_context
)
async
def
on_mx_task_notification_url
(
self
,
turn_context
:
TurnContext
,
mx
:
MedX
)
->
TaskModuleResponse
:
notification_id
:
str
)
\
->
TaskModuleResponse
:
""" On MX Task fetch Notification URL """
try
:
notification
=
await
self
.
cosmos_client
.
get_notification
(
notification_id
=
mx
.
notification_id
,
tenant_id
=
mx
.
tenant_id
or
AppConfig
.
TENANT_ID
notification_id
=
notification_id
)
link
=
notification
.
url
.
link
if
link
is
not
None
:
...
...
@@ -239,6 +238,8 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
# 1. save action to DB
# 2. return URL
initiator
=
turn_context
.
activity
.
from_property
.
name
await
self
.
cosmos_client
.
create_initiation
(
initiator
,
mx
)
return
await
self
.
on_mx_task_notification_url
(
turn_context
,
mx
)
await
self
.
cosmos_client
.
create_initiation
(
initiator
,
mx
.
notification_id
)
return
await
self
.
on_mx_task_notification_url
(
turn_context
,
mx
.
notification_id
)
return
await
self
.
on_mx_task_default
(
turn_context
)
entities/json/acknowledge_schema.py
View file @
d9947178
...
...
@@ -8,7 +8,6 @@ class AcknowledgeSchema(CamelCaseSchema):
""" Notification Schema """
id
=
fields
.
String
(
required
=
True
,
allow_none
=
True
)
# database message id
notification_id
=
fields
.
String
(
required
=
True
)
tenant_id
=
fields
.
String
(
required
=
True
)
username
=
fields
.
String
(
required
=
True
)
user_aad_id
=
fields
.
String
(
required
=
True
)
timestamp
=
fields
.
Integer
(
required
=
True
)
entities/json/initiation.py
View file @
d9947178
...
...
@@ -11,6 +11,5 @@ class Initiation(CamelCaseMixin):
""" Notification Dataclass """
initiator
:
str
# User name
notification_id
:
str
# Notification ID
tenant_id
:
str
# Tenant ID
timestamp
:
Optional
[
int
]
=
field
(
default
=
None
)
id
:
Optional
[
str
]
=
field
(
default
=
None
)
# Unique Initiation ID
entities/json/medx.py
View file @
d9947178
...
...
@@ -21,4 +21,3 @@ class MedX(CamelCaseMixin):
""" MedX data """
type
:
str
notification_id
:
Optional
[
str
]
tenant_id
:
Optional
[
str
]
entities/json/notification.py
View file @
d9947178
...
...
@@ -24,7 +24,6 @@ class Notification(CamelCaseMixin):
title
:
Optional
[
str
]
=
field
(
default
=
None
)
url
:
Optional
[
NotificationUrl
]
=
field
(
default_factory
=
NotificationUrl
)
acknowledge
:
Optional
[
bool
]
=
field
(
default
=
False
)
tenant_id
:
Optional
[
str
]
=
field
(
default
=
None
)
def
to_db
(
self
)
->
"NotificationCosmos"
:
""" Create NotificationCosmos """
...
...
@@ -34,8 +33,7 @@ class Notification(CamelCaseMixin):
message
=
self
.
message
,
title
=
self
.
title
,
url
=
self
.
url
,
acknowledge
=
self
.
acknowledge
,
tenant_id
=
self
.
tenant_id
)
acknowledge
=
self
.
acknowledge
)
# noinspection PyDataclass
...
...
@@ -44,4 +42,5 @@ class NotificationCosmos(Notification):
""" Notification Dataclass """
# We have to add these fields
id
:
Optional
[
str
]
=
field
(
default
=
None
)
tenant_id
:
Optional
[
str
]
=
field
(
default
=
None
)
timestamp
:
Optional
[
int
]
=
field
(
default_factory
=
timestamp_factory
)
utils/cosmos_client.py
View file @
d9947178
...
...
@@ -17,7 +17,6 @@ from entities.json.acknowledge_schema import AcknowledgeSchema
from
entities.json.camel_case_mixin
import
timestamp_factory
from
entities.json.conversation_reference
import
ConversationReference
from
entities.json.initiation
import
Initiation
from
entities.json.medx
import
MedX
from
entities.json.notification
import
NotificationCosmos
...
...
@@ -115,8 +114,8 @@ class CosmosClient:
return
await
self
.
execute_blocking
(
bl
)
async
def
get_acknowledge_items
(
self
,
notification_id
:
str
,
_tenant_id
:
str
)
->
List
[
Acknowledge
]:
async
def
get_acknowledge_items
(
self
,
notification_id
)
\
->
List
[
Acknowledge
]:
""" Get Acknowledge Items """
container
=
await
self
.
get_acknowledges_container
()
...
...
@@ -264,15 +263,12 @@ class CosmosClient:
CosmosDBConfig
.
Initiations
.
PARTITION_KEY
)
async
def
create_acknowledge
(
self
,
notification_id
:
str
,
tenant_id
:
str
,
async
def
create_acknowledge
(
self
,
notification_id
:
str
,
account
:
ChannelAccount
)
->
Dict
[
str
,
Any
]:
""" Add acknowledge to the DB """
from
config
import
AppConfig
container
=
await
self
.
get_acknowledges_container
()
notification
=
AcknowledgeSchema
()
.
dump
(
dict
(
notification_id
=
notification_id
,
tenant_id
=
tenant_id
or
AppConfig
.
TENANT_ID
,
username
=
account
.
name
,
user_aad_id
=
account
.
aad_object_id
,
timestamp
=
timestamp_factory
()
...
...
@@ -284,32 +280,30 @@ class CosmosClient:
""" Get Acknowledge object """
try
:
container
=
await
self
.
get_acknowledges_container
()
#
items = await self.query_items(container, notification_id)
#
return Acknowledge.get_schema(unknown=EXCLUDE).load(items)
items
=
await
self
.
query_items
(
container
,
notification_id
)
return
Acknowledge
.
get_schema
(
unknown
=
EXCLUDE
)
.
load
(
items
)
except
ItemNotFound
:
return
None
async
def
get_conversation
(
self
,
notification
:
NotificationCosmos
)
\
async
def
get_conversation
(
self
,
conversation_id
:
str
)
\
->
ConversationReference
:
""" Get Conversation Reference """
from
config
import
AppConfig
container
=
await
self
.
get_conversations_container
()
item
=
await
self
.
get_item
(
container
,
notification
.
destination
,
notification
.
tenant_id
or
AppConfig
.
TENANT_ID
)
item
=
await
self
.
get_item
(
container
,
conversation_id
,
AppConfig
.
TENANT_ID
)
return
ConversationReference
.
get_schema
(
unknown
=
EXCLUDE
)
\
.
load
(
item
)
.
to_ms_reference
()
async
def
get_notification
(
self
,
notification_id
:
str
,
tenant_id
:
str
)
\
async
def
get_notification
(
self
,
notification_id
:
str
)
\
->
NotificationCosmos
:
""" Get Notification """
from
config
import
AppConfig
container
=
await
self
.
get_notifications_container
()
item
=
await
self
.
get_item
(
container
,
notification_id
,
tenant_id
or
AppConfig
.
TENANT_ID
)
AppConfig
.
TENANT_ID
)
return
NotificationCosmos
.
get_schema
(
unknown
=
EXCLUDE
)
.
load
(
item
)
async
def
create_conversation_reference
(
self
,
turn_context
:
TurnContext
)
\
...
...
@@ -337,13 +331,12 @@ class CosmosClient:
return
raise
SaveItemError
(
e
.
http_error_message
)
async
def
create_initiation
(
self
,
initiator
:
str
,
mx
:
MedX
)
->
None
:
async
def
create_initiation
(
self
,
initiator
:
str
,
notification_id
:
str
)
->
None
:
""" Save initiation """
from
config
import
AppConfig
container
=
await
self
.
get_initiation_container
()
initiation
=
Initiation
(
initiator
=
initiator
,
timestamp
=
timestamp_factory
(),
notification_id
=
mx
.
notification_id
,
tenant_id
=
mx
.
tenant_id
or
AppConfig
.
TENANT_ID
)
notification_id
=
notification_id
)
data
=
Initiation
.
get_schema
()
.
dump
(
initiation
)
await
self
.
create_item
(
container
,
body
=
data
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment