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
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

from benchling_sdk.apps.status.errors import AppUserFacingError
from benchling_sdk.models.webhooks.v0 import (
CanvasCreatedWebhookV2Beta,
CanvasInitializeWebhookV2,
CanvasInteractionWebhookV2,
WebhookEnvelopeV0,
)

from local_app.benchling_app.canvas_interaction import route_interaction_webhook
from local_app.benchling_app.setup import init_app_from_webhook
from local_app.benchling_app.views.canvas_initialize import render_search_canvas
from local_app.benchling_app.views.canvas_initialize import (
render_search_canvas,
render_search_canvas_for_created_canvas,
)
from local_app.lib.logger import get_logger

logger = get_logger()
Expand All @@ -29,6 +33,8 @@ def handle_webhook(webhook_dict: dict[str, Any]) -> None:
try:
if isinstance(webhook.message, CanvasInitializeWebhookV2):
render_search_canvas(app, webhook.message)
elif isinstance(webhook.message, CanvasCreatedWebhookV2Beta):
render_search_canvas_for_created_canvas(app, webhook.message)
# elif isinstance(webhook.message, CanvasInteractionWebhookV2):
# route_interaction_webhook(app, webhook.message)
# else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
TextInputUiBlock,
TextInputUiBlockType,
)
from benchling_sdk.models.webhooks.v0 import CanvasInitializeWebhookV2
from benchling_sdk.models.webhooks.v0 import CanvasInitializeWebhookV2, CanvasCreatedWebhookV2Beta

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

Expand Down Expand Up @@ -39,6 +39,27 @@ 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_created: CanvasCreatedWebhookV2Beta) -> None:
canvas_builder = CanvasBuilder(
app_id=app.id,
feature_id=canvas_created.feature_id,
resource_id=canvas_created.resource_id,
blocks=[
MarkdownUiBlock(
type=MarkdownUiBlockType.MARKDOWN,
value="**Hello world!!**",
),
# TODO: Let's add a button to Hello World
],
)
app.benchling.apps.update_canvas(canvas_created.canvas_id, canvas_builder.to_update())

# with app.create_session_context("Show Sync Search", timeout_seconds=20):
# 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_created.canvas_id, canvas_builder.to_update())


def input_blocks() -> list[UiBlock]:
return [
MarkdownUiBlock(
Expand Down
4 changes: 4 additions & 0 deletions examples/chem-sync-local-flask/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ features:
- name: Sync Step
id: sync_step
type: ASSAY_RUN
- name: Sync Step
id: canvas_sync_step
type: CANVAS
subscriptions:
deliveryMethod: WEBHOOK
messages:
- type: v2.canvas.initialized
- type: v2.canvas.userInteracted
- type: v2-beta.canvas.created
configuration:
- name: Sync Folder
type: folder
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.13.0
benchling-sdk[cryptography]==1.21.2
Loading