Skip to content

Commit f543b97

Browse files
fix
1 parent d257e87 commit f543b97

File tree

7 files changed

+27
-57
lines changed

7 files changed

+27
-57
lines changed

services/web/server/src/simcore_service_webserver/chatbot/_process_chatbot_trigger_service.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
from pydantic import TypeAdapter
1212
from servicelib.logging_utils import log_catch, log_context
1313
from servicelib.rabbitmq import RabbitMQClient
14-
from simcore_service_webserver.products._models import ProductBaseUrl
15-
from simcore_service_webserver.products.errors import ProductNotFoundError
1614

1715
from ..conversations import conversations_service
1816
from ..products import products_service
@@ -55,30 +53,16 @@ async def _process_chatbot_trigger_message(app: web.Application, data: bytes) ->
5553
for msg in messages[1]:
5654
_question_for_chatbot += f"{msg.content.strip()}\n"
5755

58-
# Prepare them and talk to the chatbot service
56+
# Talk to the chatbot service
5957
chatbot_client = get_chatbot_rest_client(app)
6058
chat_response = await chatbot_client.ask_question(_question_for_chatbot)
6159

62-
# After I got respond, create a new support message in the conversation
63-
try:
64-
_product_base_url = products_service.get_product_base_url(
65-
app, product_name=_product_name
66-
)
67-
except ProductNotFoundError:
68-
_logger.warning(
69-
"Product %s does not have base URL configured, cannot process chatbot message.",
70-
_product_name,
71-
)
72-
_product_base_url = ProductBaseUrl(scheme="http", host="unknown")
73-
7460
await conversations_service.create_support_message(
7561
app=app,
7662
product_name=rabbit_message.conversation.product_name,
7763
user_id=_product.support_chatbot_user_id,
7864
conversation_user_type=ConversationUserType.CHATBOT_USER,
7965
conversation=rabbit_message.conversation,
80-
product_url_scheme=_product_base_url.scheme,
81-
product_url_host=_product_base_url.host or "unknown",
8266
content=chat_response.answer,
8367
type_=ConversationMessageType.MESSAGE,
8468
)

services/web/server/src/simcore_service_webserver/conversations/_controller/_conversations_messages_rest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ async def create_conversation_message(request: web.Request):
9191
user_id=req_ctx.user_id,
9292
conversation_user_type=conversation_user_type,
9393
conversation=_conversation,
94-
product_url_scheme=request.url.scheme,
95-
product_url_host=request.url.host or "unknown",
9694
content=body_params.content,
9795
type_=body_params.type,
9896
)

