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
d646674e
Commit
d646674e
authored
Jan 25, 2023
by
Oleksandr Barabash
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ttl preparation update
parent
e9561f11
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
30 deletions
+59
-30
app.py
app.py
+6
-4
messaging_extension_action_preview_bot.py
bots/messaging_extension_action_preview_bot.py
+37
-21
camel_case_mixin.py
entities/json/camel_case_mixin.py
+5
-1
notification.py
entities/json/notification.py
+10
-1
pa_message.py
entities/json/pa_message.py
+1
-3
No files found.
app.py
View file @
d646674e
...
...
@@ -254,15 +254,17 @@ async def v1_pa_message(request: Request) -> Response:
""" Send card to the bot """
# noinspection PyBroadException
try
:
body
=
json_loads
(
await
request
.
text
())
request_text
=
await
request
.
text
()
body
=
json_loads
(
request_text
,
dict
())
pa_message
=
PAMessage
.
get_schema
()
.
load
(
body
)
response
=
await
BOT
.
send_message
(
pa_message
.
conversation_id
,
pa_message
.
tenant_id
,
pa_message
.
text
,
pa_message
.
card
,
pa_message
.
cards
)
pa_message
.
card
)
Log
.
d
(
TAG
,
f
"v1_pa_message::notification: '{response}'"
)
return
make_response
(
200
,
"OK"
)
except
AttributeError
:
Log
.
e
(
TAG
,
f
"v1_pa_message::bad data received: {request_text}"
,
exc_info
=
sys
.
exc_info
())
except
Exception
:
Log
.
e
(
TAG
,
"v1_pa_message::error sending message"
,
exc_info
=
sys
.
exc_info
())
...
...
bots/messaging_extension_action_preview_bot.py
View file @
d646674e
...
...
@@ -83,11 +83,24 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
mx
=
turn_context
.
activity
.
value
.
get
(
"mx"
,
{})
return
mx
.
get
(
"notificationId"
,
None
)
@staticmethod
def
is_carousel
(
card_data
):
""" returns True if we have carousel data structure """
if
card_data
.
get
(
"attachmentLayout"
,
None
)
==
"carousel"
:
return
True
return
False
@staticmethod
def
is_adaptive_syntax
(
card_data
):
""" returns True if we have carousel data structure """
if
card_data
.
get
(
"type"
,
None
)
==
"AdaptiveCard"
:
return
True
return
False
def
send_message
(
self
,
conversation_id
:
str
,
tenant_id
:
str
,
text
:
str
=
None
,
card
:
Optional
[
Dict
[
any
,
any
]]
=
None
,
cards
:
Optional
[
List
[
Dict
[
any
,
any
]]]
=
None
tenant_id
:
str
,
card
:
Optional
[
Dict
[
any
,
any
]]
=
None
)
->
Future
[
ResourceResponse
]:
""" Send message as a bot """
io_loop
=
asyncio
.
get_event_loop
()
...
...
@@ -109,25 +122,28 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
async
def
callback
(
turn_context
:
TurnContext
)
->
None
:
""" Turn Context callback. Kinda awful syntax, I know """
try
:
attachments
=
None
if
cards
is
not
None
:
Log
.
i
(
TAG
,
f
"send_message::cards: {cards}"
)
attachments
=
[
CardFactory
.
adaptive_card
(
x
)
for
x
in
cards
]
elif
card
is
not
None
:
# TODO(s1z): create parase for all card types
attachments
=
[
CardFactory
.
adaptive_card
(
card
)]
activity
=
Activity
(
type
=
ActivityTypes
.
message
,
text
=
text
,
attachments
=
attachments
)
if
len
(
attachments
)
>
1
:
activity
.
attachment_layout
=
(
AttachmentLayoutTypes
.
carousel
)
response
=
await
turn_context
.
send_activity
(
activity
)
if
response
:
future
.
set_result
(
response
)
text
=
"REMOVE ME"
)
if
card
is
not
None
and
isinstance
(
card
,
dict
):
# TODO(s1z): handle card!
if
self
.
is_carousel
(
card
):
Log
.
d
(
TAG
,
"send_message::got carousel"
)
activity
.
attachment_layout
=
"carousel"
activity
.
attachments
=
card
.
get
(
"attachments"
,
[])
elif
self
.
is_adaptive_syntax
(
card
):
Log
.
d
(
TAG
,
"send_message::got simple card"
)
activity
.
attachments
=
[
CardFactory
.
adaptive_card
(
card
)
]
else
:
# unknown dara type received
Log
.
e
(
TAG
,
"send_message::error:unknown card"
)
response
=
await
turn_context
.
send_activity
(
activity
)
return
future
.
set_result
(
response
)
else
:
# TODO(s1z): add response!!!
pass
future
.
set_result
(
None
)
except
Exception
as
exception
:
future
.
set_exception
(
exception
)
...
...
entities/json/camel_case_mixin.py
View file @
d646674e
...
...
@@ -3,7 +3,7 @@ import uuid
from
datetime
import
datetime
import
marshmallow_dataclass
from
marshmallow
import
pre_load
,
post_dump
from
marshmallow
import
pre_load
,
post_dump
,
EXCLUDE
from
stringcase
import
snakecase
,
camelcase
...
...
@@ -20,6 +20,10 @@ def timestamp_factory() -> int:
class
CamelCaseMixin
:
""" Camel Case mixin """
class
Meta
:
""" Meta class with configuration """
unknown
=
EXCLUDE
@pre_load
def
to_snake_case
(
self
,
data
,
**
_kwargs
):
""" to snake case pre load method """
...
...
entities/json/notification.py
View file @
d646674e
...
...
@@ -15,6 +15,13 @@ 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
]
...
...
@@ -24,6 +31,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
)
def
to_db
(
self
)
->
"NotificationCosmos"
:
""" Create NotificationCosmos """
...
...
@@ -33,7 +41,8 @@ class Notification(CamelCaseMixin):
message
=
self
.
message
,
title
=
self
.
title
,
url
=
self
.
url
,
acknowledge
=
self
.
acknowledge
)
acknowledge
=
self
.
acknowledge
,
ttl
=
self
.
ttl
)
# noinspection PyDataclass
...
...
entities/json/pa_message.py
View file @
d646674e
...
...
@@ -10,6 +10,4 @@ class PAMessage(CamelCaseMixin):
""" PA message Schema """
conversation_id
:
str
tenant_id
:
str
text
:
Optional
[
str
]
card
:
Any
=
None
cards
:
Any
=
None
card
:
Optional
[
Any
]
=
None
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