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
70617486
Commit
70617486
authored
Dec 19, 2022
by
Oleksandr Barabash
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor update with the content for the PA
parent
b0022428
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
11 deletions
+69
-11
app.py
app.py
+16
-0
messaging_extension_action_preview_bot.py
bots/messaging_extension_action_preview_bot.py
+51
-9
cosmos_client.py
utils/cosmos_client.py
+2
-2
No files found.
app.py
View file @
70617486
...
...
@@ -265,6 +265,21 @@ async def v1_pa_message(request: Request) -> Response:
return
make_response
(
400
,
"Bad Request"
)
async
def
v1_pa_authorize
(
request
:
Request
)
->
Response
:
""" Authorize Power Automate flow token """
# noinspection PyBroadException
try
:
data
=
json_loads
(
await
request
.
text
())
if
data
is
not
None
:
return
make_response
(
200
,
"OK"
)
except
Exception
:
Log
.
e
(
TAG
,
"v1_pa_authorize::error sending message"
,
exc_info
=
sys
.
exc_info
())
return
make_response
(
500
,
"Server Error"
)
# TODO(s1z): Change thit to 400 when auth is enabled!!!
return
make_response
(
200
,
"Bad Request"
)
async
def
init_db_containers
():
""" To speed up the process we have to create containers first """
await
COSMOS_CLIENT
.
create_db
(
CosmosDBConfig
.
Conversations
.
DATABASE
)
...
...
@@ -308,6 +323,7 @@ async def app_factory(bot):
# PA endpoints
app
.
router
.
add_post
(
"/api/pa/v1/message"
,
v1_pa_message
)
app
.
router
.
add_post
(
"/api/pa/v1/authorize"
,
v1_pa_authorize
)
bot
.
add_web_app
(
app
)
bot
.
add_cosmos_client
(
COSMOS_CLIENT
)
...
...
bots/messaging_extension_action_preview_bot.py
View file @
70617486
...
...
@@ -238,24 +238,66 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
async
def
on_message_activity
(
self
,
turn_context
:
TurnContext
)
->
None
:
i18n
=
get_i18n
(
turn_context
)
# check tenant
if
turn_context
.
activity
.
conversation
.
tenant_id
!=
AppConfig
.
TENANT_ID
:
await
turn_context
.
send_activity
(
i18n
.
t
(
"tenant_forbidden"
))
return
await
turn_context
.
send_activity
(
i18n
.
t
(
"tenant_forbidden"
))
return
await
self
.
cosmos_client
.
create_conversation_reference
(
turn_context
)
# save conversation reference
reference
=
await
self
.
cosmos_client
.
create_conversation_reference
(
turn_context
)
if
turn_context
.
activity
.
value
is
not
None
:
# TODO(s1z): translate this string
return
await
turn_context
.
send_activity
(
"Sorry, not supported! :("
)
return
await
self
.
handle_submit_action
(
turn_context
)
""" DATA STRUCTURE:
{
"authorizartion": {
"token": "123"
},
"message": "message",
"reference": {
"user": {
"name": null,
"id": "29:12v6wyPB....",
"role": null,
"aadObjectId": "ed77c873-f9a4-4d94-bd08-e159fa3349d2"
},
"channelId": "msteams",
"conversation": {
"id": "a:1aStwF-.....jogUhlEo",
"tenantId": "d3c0e3f9-060e-43d8-9d64-57fbb51d2003",
"name": null,
"aadObjectId": null,
"conversationType": "personal",
"properties": null,
"role": null,
"isGroup": null
},
"activityId": "f:c20375cb-8a88-6d68-8339-090d46d54fa0",
"serviceUrl": "https://smba.trafficmanager.net/emea/",
"bot": {
"name": "SuperBotFinal",
"id": "28:e250ed7c-49a9-46ab-9210-edf26cf4a221",
"role": null,
"aadObjectId": null
},
"locale": null,
"id": "a:1aStwF-......gUhlEo"
}
}
"""
# send request to PA
async
with
aiohttp
.
ClientSession
()
as
session
:
# TODO(s1z): string bot's @mention if needed.
message
=
turn_context
.
activity
.
text
.
strip
()
.
lower
()
tenant_id
=
turn_context
.
activity
.
conversation
.
tenant_id
conversation_id
=
turn_context
.
activity
.
conversation
.
id
data
=
dict
(
conversationId
=
conversation_id
,
tenantId
=
tenant_id
,
text
=
message
)
data
=
dict
(
authorizartion
=
dict
(
token
=
reference
),
reference
=
reference
,
message
=
message
)
async
with
session
.
post
(
AppConfig
.
PA_URL
,
json
=
data
)
as
resp
:
Log
.
e
(
TAG
,
f
"on_message_activity::response.status:"
f
"{resp.status}"
)
...
...
utils/cosmos_client.py
View file @
70617486
...
...
@@ -349,7 +349,7 @@ class CosmosClient:
return
NotificationCosmos
.
get_schema
(
unknown
=
EXCLUDE
)
.
load
(
item
)
async
def
create_conversation_reference
(
self
,
turn_context
:
TurnContext
)
\
->
None
:
->
Dict
[
str
,
Any
]
:
""" Save Conversation Regerence """
from
config
import
CosmosDBConfig
...
...
@@ -372,7 +372,7 @@ class CosmosClient:
Log
.
i
(
__name__
,
"create_conversation_reference::error:"
,
sys
.
exc_info
())
if
e
.
status_code
==
409
:
# Already exists
return
return
reference_json
raise
SaveItemError
(
e
.
http_error_message
)
async
def
create_initiation
(
self
,
initiator
:
str
,
...
...
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