services/web/server/src/simcore_service_webserver/conversations/_conversation_message_service.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,6 @@ async def create_support_message(
232232
user_id: UserID,
233233
conversation_user_type: ConversationUserType,
234234
conversation: ConversationGetDB,
235-
product_url_scheme: str,
236-
product_url_host: str,
237235
# Creation attributes
238236
content: str,
239237
type_: ConversationMessageType,
@@ -250,7 +248,9 @@ async def create_support_message(
250248

251249
product = products_service.get_product(app, product_name=product_name)
252250
fogbugz_settings_or_none = app[APP_SETTINGS_APPKEY].WEBSERVER_FOGBUGZ
253-
_conversation_url = f"{product_url_scheme}://{product_url_host}/#/conversation/{conversation.conversation_id}"
251+
_conversation_url = (
252+
f"{product.base_url}#/conversation/{conversation.conversation_id}"
253+
)
254254

255255
if (
256256
product.support_standard_group_id is None
@@ -278,7 +278,7 @@ async def create_support_message(
278278
user_id=user_id,
279279
message_content=message.content,
280280
conversation_url=_conversation_url,
281-
host=product_url_host,
281+
host=product.base_url.host or "unknown",
282282
product_support_assigned_fogbugz_project_id=product.support_assigned_fogbugz_project_id,
283283
fogbugz_url=str(fogbugz_settings_or_none.FOGBUGZ_URL),
284284
)

services/web/server/src/simcore_service_webserver/products/_models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
BeforeValidator,
1818
ConfigDict,
1919
Field,
20+
HttpUrl,
2021
PositiveInt,
2122
field_serializer,
2223
field_validator,
@@ -87,6 +88,11 @@ class Product(BaseModel):
8788
Field(description="Host regex"),
8889
]
8990

91+
base_url: Annotated[
92+
HttpUrl,
93+
Field(description="Product Base URL"),
94+
]
95+
9096
support_email: Annotated[
9197
LowerCaseEmailStr,
9298
Field(

services/web/server/src/simcore_service_webserver/products/_service.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from servicelib.exceptions import InvalidConfig
99
from simcore_postgres_database.utils_products_prices import ProductPriceInfo
1010

11-
from ._application_keys import PRODUCTS_APPKEY, PRODUCTS_URL_MAPPING_APPKEY
12-
from ._models import CreditResult, Product, ProductBaseUrl, ProductStripeInfo
11+
from ._application_keys import PRODUCTS_APPKEY
12+
from ._models import CreditResult, Product, ProductStripeInfo
1313
from ._repository import ProductRepository
1414
from .errors import (
1515
BelowMinimumPaymentError,
@@ -43,18 +43,6 @@ def get_product(app: web.Application, product_name: ProductName) -> Product:
4343
raise ProductNotFoundError(product_name=product_name) from exc
4444

4545

46-
def get_product_base_url(
47-
app: web.Application, product_name: ProductName
48-
) -> ProductBaseUrl:
49-
try:
50-
product_base_url: ProductBaseUrl = app[PRODUCTS_URL_MAPPING_APPKEY][
51-
product_name
52-
]
53-
return product_base_url
54-
except KeyError as exc:
55-
raise ProductNotFoundError(product_name=product_name) from exc
56-
57-
5846
def list_products(app: web.Application) -> list[Product]:
5947
products: list[Product] = list(app[PRODUCTS_APPKEY].values())
6048
return products

services/web/server/src/simcore_service_webserver/products/_web_helpers.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
from ..constants import RQ_PRODUCT_KEY
1313
from ..groups import api as groups_service
1414
from . import _service
15-
from ._application_keys import (
16-
PRODUCTS_URL_MAPPING_APPKEY,
17-
)
18-
from ._models import ProductBaseUrl
1915
from ._web_events import PRODUCTS_TEMPLATES_DIR_APPKEY
2016
from .errors import (
2117
FileTemplateNotFoundError,
@@ -47,20 +43,20 @@ def get_current_product(request: web.Request) -> Product:
4743
return current_product
4844

4945

50-
def set_product_base_url(request: web.Request, product_name: ProductName) -> None:
51-
if (
52-
not request.app[PRODUCTS_URL_MAPPING_APPKEY].get(product_name)
53-
and request.url.host
54-
):
55-
request.app[PRODUCTS_URL_MAPPING_APPKEY][product_name] = ProductBaseUrl(
56-
scheme=request.url.scheme, host=request.url.host
57-
)
58-
_logger.debug(
59-
"Set product url for %s to %s://%s",
60-
product_name,
61-
request.url.scheme,
62-
request.url.host,
63-
)
46+
# def set_product_base_url(request: web.Request, product_name: ProductName) -> None:
47+
# if (
48+
# not request.app[PRODUCTS_URL_MAPPING_APPKEY].get(product_name)
49+
# and request.url.host
50+
# ):
51+
# request.app[PRODUCTS_URL_MAPPING_APPKEY][product_name] = ProductBaseUrl(
52+
# scheme=request.url.scheme, host=request.url.host
53+
# )
54+
# _logger.debug(
55+
# "Set product url for %s to %s://%s",
56+
# product_name,
57+
# request.url.scheme,
58+
# request.url.host,
59+
# )
6460

6561

6662
async def is_user_in_product_support_group(

services/web/server/src/simcore_service_webserver/socketio/_handlers.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ async def connect(
149149
extra=get_log_record_extra(user_id=user_id),
150150
)
151151

152-
products_web.set_product_base_url(_request, product_name)
153-
154152
await _set_user_in_group_rooms(app, user_id, socket_id)
155153
await _set_user_in_project_rooms(app, user_id, client_session_id, socket_id)
156154

0 commit comments

Comments
 (0)