Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/chem-sync-local-flask/local_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def receive_webhooks(target: str) -> tuple[str, int]: # noqa: ARG001

# Important! To verify webhooks, we need to pass the body as an unmodified string
# Flask's request.data is bytes, so decode to string. Passing bytes or JSON won't work
verify(app_def_id, request.data.decode("utf-8"), request.headers) # type: ignore[arg-type]
verify(app_def_id, request.data.decode("utf-8"), request.headers)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

niceee 😄


logger.debug("Received webhook message: %s", request.json)
# Dispatch work and ACK webhook as quickly as possible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def handle_webhook(webhook_dict: dict[str, Any]) -> None:
elif isinstance(webhook.message, CanvasInteractionWebhookV2):
route_interaction_webhook(app, webhook.message)
elif isinstance(webhook.message, CanvasCreatedWebhookV2Beta):
render_search_canvas_for_created_canvas(app, webhook.message.canvas_id)
render_search_canvas_for_created_canvas(app, webhook.message)
else:
# Should only happen if the app's manifest requests webhooks that aren't handled in its code paths
raise UnsupportedWebhookError(f"Received an unsupported webhook type: {webhook}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
TextInputUiBlock,
TextInputUiBlockType,
)
from benchling_sdk.models.webhooks.v0 import CanvasInitializeWebhookV2
from benchling_sdk.models.webhooks.v0 import (
CanvasCreatedWebhookV2Beta,
CanvasInitializeWebhookV2,
)

from local_app.benchling_app.views.constants import SEARCH_BUTTON_ID, SEARCH_TEXT_ID


def _canvas_builder_from_canvas_id(app: App, canvas_id: str) -> CanvasBuilder:
current_canvas = app.benchling.apps.get_canvas_by_id(canvas_id)
return CanvasBuilder.from_canvas(current_canvas)

def render_search_canvas(app: App, canvas_initialized: CanvasInitializeWebhookV2) -> None:
with app.create_session_context("Show Sync Search", timeout_seconds=20):
canvas_builder = CanvasBuilder(
Expand All @@ -29,11 +28,11 @@ def render_search_canvas(app: App, canvas_initialized: CanvasInitializeWebhookV2
app.benchling.apps.create_canvas(canvas_builder.to_create())


def render_search_canvas_for_created_canvas(app: App, canvas_id: str) -> None:
def render_search_canvas_for_created_canvas(app: App, canvas_created: CanvasCreatedWebhookV2Beta) -> None:
with app.create_session_context("Show Sync Search", timeout_seconds=20):
canvas_builder = _canvas_builder_from_canvas_id(app, canvas_id)
canvas_builder = CanvasBuilder(app_id=app.id, feature_id=canvas_created.feature_id)
canvas_builder.blocks.append(input_blocks())
app.benchling.apps.update_canvas(canvas_id, canvas_builder.to_update())
app.benchling.apps.update_canvas(canvas_created.canvas_id, canvas_builder.to_update())


def input_blocks() -> list[UiBlock]:
Expand Down
2 changes: 1 addition & 1 deletion examples/chem-sync-local-flask/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
flask~=3.0.2
# Cryptography extra needed for webhook verification
benchling-sdk[cryptography]==1.19.0
benchling-sdk[cryptography]==1.21.1
Loading