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:
...
@@ -254,15 +254,17 @@ async def v1_pa_message(request: Request) -> Response:
""" Send card to the bot """
""" Send card to the bot """
# noinspection PyBroadException
# noinspection PyBroadException
try
:
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
)
pa_message
=
PAMessage
.
get_schema
()
.
load
(
body
)
response
=
await
BOT
.
send_message
(
pa_message
.
conversation_id
,
response
=
await
BOT
.
send_message
(
pa_message
.
conversation_id
,
pa_message
.
tenant_id
,
pa_message
.
tenant_id
,
pa_message
.
text
,
pa_message
.
card
)
pa_message
.
card
,
pa_message
.
cards
)
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
:
Log
.
e
(
TAG
,
f
"v1_pa_message::bad data received: {request_text}"
,
exc_info
=
sys
.
exc_info
())
except
Exception
:
except
Exception
:
Log
.
e
(
TAG
,
"v1_pa_message::error sending message"
,
Log
.
e
(
TAG
,
"v1_pa_message::error sending message"
,
exc_info
=
sys
.
exc_info
())
exc_info
=
sys
.
exc_info
())
...
...
bots/messaging_extension_action_preview_bot.py
View file @
d646674e
...
@@ -83,11 +83,24 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
...
@@ -83,11 +83,24 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
mx
=
turn_context
.
activity
.
value
.
get
(
"mx"
,
{})
mx
=
turn_context
.
activity
.
value
.
get
(
"mx"
,
{})
return
mx
.
get
(
"notificationId"
,
None
)
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
,
def
send_message
(
self
,
conversation_id
:
str
,
conversation_id
:
str
,
tenant_id
:
str
,
text
:
str
=
None
,
tenant_id
:
str
,
card
:
Optional
[
Dict
[
any
,
any
]]
=
None
,
card
:
Optional
[
Dict
[
any
,
any
]]
=
None
cards
:
Optional
[
List
[
Dict
[
any
,
any
]]]
=
None
)
->
Future
[
ResourceResponse
]:
)
->
Future
[
ResourceResponse
]:
""" Send message as a bot """
""" Send message as a bot """
io_loop
=
asyncio
.
get_event_loop
()
io_loop
=
asyncio
.
get_event_loop
()
...
@@ -109,25 +122,28 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
...
@@ -109,25 +122,28 @@ 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
:
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
,
activity
=
Activity
(
type
=
ActivityTypes
.
message
,
text
=
text
,
attachments
=
attachments
)
text
=
"REMOVE ME"
)
if
len
(
attachments
)
>
1
:
if
card
is
not
None
and
isinstance
(
card
,
dict
):
activity
.
attachment_layout
=
(
# TODO(s1z): handle card!
AttachmentLayoutTypes
.
carousel
if
self
.
is_carousel
(
card
):
)
Log
.
d
(
TAG
,
"send_message::got carousel"
)
response
=
await
turn_context
.
send_activity
(
activity
)
activity
.
attachment_layout
=
"carousel"
if
response
:
activity
.
attachments
=
card
.
get
(
"attachments"
,
[])
future
.
set_result
(
response
)
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
:
except
Exception
as
exception
:
future
.
set_exception
(
exception
)
future
.
set_exception
(
exception
)
...
...
entities/json/camel_case_mixin.py
View file @
d646674e
...
@@ -3,7 +3,7 @@ import uuid
...
@@ -3,7 +3,7 @@ import uuid
from
datetime
import
datetime
from
datetime
import
datetime
import
marshmallow_dataclass
import
marshmallow_dataclass
from
marshmallow
import
pre_load
,
post_dump
from
marshmallow
import
pre_load
,
post_dump
,
EXCLUDE
from
stringcase
import
snakecase
,
camelcase
from
stringcase
import
snakecase
,
camelcase
...
@@ -20,6 +20,10 @@ def timestamp_factory() -> int:
...
@@ -20,6 +20,10 @@ def timestamp_factory() -> int:
class
CamelCaseMixin
:
class
CamelCaseMixin
:
""" Camel Case mixin """
""" Camel Case mixin """
class
Meta
:
""" Meta class with configuration """
unknown
=
EXCLUDE
@pre_load
@pre_load
def
to_snake_case
(
self
,
data
,
**
_kwargs
):
def
to_snake_case
(
self
,
data
,
**
_kwargs
):
""" to snake case pre load method """
""" to snake case pre load method """
...
...
entities/json/notification.py
View file @
d646674e
...
@@ -15,6 +15,13 @@ class NotificationUrl(CamelCaseMixin):
...
@@ -15,6 +15,13 @@ 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
]
...
@@ -24,6 +31,7 @@ class Notification(CamelCaseMixin):
...
@@ -24,6 +31,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
)
def
to_db
(
self
)
->
"NotificationCosmos"
:
def
to_db
(
self
)
->
"NotificationCosmos"
:
""" Create NotificationCosmos """
""" Create NotificationCosmos """
...
@@ -33,7 +41,8 @@ class Notification(CamelCaseMixin):
...
@@ -33,7 +41,8 @@ class Notification(CamelCaseMixin):
message
=
self
.
message
,
message
=
self
.
message
,
title
=
self
.
title
,
title
=
self
.
title
,
url
=
self
.
url
,
url
=
self
.
url
,
acknowledge
=
self
.
acknowledge
)
acknowledge
=
self
.
acknowledge
,
ttl
=
self
.
ttl
)
# noinspection PyDataclass
# noinspection PyDataclass
...
...
entities/json/pa_message.py
View file @
d646674e
...
@@ -10,6 +10,4 @@ class PAMessage(CamelCaseMixin):
...
@@ -10,6 +10,4 @@ class PAMessage(CamelCaseMixin):
""" PA message Schema """
""" PA message Schema """
conversation_id
:
str
conversation_id
:
str
tenant_id
:
str
tenant_id
:
str
text
:
Optional
[
str
]
card
:
Optional
[
Any
]
=
None
card
:
Any
=
None
cards
:
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