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:
try
:
request_text
=
await
request
.
text
()
body
=
json_loads
(
request_text
,
dict
())
# Add TTL here!
pa_message
=
PAMessage
.
get_schema
()
.
load
(
body
)
response
=
await
BOT
.
send_message
(
pa_message
.
conversation_id
,
pa_message
.
tenant_id
,
pa_message
.
card
)
response
=
await
BOT
.
send_message
(
pa_message
)
Log
.
d
(
TAG
,
f
"v1_pa_message::notification: '{response}'"
)
return
make_response
(
200
,
"OK"
)
except
AttributeError
:
...
...
bots/messaging_extension_action_preview_bot.py
View file @
02ee72e4
...
...
@@ -24,6 +24,7 @@ from bots.exceptions import ConversationNotFound
from
config
import
TaskModuleConfig
,
AppConfig
from
entities.json.medx
import
MedX
,
MXTypes
from
entities.json.notification
import
NotificationCosmos
from
entities.json.pa_message
import
PAMessage
from
utils.card_helper
import
CardHelper
from
utils.cosmos_client
import
CosmosClient
,
ItemNotFound
from
utils.functions
import
get_i18n
...
...
@@ -97,21 +98,19 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
return
True
return
False
def
send_message
(
self
,
conversation_id
:
str
,
tenant_id
:
str
,
card
:
Optional
[
Dict
[
any
,
any
]]
=
None
)
->
Future
[
ResourceResponse
]:
def
send_message
(
self
,
pa_message
:
PAMessage
)
->
Future
[
ResourceResponse
]:
""" Send message as a bot """
io_loop
=
asyncio
.
get_event_loop
()
future
=
Future
()
card
=
pa_message
.
card
async
def
routine
():
""" async routine """
try
:
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
:
future
.
set_exception
(
ConversationNotFound
(
"not found"
))
return
...
...
config.py
View file @
02ee72e4
...
...
@@ -121,6 +121,13 @@ class CosmosDBConfig:
PK
=
"id"
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
)
KEY_VAULT_CLIENT
=
AzureKeyVaultClient
(
AppConfig
.
CLIENT_ID
,
...
...
entities/json/notification.py
View file @
02ee72e4
...
...
@@ -5,6 +5,7 @@ from typing import Optional
import
marshmallow.validate
from
entities.json.camel_case_mixin
import
CamelCaseMixin
,
timestamp_factory
from
entities.json.ttl_record
import
TTLRecord
@dataclass
...
...
@@ -15,13 +16,6 @@ class NotificationUrl(CamelCaseMixin):
@dataclass
class
NotificationTTL
(
CamelCaseMixin
):
""" Notification TTL """
ttl
:
Optional
[
int
]
=
field
(
default
=
None
)
content
:
Optional
[
any
]
=
field
(
default
=
None
)
@dataclass
class
Notification
(
CamelCaseMixin
):
""" Notification Dataclass """
message_id
:
Optional
[
str
]
...
...
@@ -31,7 +25,7 @@ class Notification(CamelCaseMixin):
title
:
Optional
[
str
]
=
field
(
default
=
None
)
url
:
Optional
[
NotificationUrl
]
=
field
(
default_factory
=
NotificationUrl
)
acknowledge
:
Optional
[
bool
]
=
field
(
default
=
False
)
ttl
:
Optional
[
NotificationTTL
]
=
field
(
default
=
None
)
ttl
:
Optional
[
TTLRecord
]
=
field
(
default
=
None
)
def
to_db
(
self
)
->
"NotificationCosmos"
:
""" Create NotificationCosmos """
...
...
entities/json/pa_message.py
View file @
02ee72e4
...
...
@@ -2,12 +2,15 @@
from
dataclasses
import
dataclass
,
field
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
class
PAMessage
(
CamelCaseMixin
):
""" PA message Schema """
id
:
Optional
[
str
]
conversation_id
:
str
tenant_id
:
str
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
from
entities.json.flow
import
Flow
from
entities.json.initiation
import
Initiation
from
entities.json.notification
import
NotificationCosmos
from
entities.json.pa_message
import
PAMessage
from
utils.functions
import
get_first_or_none
from
utils.log
import
Log
...
...
@@ -266,6 +267,14 @@ class CosmosClient:
saved_item
=
container
.
create_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__
()
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
:
""" get_acknowledges_container """
from
config
import
CosmosDBConfig
...
...
@@ -286,6 +295,14 @@ class CosmosClient:
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
:
""" Get Messages container """
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