Skip to content

Commit 1091091

Browse files
Merge pull request #21 from benchling/benchtalk-workshop-embedable-canvas
Benchtalk workshop embeddable canvas
2 parents e9028a9 + 33e4f5f commit 1091091

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

examples/chem-sync-local-flask/local_app/benchling_app/handler.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
from benchling_sdk.apps.status.errors import AppUserFacingError
44
from benchling_sdk.models.webhooks.v0 import (
5+
CanvasCreatedWebhookV2Beta,
56
CanvasInitializeWebhookV2,
67
CanvasInteractionWebhookV2,
78
WebhookEnvelopeV0,
89
)
910

1011
from local_app.benchling_app.canvas_interaction import route_interaction_webhook
1112
from local_app.benchling_app.setup import init_app_from_webhook
12-
from local_app.benchling_app.views.canvas_initialize import render_search_canvas
13+
from local_app.benchling_app.views.canvas_initialize import (
14+
render_search_canvas,
15+
render_search_canvas_for_created_canvas,
16+
)
1317
from local_app.lib.logger import get_logger
1418

1519
logger = get_logger()
@@ -29,6 +33,8 @@ def handle_webhook(webhook_dict: dict[str, Any]) -> None:
2933
try:
3034
if isinstance(webhook.message, CanvasInitializeWebhookV2):
3135
render_search_canvas(app, webhook.message)
36+
elif isinstance(webhook.message, CanvasCreatedWebhookV2Beta):
37+
render_search_canvas_for_created_canvas(app, webhook.message)
3238
# elif isinstance(webhook.message, CanvasInteractionWebhookV2):
3339
# route_interaction_webhook(app, webhook.message)
3440
# else:

examples/chem-sync-local-flask/local_app/benchling_app/views/canvas_initialize.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
TextInputUiBlock,
1010
TextInputUiBlockType,
1111
)
12-
from benchling_sdk.models.webhooks.v0 import CanvasInitializeWebhookV2
12+
from benchling_sdk.models.webhooks.v0 import CanvasInitializeWebhookV2, CanvasCreatedWebhookV2Beta
1313

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

@@ -39,6 +39,27 @@ def render_search_canvas(app: App, canvas_initialized: CanvasInitializeWebhookV2
3939
# app.benchling.apps.create_canvas(canvas_builder.to_create())
4040

4141

42+
def render_search_canvas_for_created_canvas(app: App, canvas_created: CanvasCreatedWebhookV2Beta) -> None:
43+
canvas_builder = CanvasBuilder(
44+
app_id=app.id,
45+
feature_id=canvas_created.feature_id,
46+
resource_id=canvas_created.resource_id,
47+
blocks=[
48+
MarkdownUiBlock(
49+
type=MarkdownUiBlockType.MARKDOWN,
50+
value="**Hello world!!**",
51+
),
52+
# TODO: Let's add a button to Hello World
53+
],
54+
)
55+
app.benchling.apps.update_canvas(canvas_created.canvas_id, canvas_builder.to_update())
56+
57+
# with app.create_session_context("Show Sync Search", timeout_seconds=20):
58+
# canvas_builder = CanvasBuilder(app_id=app.id, feature_id=canvas_created.feature_id)
59+
# canvas_builder.blocks.append(input_blocks())
60+
# app.benchling.apps.update_canvas(canvas_created.canvas_id, canvas_builder.to_update())
61+
62+
4263
def input_blocks() -> list[UiBlock]:
4364
return [
4465
MarkdownUiBlock(

examples/chem-sync-local-flask/manifest.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ features:
66
- name: Sync Step
77
id: sync_step
88
type: ASSAY_RUN
9+
- name: Sync Step
10+
id: canvas_sync_step
11+
type: CANVAS
912
subscriptions:
1013
deliveryMethod: WEBHOOK
1114
messages:
1215
- type: v2.canvas.initialized
1316
- type: v2.canvas.userInteracted
17+
- type: v2-beta.canvas.created
1418
configuration:
1519
- name: Sync Folder
1620
type: folder
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
flask~=3.0.2
22
# Cryptography extra needed for webhook verification
3-
benchling-sdk[cryptography]==1.13.0
3+
benchling-sdk[cryptography]==1.21.2

0 commit comments

Comments
 (0)