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
77030c45
Commit
77030c45
authored
Feb 01, 2023
by
Oleksandr Barabash
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleaner client added
parent
2640e282
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
3 deletions
+39
-3
messaging_extension_action_preview_bot.py
bots/messaging_extension_action_preview_bot.py
+13
-3
config.py
config.py
+5
-0
cleaner_client.py
utils/cleaner_client.py
+21
-0
No files found.
bots/messaging_extension_action_preview_bot.py
View file @
77030c45
...
...
@@ -23,7 +23,7 @@ from botframework.connector import Channels
from
marshmallow
import
EXCLUDE
from
bots.exceptions
import
ConversationNotFound
from
config
import
TaskModuleConfig
,
AppConfig
from
config
import
TaskModuleConfig
,
AppConfig
,
CLEANER_CLIENT
from
entities.json.medx
import
MedX
,
MXTypes
from
entities.json.notification
import
NotificationCosmos
from
entities.json.pa_message
import
PAMessage
...
...
@@ -146,7 +146,12 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
Log
.
e
(
TAG
,
"send_message::error:unknown card"
)
response
=
await
turn_context
.
send_activity
(
activity
)
pa_message
.
message_id
=
response
.
id
await
self
.
cosmos_client
.
create_pa_message
(
pa_message
)
await
asyncio
.
gather
(
self
.
cosmos_client
.
create_pa_message
(
pa_message
),
CLEANER_CLIENT
.
notify_new_ttl
(
pa_message
.
content_t_t_l
.
ttl
)
)
return
future
.
set_result
(
response
)
else
:
# TODO(s1z): add response!!!
...
...
@@ -200,7 +205,12 @@ class TeamsMessagingExtensionsActionPreviewBot(TeamsActivityHandler):
attachments
=
attachments
)
response
=
await
turn_context
.
send_activity
(
message
)
notification
.
message_id
=
response
.
id
await
self
.
cosmos_client
.
create_notification
(
notification
)
await
asyncio
.
gather
(
self
.
cosmos_client
.
create_notification
(
notification
),
CLEANER_CLIENT
.
notify_new_ttl
(
notification
.
content_t_t_l
.
ttl
)
)
log
.
info
(
f
"notification response: {response}"
)
future
.
set_result
(
notification
.
id
)
except
Exception
as
exception
:
...
...
config.py
View file @
77030c45
...
...
@@ -4,6 +4,7 @@ import os
from
azure.cosmos
import
PartitionKey
from
utils.azure_key_vault_client
import
AzureKeyVaultClient
from
utils.cleaner_client
import
CleanerClient
from
utils.cosmos_client
import
CosmosClient
from
utils.token_helper
import
TokenHelper
...
...
@@ -69,6 +70,9 @@ class AppConfig:
BOT_NAME
=
os
.
environ
.
get
(
"BOT_NAME"
,
'TheBot'
)
WEB_APP_NAME
=
os
.
environ
.
get
(
"WEB_APP_NAME"
,
"wa-name"
)
WEB_APP_CLEANER_NAME
=
os
.
environ
.
get
(
"WEB_APP_CLEANER_NAME"
,
f
"wac-{WEB_APP_NAME.split('-')[1]}"
)
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
(
...
...
@@ -133,3 +137,4 @@ COSMOS_CLIENT = CosmosClient(CosmosDBConfig.HOST, CosmosDBConfig.KEY)
KEY_VAULT_CLIENT
=
AzureKeyVaultClient
(
AppConfig
.
CLIENT_ID
,
AppConfig
.
KEY_VAULT
)
TOKEN_HELPER
=
TokenHelper
(
KEY_VAULT_CLIENT
)
CLEANER_CLIENT
=
CleanerClient
(
AppConfig
.
WEB_APP_CLEANER_NAME
)
utils/cleaner_client.py
0 → 100644
View file @
77030c45
""" Cleaner client """
import
logging
import
aiohttp
log
=
logging
.
getLogger
()
class
CleanerClient
:
""" Cleaner Client class """
PATH_TTL
=
"/api/v1/ttl"
def
__init__
(
self
,
domain_name
:
str
):
self
.
domain_name
=
domain_name
async
def
notify_new_ttl
(
self
,
ttl
:
int
):
""" Notify cleaner with the new ttl received """
url
=
f
"{self.domain_name}{self.PATH_TTL}"
async
with
aiohttp
.
ClientSession
()
as
session
:
async
with
session
.
post
(
url
,
json
=
dict
(
ttl
=
ttl
))
as
response
:
log
.
info
(
f
"response: {response}"
)
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