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
fb512245
Commit
fb512245
authored
Dec 12, 2022
by
Oleksandr Barabash
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PA message handler added
parent
18efe630
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
39 deletions
+75
-39
app.py
app.py
+6
-5
messaging_extension_action_preview_bot.py
bots/messaging_extension_action_preview_bot.py
+61
-34
config.py
config.py
+8
-0
No files found.
app.py
View file @
fb512245
...
...
@@ -252,11 +252,12 @@ async def v1_pa_message(request: Request) -> Response:
try
:
body
=
json_loads
(
await
request
.
text
())
pa_message
=
PAMessage
.
get_schema
()
.
load
(
body
)
notification_id
=
await
BOT
.
send_message
(
pa_message
.
conversation_id
,
pa_message
.
tenant_id
,
pa_message
.
text
,
pa_message
.
card
)
Log
.
d
(
TAG
,
f
"v1_pa_message::notification: '{notification_id}'"
)
response
=
await
BOT
.
send_message
(
pa_message
.
conversation_id
,
pa_message
.
tenant_id
,
pa_message
.
text
,
pa_message
.
card
)
Log
.
d
(
TAG
,
f
"v1_pa_message::notification: '{response}'"
)
return
make_response
(
200
,
"OK"
)
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 @
fb512245
...
...
@@ -5,6 +5,7 @@ from asyncio import Future
from
typing
import
Optional
,
Dict
from
urllib.parse
import
urlparse
,
parse_qsl
,
urlencode
import
aiohttp
from
aiohttp.web_app
import
Application
from
botbuilder.core
import
(
TurnContext
,
CardFactory
,
BotFrameworkAdapter
,
BotFrameworkAdapterSettings
)
...
...
@@ -236,49 +237,75 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
await
turn_context
.
send_activity
(
i18n
.
t
(
"unknown_request"
))
async
def
on_message_activity
(
self
,
turn_context
:
TurnContext
)
->
None
:
""" on message activity """
i18n
=
get_i18n
(
turn_context
)
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
# try to save conversation reference,
# who knows maybe we didn't get the on_conversation_update!
await
self
.
cosmos_client
.
create_conversation_reference
(
turn_context
)
if
turn_context
.
activity
.
value
is
not
None
:
return
await
self
.
handle_submit_action
(
turn_context
)
message
=
turn_context
.
activity
.
text
.
strip
()
.
lower
()
# TODO(s1z): translate this string
return
await
turn_context
.
send_activity
(
"Sorry, not supported! :("
)
cmd_help
=
i18n
.
t
(
"cmd_help"
)
cmd_portal
=
i18n
.
t
(
"cmd_portal"
)
if
message
==
cmd_help
.
lower
():
# 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
response
=
await
turn_context
.
send_activity
(
i18n
.
t
(
"response_help"
,
cmd_portal
=
cmd_portal
,
cmd_help
=
cmd_help
,
tenant_id
=
tenant_id
,
conversation_id
=
conversation_id
)
)
Log
.
d
(
TAG
,
"on_message_activity::help_resp: {}"
.
format
(
response
))
return
if
message
==
cmd_portal
.
lower
():
card
=
CardHelper
.
load_assets_card
(
"default_card"
)
attachments
=
[
CardFactory
.
adaptive_card
(
card
)]
message
=
Activity
(
type
=
ActivityTypes
.
message
,
attachments
=
attachments
)
await
turn_context
.
send_activity
(
message
)
return
data
=
dict
(
conversationId
=
conversation_id
,
tenantId
=
tenant_id
,
text
=
message
)
async
with
session
.
post
(
AppConfig
.
PA_URL
,
data
=
data
)
as
resp
:
Log
.
e
(
TAG
,
f
"on_message_activity::response.status:"
f
"{resp.status}"
)
rest_text
=
await
resp
.
text
()
Log
.
e
(
TAG
,
f
"on_message_activity::response.text: {rest_text}"
)
return
await
turn_context
.
send_activity
(
i18n
.
t
(
"response_unknown_cmd"
,
cmd_help
=
cmd_help
))
# async def on_message_activity(self, turn_context: TurnContext) -> None:
# """ on message activity """
#
# i18n = get_i18n(turn_context)
#
# if turn_context.activity.conversation.tenant_id != AppConfig.TENANT_ID:
# await turn_context.send_activity(i18n.t("tenant_forbidden"))
# return
#
# # try to save conversation reference,
# # who knows maybe we didn't get the on_conversation_update!
# await self.cosmos_client.create_conversation_reference(turn_context)
#
# if turn_context.activity.value is not None:
# return await self.handle_submit_action(turn_context)
#
# message = turn_context.activity.text.strip().lower()
#
# cmd_help = i18n.t("cmd_help")
# cmd_portal = i18n.t("cmd_portal")
#
# if message == cmd_help.lower():
# tenant_id = turn_context.activity.conversation.tenant_id
# conversation_id = turn_context.activity.conversation.id
# response = await turn_context.send_activity(
# i18n.t("response_help",
# cmd_portal=cmd_portal,
# cmd_help=cmd_help,
# tenant_id=tenant_id,
# conversation_id=conversation_id)
# )
# Log.d(TAG, "on_message_activity::help_resp: {}".format(response))
# return
#
# if message == cmd_portal.lower():
# card = CardHelper.load_assets_card("default_card")
# attachments = [CardFactory.adaptive_card(card)]
# message = Activity(type=ActivityTypes.message,
# attachments=attachments)
# await turn_context.send_activity(message)
# return
#
# await turn_context.send_activity(i18n.t("response_unknown_cmd",
# cmd_help=cmd_help))
async
def
on_mx_task_unsupported
(
self
,
turn_context
:
TurnContext
)
\
->
TaskModuleResponse
:
...
...
config.py
View file @
fb512245
...
...
@@ -71,6 +71,14 @@ class AppConfig:
WEB_APP_NAME
=
os
.
environ
.
get
(
"WEB_APP_NAME"
,
"wa-name"
)
APP_ID
=
os
.
environ
.
get
(
"MS_APP_ID"
,
"app-id"
)
APP_PASSWORD
=
os
.
environ
.
get
(
"MS_APP_PASSWORD"
,
"app-password"
)
PA_URL
=
os
.
environ
.
get
(
"PA_URL"
,
(
"https://prod-192.westeurope.logic.azure.com:443"
"/workflows/22a28a2927454e6eb935484d84097132"
"/triggers/manual/paths/"
"invoke?api-version=2016-06-01&"
"sp=
%2
Ftriggers
%2
Fmanual
%2
Frun&sv=1.0"
"&sig=7cNmhQciqmG-CGzOWdS6gTXocXN7fn-900hU04riygs"
)
)
class
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