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
8566eebc
Commit
8566eebc
authored
Sep 23, 2023
by
Oleksandr Barabash
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle_mars_report now returns user emails in the team
parent
d623ff42
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
12 deletions
+26
-12
app.py
app.py
+11
-7
messaging_extension_action_preview_bot.py
bots/messaging_extension_action_preview_bot.py
+15
-5
No files found.
app.py
View file @
8566eebc
...
@@ -6,7 +6,7 @@ import time
...
@@ -6,7 +6,7 @@ import time
import
traceback
import
traceback
from
datetime
import
datetime
from
datetime
import
datetime
from
http
import
HTTPStatus
from
http
import
HTTPStatus
from
typing
import
Dict
,
Union
,
List
from
typing
import
Dict
,
Union
,
List
,
Optional
import
marshmallow_dataclass
import
marshmallow_dataclass
from
aiohttp
import
web
from
aiohttp
import
web
...
@@ -83,7 +83,8 @@ ADAPTER.on_turn_error = on_error
...
@@ -83,7 +83,8 @@ ADAPTER.on_turn_error = on_error
def
make_response
(
code
:
int
,
message
:
str
,
def
make_response
(
code
:
int
,
message
:
str
,
data
:
Union
[
Dict
[
any
,
any
],
List
[
Dict
[
any
,
any
]]]
=
None
)
\
data
:
Optional
[
Union
[
Dict
[
any
,
any
],
List
[
Dict
[
any
,
any
]]]]
=
None
)
\
->
Response
:
->
Response
:
""" Make an API json response """
""" Make an API json response """
body
=
dict
(
status
=
dict
(
code
=
code
,
message
=
message
))
body
=
dict
(
status
=
dict
(
code
=
code
,
message
=
message
))
...
@@ -334,13 +335,16 @@ async def v1_mars_report(request: Request) -> Response:
...
@@ -334,13 +335,16 @@ async def v1_mars_report(request: Request) -> Response:
request_json
=
await
request
.
json
()
request_json
=
await
request
.
json
()
report
=
MarsReport
.
load
(
request_json
,
unknown
=
EXCLUDE
)
report
=
MarsReport
.
load
(
request_json
,
unknown
=
EXCLUDE
)
response
=
await
BOT
.
handle_mars_report
(
channel_id
,
report
)
emails
=
await
BOT
.
handle_mars_report
(
channel_id
,
report
)
Log
.
d
(
TAG
,
f
"v1_mars_report::notification: '{response}'"
)
Log
.
d
(
TAG
,
f
"v1_mars_report::notification: '{emails}'"
)
return
make_response
(
200
,
"OK"
,
{
"info"
:
{
"channelId"
:
channel_id
}})
data
=
None
if
isinstance
(
emails
,
list
)
and
len
(
emails
)
>
0
:
data
=
{
"data"
:
emails
}
return
make_response
(
200
,
"OK"
,
data
)
except
Exception
:
except
Exception
:
Log
.
e
(
TAG
,
"v1_mars_report::error"
,
exc_info
=
sys
.
exc_info
())
Log
.
e
(
TAG
,
"v1_mars_report::error"
,
exc_info
=
sys
.
exc_info
())
return
make_response
(
500
,
"Bad Request"
,
#
return make_response(500, "Bad Request",
{
"info"
:
traceback
.
format_exc
()})
#
{"info": traceback.format_exc()})
return
make_response
(
400
,
"Bad Request"
)
return
make_response
(
400
,
"Bad Request"
)
...
...
bots/messaging_extension_action_preview_bot.py
View file @
8566eebc
...
@@ -115,6 +115,7 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
...
@@ -115,6 +115,7 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
# 2. Add permissions for the recipients
# 2. Add permissions for the recipients
# 3. Send info into the flow
# 3. Send info into the flow
logger
.
info
(
"handle_mars_report"
)
logger
.
info
(
"handle_mars_report"
)
future
=
Future
()
# todo(s1z): Make this secure and not such ugly
# todo(s1z): Make this secure and not such ugly
stripped_channel_id
=
parse
.
unquote_plus
(
channel_id
)
.
split
(
";"
)[
0
]
stripped_channel_id
=
parse
.
unquote_plus
(
channel_id
)
.
split
(
";"
)[
0
]
...
@@ -137,9 +138,17 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
...
@@ -137,9 +138,17 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
client
=
GraphServiceClient
(
credentials
=
credential
,
client
=
GraphServiceClient
(
credentials
=
credential
,
scopes
=
scopes
)
scopes
=
scopes
)
res
=
await
client
.
groups
.
by_group_id
(
group_id
)
.
members
.
get
()
response
=
await
client
.
groups
.
by_group_id
(
except
Exception
:
group_id
res
=
traceback
.
format_exc
()
)
.
members
.
get
()
emails
=
[]
for
member
in
response
.
value
:
if
member
.
mail
is
not
None
:
emails
.
append
(
member
.
mail
)
future
.
set_result
(
emails
)
except
Exception
as
e
:
future
.
set_exception
(
e
)
try
:
try
:
# send mail notifications!
# send mail notifications!
...
@@ -150,8 +159,9 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
...
@@ -150,8 +159,9 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
except
Exception
:
except
Exception
:
raise
raise
return
await
self
.
adapter
.
continue_conversation
(
reference
,
callback
,
await
self
.
adapter
.
continue_conversation
(
reference
,
callback
,
self
.
settings
.
app_id
)
self
.
settings
.
app_id
)
return
future
def
send_message
(
self
,
pa_message
:
PAMessage
)
->
Future
[
ResourceResponse
]:
def
send_message
(
self
,
pa_message
:
PAMessage
)
->
Future
[
ResourceResponse
]:
""" Send message as a bot """
""" Send message as a bot """
...
...
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