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
02ee72e4
Commit
02ee72e4
authored
Jan 25, 2023
by
Oleksandr Barabash
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ttl object created, added to PA and Notification objects
parent
d646674e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
49 additions
and
18 deletions
+49
-18
app.py
app.py
+2
-3
messaging_extension_action_preview_bot.py
bots/messaging_extension_action_preview_bot.py
+5
-6
config.py
config.py
+7
-0
notification.py
entities/json/notification.py
+2
-8
pa_message.py
entities/json/pa_message.py
+4
-1
ttl_record.py
entities/json/ttl_record.py
+12
-0
cosmos_client.py
utils/cosmos_client.py
+17
-0
No files found.
app.py
View file @
02ee72e4
...
@@ -256,10 +256,9 @@ async def v1_pa_message(request: Request) -> Response:
...
@@ -256,10 +256,9 @@ async def v1_pa_message(request: Request) -> Response:
try
:
try
:
request_text
=
await
request
.
text
()
request_text
=
await
request
.
text
()
body
=
json_loads
(
request_text
,
dict
())
body
=
json_loads
(
request_text
,
dict
())
# Add TTL here!
pa_message
=
PAMessage
.
get_schema
()
.
load
(
body
)
pa_message
=
PAMessage
.
get_schema
()
.
load
(
body
)
response
=
await
BOT
.
send_message
(
pa_message
.
conversation_id
,
response
=
await
BOT
.
send_message
(
pa_message
)
pa_message
.
tenant_id
,
pa_message
.
card
)
Log
.
d
(
TAG
,
f
"v1_pa_message::notification: '{response}'"
)
Log
.
d
(
TAG
,
f
"v1_pa_message::notification: '{response}'"
)
return
make_response
(
200
,
"OK"
)
return
make_response
(
200
,
"OK"
)
except
AttributeError
:
except
AttributeError
:
...
...
bots/messaging_extension_action_preview_bot.py
View file @
02ee72e4
...
@@ -24,6 +24,7 @@ from bots.exceptions import ConversationNotFound
...
@@ -24,6 +24,7 @@ from bots.exceptions import ConversationNotFound
from
config
import
TaskModuleConfig
,
AppConfig
from
config
import
TaskModuleConfig
,
AppConfig
from
entities.json.medx
import
MedX
,
MXTypes
from
entities.json.medx
import
MedX
,
MXTypes
from
entities.json.notification
import
NotificationCosmos
from
entities.json.notification
import
NotificationCosmos
from
entities.json.pa_message
import
PAMessage
from
utils.card_helper
import
CardHelper
from
utils.card_helper
import
CardHelper
from
utils.cosmos_client
import
CosmosClient
,
ItemNotFound
from
utils.cosmos_client
import
CosmosClient
,
ItemNotFound
from
utils.functions
import
get_i18n
from
utils.functions
import
get_i18n
...
@@ -97,21 +98,19 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
...
@@ -97,21 +98,19 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
return
True
return
True
return
False
return
False
def
send_message
(
self
,
def
send_message
(
self
,
pa_message
:
PAMessage
)
->
Future
[
ResourceResponse
]:
conversation_id
:
str
,
tenant_id
:
str
,
card
:
Optional
[
Dict
[
any
,
any
]]
=
None
)
->
Future
[
ResourceResponse
]:
""" Send message as a bot """
""" Send message as a bot """
io_loop
=
asyncio
.
get_event_loop
()
io_loop
=
asyncio
.
get_event_loop
()
future
=
Future
()
future
=
Future
()
card
=
pa_message
.
card
async
def
routine
():
async
def
routine
():
""" async routine """
""" async routine """
try
:
try
:
reference
=
await
self
.
cosmos_client
.
get_conversation
(
reference
=
await
self
.
cosmos_client
.
get_conversation
(
conversation_id
,
tenant_id
pa_message
.
conversation_id
,
pa_message
.
tenant_id
)
)
await
self
.
cosmos_client
.
create_pa_message
(
pa_message
)
except
ItemNotFound
:
except
ItemNotFound
:
future
.
set_exception
(
ConversationNotFound
(
"not found"
))
future
.
set_exception
(
ConversationNotFound
(
"not found"
))
return
return
...
...
config.py
View file @
02ee72e4
...
@@ -121,6 +121,13 @@ class CosmosDBConfig:
...
@@ -121,6 +121,13 @@ class CosmosDBConfig:
PK
=
"id"
PK
=
"id"
PARTITION_KEY
=
PartitionKey
(
path
=
"/tenantId"
)
PARTITION_KEY
=
PartitionKey
(
path
=
"/tenantId"
)
class
PAMessage
:
""" Power Automate message """
DATABASE
=
"bot"
CONTAINER
=
"pa"
PK
=
"id"
PARTITION_KEY
=
PartitionKey
(
path
=
"/tenantId"
)
COSMOS_CLIENT
=
CosmosClient
(
CosmosDBConfig
.
HOST
,
CosmosDBConfig
.
KEY
)
COSMOS_CLIENT
=
CosmosClient
(
CosmosDBConfig
.
HOST
,
CosmosDBConfig
.
KEY
)
KEY_VAULT_CLIENT
=
AzureKeyVaultClient
(
AppConfig
.
CLIENT_ID
,
KEY_VAULT_CLIENT
=
AzureKeyVaultClient
(
AppConfig
.
CLIENT_ID
,
...
...
entities/json/notification.py
View file @
02ee72e4
...
@@ -5,6 +5,7 @@ from typing import Optional
...
@@ -5,6 +5,7 @@ from typing import Optional
import
marshmallow.validate
import
marshmallow.validate
from
entities.json.camel_case_mixin
import
CamelCaseMixin
,
timestamp_factory
from
entities.json.camel_case_mixin
import
CamelCaseMixin
,
timestamp_factory
from
entities.json.ttl_record
import
TTLRecord
@dataclass
@dataclass
...
@@ -15,13 +16,6 @@ class NotificationUrl(CamelCaseMixin):
...
@@ -15,13 +16,6 @@ class NotificationUrl(CamelCaseMixin):
@dataclass
@dataclass
class
NotificationTTL
(
CamelCaseMixin
):
""" Notification TTL """
ttl
:
Optional
[
int
]
=
field
(
default
=
None
)
content
:
Optional
[
any
]
=
field
(
default
=
None
)
@dataclass
class
Notification
(
CamelCaseMixin
):
class
Notification
(
CamelCaseMixin
):
""" Notification Dataclass """
""" Notification Dataclass """
message_id
:
Optional
[
str
]
message_id
:
Optional
[
str
]
...
@@ -31,7 +25,7 @@ class Notification(CamelCaseMixin):
...
@@ -31,7 +25,7 @@ class Notification(CamelCaseMixin):
title
:
Optional
[
str
]
=
field
(
default
=
None
)
title
:
Optional
[
str
]
=
field
(
default
=
None
)
url
:
Optional
[
NotificationUrl
]
=
field
(
default_factory
=
NotificationUrl
)
url
:
Optional
[
NotificationUrl
]
=
field
(
default_factory
=
NotificationUrl
)
acknowledge
:
Optional
[
bool
]
=
field
(
default
=
False
)
acknowledge
:
Optional
[
bool
]
=
field
(
default
=
False
)
ttl
:
Optional
[
NotificationTTL
]
=
field
(
default
=
None
)
ttl
:
Optional
[
TTLRecord
]
=
field
(
default
=
None
)
def
to_db
(
self
)
->
"NotificationCosmos"
:
def
to_db
(
self
)
->
"NotificationCosmos"
:
""" Create NotificationCosmos """
""" Create NotificationCosmos """
...
...
entities/json/pa_message.py
View file @
02ee72e4
...
@@ -2,12 +2,15 @@
...
@@ -2,12 +2,15 @@
from
dataclasses
import
dataclass
,
field
from
dataclasses
import
dataclass
,
field
from
typing
import
Optional
,
Union
,
List
,
Dict
,
Any
from
typing
import
Optional
,
Union
,
List
,
Dict
,
Any
from
entities.json.camel_case_mixin
import
CamelCaseMixin
from
entities.json.camel_case_mixin
import
CamelCaseMixin
,
uuid_factory
from
entities.json.ttl_record
import
TTLRecord
@dataclass
@dataclass
class
PAMessage
(
CamelCaseMixin
):
class
PAMessage
(
CamelCaseMixin
):
""" PA message Schema """
""" PA message Schema """
id
:
Optional
[
str
]
conversation_id
:
str
conversation_id
:
str
tenant_id
:
str
tenant_id
:
str
card
:
Optional
[
Any
]
=
None
card
:
Optional
[
Any
]
=
None
ttl
:
Optional
[
TTLRecord
]
=
None
entities/json/ttl_record.py
0 → 100644
View file @
02ee72e4
""" TTL record for the messages in database """
from
dataclasses
import
dataclass
,
field
from
typing
import
Optional
from
entities.json.camel_case_mixin
import
CamelCaseMixin
@dataclass
class
TTLRecord
(
CamelCaseMixin
):
""" Notification TTL """
ttl
:
Optional
[
int
]
=
field
(
default
=
None
)
content
:
Optional
[
any
]
=
field
(
default
=
None
)
utils/cosmos_client.py
View file @
02ee72e4
...
@@ -20,6 +20,7 @@ from entities.json.conversation_reference import ConversationReference
...
@@ -20,6 +20,7 @@ from entities.json.conversation_reference import ConversationReference
from
entities.json.flow
import
Flow
from
entities.json.flow
import
Flow
from
entities.json.initiation
import
Initiation
from
entities.json.initiation
import
Initiation
from
entities.json.notification
import
NotificationCosmos
from
entities.json.notification
import
NotificationCosmos
from
entities.json.pa_message
import
PAMessage
from
utils.functions
import
get_first_or_none
from
utils.functions
import
get_first_or_none
from
utils.log
import
Log
from
utils.log
import
Log
...
@@ -266,6 +267,14 @@ class CosmosClient:
...
@@ -266,6 +267,14 @@ class CosmosClient:
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
create_pa_message
(
self
,
pa_message
:
PAMessage
)
->
PAMessage
:
""" Saves PA Message to DB """
pa_message
.
id
=
uuid
.
uuid4
()
.
__str__
()
schema
=
PAMessage
.
get_schema
(
unknown
=
EXCLUDE
)
container
=
await
self
.
get_pa_container
()
saved_item
=
container
.
create_item
(
body
=
schema
.
dump
(
pa_message
))
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
...
@@ -286,6 +295,14 @@ class CosmosClient:
...
@@ -286,6 +295,14 @@ class CosmosClient:
CosmosDBConfig
.
Notifications
.
PARTITION_KEY
CosmosDBConfig
.
Notifications
.
PARTITION_KEY
)
)
async
def
get_pa_container
(
self
)
->
ContainerProxy
:
""" Get PA container """
from
config
import
CosmosDBConfig
return
await
self
.
get_container
(
CosmosDBConfig
.
PAMessage
.
DATABASE
,
CosmosDBConfig
.
PAMessage
.
CONTAINER
,
CosmosDBConfig
.
PAMessage
.
PARTITION_KEY
)
async
def
get_messages_container
(
self
)
->
ContainerProxy
:
async
def
get_messages_container
(
self
)
->
ContainerProxy
:
""" Get Messages container """
""" Get Messages container """
from
config
import
CosmosDBConfig
from
config
import
CosmosDBConfig
...
...
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